Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,36 +1,39 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
import
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from gradio_client import Client, handle_file
|
| 3 |
+
|
| 4 |
+
# Connect to Spaces using gradio_client
|
| 5 |
+
vton_client = Client("Kwai-Kolors/Kolors-Virtual-Try-On")
|
| 6 |
+
mesh_client = Client("tencent/Hunyuan3D-2.1")
|
| 7 |
+
|
| 8 |
+
def vton_to_3d(person_img, cloth_img):
|
| 9 |
+
# Step 1: Virtual Try-On (2D image)
|
| 10 |
+
vton_output = vton_client.predict(
|
| 11 |
+
person_img, cloth_img,
|
| 12 |
+
api_name="/tryon" # verify via "Use via API" on the Space UI
|
| 13 |
+
)
|
| 14 |
+
tryon_img = vton_output
|
| 15 |
+
|
| 16 |
+
# Step 2: Generate 3D mesh using the 2D try-on image
|
| 17 |
+
mesh_output = mesh_client.predict(
|
| 18 |
+
tryon_img,
|
| 19 |
+
api_name="/predict" # verify via "Use via API" on the Space UI
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
return tryon_img, mesh_output
|
| 23 |
+
|
| 24 |
+
demo = gr.Interface(
|
| 25 |
+
fn=vton_to_3d,
|
| 26 |
+
inputs=[
|
| 27 |
+
gr.Image(type="filepath", label="Person Image"),
|
| 28 |
+
gr.Image(type="filepath", label="Cloth Image")
|
| 29 |
+
],
|
| 30 |
+
outputs=[
|
| 31 |
+
gr.Image(label="2D Try-On Result"),
|
| 32 |
+
gr.File(label="3D Mesh Output (.glb/.obj/.ply)")
|
| 33 |
+
],
|
| 34 |
+
title="2D Try-On → 3D Mesh Pipeline",
|
| 35 |
+
description="Uploads a person image and clothing image → performs virtual try-on → generates a 3D mesh."
|
| 36 |
+
)
|
| 37 |
+
|
| 38 |
+
if __name__ == "__main__":
|
| 39 |
+
demo.launch(share=True) # Set share=True to create a public link
|