Spaces:
Sleeping
Sleeping
Upload fal_api.py
Browse files- src/fal_api.py +46 -0
src/fal_api.py
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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)
|
| 7 |
+
|
| 8 |
+
handler = fal_client.submit(
|
| 9 |
+
"comfy/JarvisSan22/cloth_ipadapter",
|
| 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)
|
| 17 |
+
result= handler.get()
|
| 18 |
+
#image_urls=[]
|
| 19 |
+
print(result["outputs"])
|
| 20 |
+
"""
|
| 21 |
+
for k,item in result["outputs"].items():
|
| 22 |
+
if "images" in item:
|
| 23 |
+
image_urls.append(item["images"][0]["url"])
|
| 24 |
+
print(image_urls)
|
| 25 |
+
return image_urls
|
| 26 |
+
"""
|
| 27 |
+
#print(result)
|
| 28 |
+
return result["outputs"]["20"]["images"][0]["url"]
|
| 29 |
+
|
| 30 |
+
def fal_faceswap_api(input_image,face_image):
|
| 31 |
+
print(input_image.shape,face_image.shape,type(face_image))
|
| 32 |
+
#face_image.resize((1024, 1024))
|
| 33 |
+
input_image=resize_image(input_image)
|
| 34 |
+
face_image=resize_image(face_image)
|
| 35 |
+
print(input_image.shape,face_image.shape)
|
| 36 |
+
handler = fal_client.submit(
|
| 37 |
+
"fal-ai/face-swap",
|
| 38 |
+
arguments={
|
| 39 |
+
"base_image_url": numpy_to_base64(input_image),
|
| 40 |
+
"swap_image_url": numpy_to_base64(face_image),
|
| 41 |
+
},
|
| 42 |
+
)
|
| 43 |
+
|
| 44 |
+
result = handler.get()
|
| 45 |
+
print(result)
|
| 46 |
+
return result["image"]["url"]
|