Spaces:
Sleeping
Sleeping
Upload 6 files
Browse files- src/fal_api.py +2 -1
- src/rep_api.py +10 -19
- src/utils.py +19 -3
src/fal_api.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import fal_client
|
| 2 |
from src.utils import numpy_to_base64
|
| 3 |
from src.helpers import resize_image
|
|
|
|
| 4 |
|
| 5 |
def fal_ipadapter_api(input_image,ip_image,seg_prompt):
|
| 6 |
#print(input_image,ip_image,seg_prompt)
|
|
@@ -10,7 +11,7 @@ def fal_ipadapter_api(input_image,ip_image,seg_prompt):
|
|
| 10 |
arguments={
|
| 11 |
"loadimage_1":numpy_to_base64(input_image),
|
| 12 |
"loadimage_2":numpy_to_base64(ip_image),
|
| 13 |
-
"groundingdinosamsegment (segment anything)_prompt":seg_prompt
|
| 14 |
},
|
| 15 |
)
|
| 16 |
#print(handler)
|
|
|
|
| 1 |
import fal_client
|
| 2 |
from src.utils import numpy_to_base64
|
| 3 |
from src.helpers import resize_image
|
| 4 |
+
from src.deepl import detect_and_translate
|
| 5 |
|
| 6 |
def fal_ipadapter_api(input_image,ip_image,seg_prompt):
|
| 7 |
#print(input_image,ip_image,seg_prompt)
|
|
|
|
| 11 |
arguments={
|
| 12 |
"loadimage_1":numpy_to_base64(input_image),
|
| 13 |
"loadimage_2":numpy_to_base64(ip_image),
|
| 14 |
+
"groundingdinosamsegment (segment anything)_prompt":detect_and_translate(seg_prompt)
|
| 15 |
},
|
| 16 |
)
|
| 17 |
#print(handler)
|
src/rep_api.py
CHANGED
|
@@ -327,34 +327,25 @@ light_source_options=[
|
|
| 327 |
"Ambient"
|
| 328 |
]
|
| 329 |
|
|
|
|
| 330 |
|
| 331 |
def replicate_iclight_BG(img,prompt,bg_img,light_source="Use Background Image",
|
| 332 |
negative_prompt="(deformed iris, deformed pupils, semi-realistic, cgi, 3d, render, sketch, cartoon, drawing, anime, mutated hands and fingers:1.4), (deformed, distorted, disfigured:1.3), poorly drawn, bad anatomy, wrong anatomy, extra limb, missing limb, floating limbs, disconnected limbs, mutation, mutated, ugly, disgusting, amputation"
|
| 333 |
):
|
| 334 |
-
|
| 335 |
assert light_source in light_source_options, "Please select a correct ligh source option"
|
| 336 |
-
#if type(img)!=str:
|
| 337 |
-
# img=open_image_from_url(img)
|
| 338 |
-
#if type(bg_img)!=str:
|
| 339 |
-
# bg_img=open_image_from_url(bg_img)
|
| 340 |
-
|
| 341 |
width, height = img.size
|
| 342 |
print(width,height)
|
| 343 |
-
|
| 344 |
-
target_width = find_closest_valid_dimension(width)
|
| 345 |
-
target_height = find_closest_valid_dimension(height)
|
| 346 |
-
resized_img = resize_image(img, target_width, target_height)
|
| 347 |
-
img=image_to_base64(resized_img)
|
| 348 |
-
|
| 349 |
#if light_source=="Use Background Image":
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
target_height = find_closest_valid_dimension(bg_height)
|
| 353 |
-
print(bg_img)
|
| 354 |
-
bg_img = resize_image(bg_img, target_width, target_height)
|
| 355 |
bg_img=image_to_base64(bg_img)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 356 |
|
| 357 |
-
|
| 358 |
output=replicate.run(
|
| 359 |
"zsxkib/ic-light-background:60015df78a8a795470da6494822982140d57b150b9ef14354e79302ff89f69e3",
|
| 360 |
input={
|
|
@@ -371,7 +362,7 @@ def replicate_iclight_BG(img,prompt,bg_img,light_source="Use Background Image",
|
|
| 371 |
"output_quality": 100,
|
| 372 |
"appended_prompt": "best quality",
|
| 373 |
"highres_denoise": 0.5,
|
| 374 |
-
"negative_prompt":
|
| 375 |
"background_image": bg_img,
|
| 376 |
"number_of_images": 1
|
| 377 |
}
|
|
|
|
| 327 |
"Ambient"
|
| 328 |
]
|
| 329 |
|
| 330 |
+
defult_image="https://replicate.delivery/pbxt/KxPIbJUjSmVBlvn0M3C8PAz6brN5Z0eyZSGcKIVw3XfJ6vNV/7.webp"
|
| 331 |
|
| 332 |
def replicate_iclight_BG(img,prompt,bg_img,light_source="Use Background Image",
|
| 333 |
negative_prompt="(deformed iris, deformed pupils, semi-realistic, cgi, 3d, render, sketch, cartoon, drawing, anime, mutated hands and fingers:1.4), (deformed, distorted, disfigured:1.3), poorly drawn, bad anatomy, wrong anatomy, extra limb, missing limb, floating limbs, disconnected limbs, mutation, mutated, ugly, disgusting, amputation"
|
| 334 |
):
|
|
|
|
| 335 |
assert light_source in light_source_options, "Please select a correct ligh source option"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 336 |
width, height = img.size
|
| 337 |
print(width,height)
|
| 338 |
+
img=image_to_base64(img)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 339 |
#if light_source=="Use Background Image":
|
| 340 |
+
if bg_img is None:
|
| 341 |
+
bg_img=open_image_from_url(defult_image)
|
|
|
|
|
|
|
|
|
|
| 342 |
bg_img=image_to_base64(bg_img)
|
| 343 |
+
#else:
|
| 344 |
+
#bg_img=None
|
| 345 |
+
|
| 346 |
+
prompt=prompt
|
| 347 |
+
|
| 348 |
|
|
|
|
| 349 |
output=replicate.run(
|
| 350 |
"zsxkib/ic-light-background:60015df78a8a795470da6494822982140d57b150b9ef14354e79302ff89f69e3",
|
| 351 |
input={
|
|
|
|
| 362 |
"output_quality": 100,
|
| 363 |
"appended_prompt": "best quality",
|
| 364 |
"highres_denoise": 0.5,
|
| 365 |
+
"negative_prompt": negative_prompt,
|
| 366 |
"background_image": bg_img,
|
| 367 |
"number_of_images": 1
|
| 368 |
}
|
src/utils.py
CHANGED
|
@@ -10,8 +10,20 @@ import zipfile
|
|
| 10 |
import numpy as np
|
| 11 |
import json
|
| 12 |
import gradio as gr
|
|
|
|
| 13 |
|
|
|
|
|
|
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
def resize_image(img, target_width, target_height):
|
| 16 |
"""Resizes an image while maintaining aspect ratio.
|
| 17 |
|
|
@@ -63,9 +75,13 @@ def convert_to_pil(img):
|
|
| 63 |
if isinstance(img, np.ndarray):
|
| 64 |
img = Image.fromarray(img)
|
| 65 |
# If the image is a URL, fetch the image and convert it to a PIL image
|
| 66 |
-
elif isinstance(img, str)
|
| 67 |
-
|
| 68 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
return img
|
| 70 |
|
| 71 |
def open_image_from_url(image_url):
|
|
|
|
| 10 |
import numpy as np
|
| 11 |
import json
|
| 12 |
import gradio as gr
|
| 13 |
+
import subprocess
|
| 14 |
|
| 15 |
+
class dwebpException(Exception):
|
| 16 |
+
pass
|
| 17 |
|
| 18 |
+
|
| 19 |
+
def dwebp(file: str):
|
| 20 |
+
webp = subprocess.run(
|
| 21 |
+
f"dwebp {file} -quiet -o -", shell=True, capture_output=True
|
| 22 |
+
)
|
| 23 |
+
if webp.returncode != 0:
|
| 24 |
+
raise dwebpException(webp.stderr.decode())
|
| 25 |
+
else:
|
| 26 |
+
return Image.open(BytesIO(webp.stdout))
|
| 27 |
def resize_image(img, target_width, target_height):
|
| 28 |
"""Resizes an image while maintaining aspect ratio.
|
| 29 |
|
|
|
|
| 75 |
if isinstance(img, np.ndarray):
|
| 76 |
img = Image.fromarray(img)
|
| 77 |
# If the image is a URL, fetch the image and convert it to a PIL image
|
| 78 |
+
elif isinstance(img, str):
|
| 79 |
+
if "https:" in img or "http:" in img:
|
| 80 |
+
response = requests.get(img)
|
| 81 |
+
img = Image.open(BytesIO(response.content))
|
| 82 |
+
#else is pil type
|
| 83 |
+
else:
|
| 84 |
+
img=Image.open(img)
|
| 85 |
return img
|
| 86 |
|
| 87 |
def open_image_from_url(image_url):
|