Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,8 +1,14 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import cv2
|
| 3 |
import numpy as np
|
|
|
|
| 4 |
from gradio_client import Client
|
| 5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
# -----------------------------
|
| 7 |
# Local "try-on" function
|
| 8 |
# -----------------------------
|
|
@@ -45,14 +51,14 @@ def tryon_to_3d(person_img, garment_img, seed, randomize_seed):
|
|
| 45 |
return None, "Try-on failed"
|
| 46 |
|
| 47 |
try:
|
| 48 |
-
# Convert
|
| 49 |
-
|
| 50 |
-
|
| 51 |
|
| 52 |
-
# Send
|
| 53 |
result_3d = hunyuan_client.predict(
|
| 54 |
-
|
| 55 |
-
|
| 56 |
fn_index=fn_index_default
|
| 57 |
)
|
| 58 |
return result_3d, tryon_info
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import cv2
|
| 3 |
import numpy as np
|
| 4 |
+
import base64
|
| 5 |
from gradio_client import Client
|
| 6 |
|
| 7 |
+
def np_to_base64(img_np):
|
| 8 |
+
_, buffer = cv2.imencode('.png', img_np)
|
| 9 |
+
img_bytes = buffer.tobytes()
|
| 10 |
+
return "data:image/png;base64," + base64.b64encode(img_bytes).decode()
|
| 11 |
+
|
| 12 |
# -----------------------------
|
| 13 |
# Local "try-on" function
|
| 14 |
# -----------------------------
|
|
|
|
| 51 |
return None, "Try-on failed"
|
| 52 |
|
| 53 |
try:
|
| 54 |
+
# Convert images to base64 strings
|
| 55 |
+
person_base64 = np_to_base64(tryon_img)
|
| 56 |
+
garment_base64 = np_to_base64(garment_img)
|
| 57 |
|
| 58 |
+
# Send base64 images to Hunyuan3D API
|
| 59 |
result_3d = hunyuan_client.predict(
|
| 60 |
+
person_base64,
|
| 61 |
+
garment_base64,
|
| 62 |
fn_index=fn_index_default
|
| 63 |
)
|
| 64 |
return result_3d, tryon_info
|