Skip to content

Commit

Permalink
Merge branch 'master' into email_zero_credits
Browse files Browse the repository at this point in the history
  • Loading branch information
clr-li committed Oct 10, 2023
2 parents bf1f00d + cd31654 commit 81190e8
Show file tree
Hide file tree
Showing 18 changed files with 467 additions and 264 deletions.
20 changes: 8 additions & 12 deletions daras_ai_v2/asr.py
Original file line number Diff line number Diff line change
Expand Up @@ -384,19 +384,15 @@ def run_asr(
if result.alternatives
)
elif "nemo" in selected_model.name:
r = requests.post(
str(GpuEndpoints.nemo_asr),
json={
"pipeline": dict(
model_id=asr_model_ids[selected_model],
),
"inputs": dict(
audio=audio_url,
),
},
data = call_celery_task(
"nemo_asr",
pipeline=dict(
model_id=asr_model_ids[selected_model],
),
inputs=dict(
audio=audio_url,
),
)
r.raise_for_status()
data = r.json()
# check if we should use the fast queue
# call one of the self-hosted models
else:
Expand Down
17 changes: 14 additions & 3 deletions daras_ai_v2/enum_selector_widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ def enum_multiselect(
checkboxes=True,
allow_none=True,
):
try:
deprecated = enum_cls._deprecated()
except AttributeError:
deprecated = set()
enums = [e for e in enum_cls if not e in deprecated]

if checkboxes:
if label:
st.write(label)
Expand All @@ -31,13 +37,13 @@ def render(e):
else:
selected.discard(e.name)

grid_layout(2, enum_cls, render, separator=False)
grid_layout(2, enums, render, separator=False)
st.session_state[key] = list(selected)

return selected
else:
return st.multiselect(
options=[e.name for e in enum_cls],
options=[e.name for e in enums],
format_func=lambda k: enum_cls[k].value,
label=label,
key=key,
Expand All @@ -53,8 +59,13 @@ def enum_selector(
exclude: list[E] | None = None,
**kwargs,
) -> str:
try:
deprecated = enum_cls._deprecated()
except AttributeError:
deprecated = set()
enums = [e for e in enum_cls if not e in deprecated]
label = label or enum_cls.__name__
options = [e.name for e in enum_cls]
options = [e.name for e in enums]
if exclude:
options = [o for o in options if o not in exclude]
if allow_none:
Expand Down
15 changes: 7 additions & 8 deletions daras_ai_v2/face_restoration.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,10 @@ def gfpgan(img: str, scale: int = 1) -> bytes:
elif scale != 2:
scale *= 2

return call_gpu_server_b64(
endpoint=GpuEndpoints.gfpgan,
input_data={
"img": img,
"version": "v1.4",
"scale": scale,
},
)[0]
# https://replicate.com/nightmareai/real-esrgan/versions/42fed1c4974146d4d2414e2be2c5277c7fcf05fcc3a73abf41610695738c1d7b#output-schema
model = replicate.models.get("tencentarc/gfpgan")
version = model.versions.get(
"9283608cc6b7be6b65a8e44983db012355fde4132009bf99d976b2f0896856a3"
)
img = version.predict(img=img, version="v1.4", scale=scale)
return requests.get(img).content
28 changes: 0 additions & 28 deletions daras_ai_v2/gpu_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,6 @@


class GpuEndpoints:
wav2lip = settings.GPU_SERVER_1.copy().set(port=5001)
glid_3_xl_stable = settings.GPU_SERVER_1.copy().set(port=5002)
gfpgan = settings.GPU_SERVER_1.copy().set(port=5003)
dichotomous_image_segmentation = settings.GPU_SERVER_1.copy().set(port=5004)
# flan_t5 = f"{settings.GPU_SERVER_2}:5005"
# runway_ml_inpainting = f"{settings.GPU_SERVER_2}:5006"
u2net = settings.GPU_SERVER_1.copy().set(port=5007)
# deforum_sd = f"{settings.GPU_SERVER_2}:5008"
sd_2 = settings.GPU_SERVER_1.copy().set(port=5011)
# sd_multi = settings.GPU_SERVER_1.copy().set(port=5012)
# real_esrgan = settings.GPU_SERVER_1furl().set(port=5013)
# defourm_sd = settings.GPU_SERVER_2.copy().set(port=5014) / "deforum"

lavis = settings.GPU_SERVER_1.copy().set(port=5015)
vqa = lavis / "vqa"
image_captioning = lavis / "image-captioning"

_asr = settings.GPU_SERVER_1.copy().set(port=5016)
whisper = _asr / "whisper"
nemo_asr = _asr / "nemo/asr"

_asr_fast = settings.GPU_SERVER_1.copy().set(port=5019)
whisper_fast = _asr_fast / "whisper"
nemo_asr_fast = _asr_fast / "nemo/asr"

audio_ldm = settings.GPU_SERVER_1.copy().set(port=5017) / "audio_ldm"
bark = settings.GPU_SERVER_1.copy().set(port=5017) / "bark"

deepfloyd_if = settings.GPU_SERVER_1.copy().set(port=5018) / "deepfloyd_if"


Expand Down
35 changes: 23 additions & 12 deletions daras_ai_v2/image_segmentation.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from enum import Enum

from daras_ai.image_input import bytes_to_cv2_img, cv2_img_to_bytes
from daras_ai_v2.gpu_server import call_gpu_server_b64, GpuEndpoints
import requests

from daras_ai_v2.gpu_server import (
call_celery_task_outfile,
)


class ImageSegmentationModels(Enum):
Expand All @@ -10,18 +13,26 @@ class ImageSegmentationModels(Enum):


def u2net(input_image: str) -> bytes:
return call_gpu_server_b64(
endpoint=GpuEndpoints.u2net,
input_data={
"image": input_image,
},
url = call_celery_task_outfile(
"u2net",
pipeline=dict(model_id="u2net"),
inputs={"images": [input_image]},
content_type="image/png",
filename="u2net.png",
)[0]
r = requests.get(url)
r.raise_for_status()
return r.content


def dis(input_image: str) -> bytes:
return call_gpu_server_b64(
endpoint=GpuEndpoints.dichotomous_image_segmentation,
input_data={
"input_image": input_image,
},
url = call_celery_task_outfile(
"dis",
pipeline=dict(model_id="isnet-general-use.pth"),
inputs={"images": [input_image]},
content_type="image/png",
filename="dis.png",
)[0]
r = requests.get(url)
r.raise_for_status()
return r.content
18 changes: 9 additions & 9 deletions daras_ai_v2/img_model_settings_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ def model_selector(
col1, col2 = st.columns(2)
with col1:
selected_model = enum_selector(
Img2ImgModels,
models_enum,
label="""
### 🤖 Choose your preferred AI Model
""",
Expand All @@ -101,20 +101,20 @@ def model_selector(
):
if "selected_controlnet_model" in st.session_state:
st.session_state["selected_controlnet_model"] = None
else:
elif models_enum is Img2ImgModels:
enum_multiselect(
ControlNetModels,
label=controlnet_explanation,
key="selected_controlnet_model",
checkboxes=False,
allow_none=not require_controlnet,
)
with col2:
controlnet_settings(
extra_explanations=extra_explanations,
low_explanation=low_explanation,
high_explanation=high_explanation,
)
with col2:
controlnet_settings(
extra_explanations=extra_explanations,
low_explanation=low_explanation,
high_explanation=high_explanation,
)
return selected_model


Expand Down Expand Up @@ -410,7 +410,7 @@ def prompt_strength_setting(selected_model: str = None):


def negative_prompt_setting(selected_model: str = None):
if selected_model in [Text2ImgModels.dall_e.name, InpaintingModels.runway_ml.name]:
if selected_model in [Text2ImgModels.dall_e.name]:
return

st.text_area(
Expand Down
4 changes: 4 additions & 0 deletions daras_ai_v2/language_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ class LargeLanguageModels(Enum):

code_davinci_002 = "Codex [Deprecated] (openai)"

@classmethod
def _deprecated(cls):
return {cls.code_davinci_002}

def is_chat_model(self) -> bool:
return self in [
LargeLanguageModels.gpt_4,
Expand Down
3 changes: 2 additions & 1 deletion daras_ai_v2/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,6 @@
EXPLORE_URL = furl(APP_BASE_URL).add(path="explore").url

GPU_SERVER_1 = furl(config("GPU_SERVER_1", "http://gpu-1.gooey.ai"))
GPU_SERVER_2 = furl(config("GPU_SERVER_2", "http://gpu-2.gooey.ai"))

SERPER_API_KEY = config("SERPER_API_KEY", None)

Expand Down Expand Up @@ -285,3 +284,5 @@
AZURE_FORM_RECOGNIZER_KEY = config("AZURE_FORM_RECOGNIZER_KEY", "")

DEEPGRAM_API_KEY = config("DEEPGRAM_API_KEY", "")

ELEVEN_LABS_API_KEY = config("ELEVEN_LABS_API_KEY", "")
Loading

0 comments on commit 81190e8

Please sign in to comment.