Monikashyapa commited on
Commit
edfb9ce
·
verified ·
1 Parent(s): 34aa681

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -36
app.py CHANGED
@@ -1,36 +1,39 @@
1
- import gradio as gr
2
- import requests
3
- from huggingface_hub import InferenceClient
4
-
5
- # Space 1: Kolors Virtual Try-On
6
- vton_client = InferenceClient("Kwai-Kolors/Kolors-Virtual-Try-On")
7
-
8
- # Space 2: Hunyuan3D-2.1
9
- mesh_client = InferenceClient("tencent/Hunyuan3D-2.1")
10
-
11
- def vton_to_3d(model_image, cloth_image):
12
- # Step 1: Run Virtual Try-On (Space 1)
13
- vton_result = vton_client.post(
14
- json={"model_image": model_image, "cloth_image": cloth_image}
15
- )
16
-
17
- # vton_result contains a try-on image
18
- tryon_image = vton_result["image"]
19
-
20
- # Step 2: Run Hunyuan3D on the try-on image (Space 2)
21
- mesh_result = mesh_client.post(
22
- json={"image": tryon_image}
23
- )
24
-
25
- return tryon_image, mesh_result["mesh"]
26
-
27
- demo = gr.Interface(
28
- fn=vton_to_3d,
29
- inputs=[gr.Image(type="filepath", label="Model Image"),
30
- gr.Image(type="filepath", label="Cloth Image")],
31
- outputs=[gr.Image(label="2D Try-On Result"),
32
- gr.Model3D(label="3D Avatar Output")]
33
- )
34
-
35
- if __name__ == "__main__":
36
- demo.launch()
 
 
 
 
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