File size: 1,246 Bytes
edfb9ce
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
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
37
38
39
40
import gradio as gr
from gradio_client import Client, handle_file

# Connect to Spaces using gradio_client
vton_client = Client("Kwai-Kolors/Kolors-Virtual-Try-On")
mesh_client = Client("tencent/Hunyuan3D-2.1")

def vton_to_3d(person_img, cloth_img):
    # Step 1: Virtual Try-On (2D image)
    vton_output = vton_client.predict(
        person_img, cloth_img,
        api_name="/tryon"  # verify via "Use via API" on the Space UI
    )
    tryon_img = vton_output

    # Step 2: Generate 3D mesh using the 2D try-on image
    mesh_output = mesh_client.predict(
        tryon_img,
        api_name="/predict"  # verify via "Use via API" on the Space UI
    )

    return tryon_img, mesh_output

demo = gr.Interface(
    fn=vton_to_3d,
    inputs=[
        gr.Image(type="filepath", label="Person Image"),
        gr.Image(type="filepath", label="Cloth Image")
    ],
    outputs=[
        gr.Image(label="2D Try-On Result"),
        gr.File(label="3D Mesh Output (.glb/.obj/.ply)")
    ],
    title="2D Try-On β†’ 3D Mesh Pipeline",
    description="Uploads a person image and clothing image β†’ performs virtual try-on β†’ generates a 3D mesh."
)

if __name__ == "__main__":
    demo.launch(share=True)  # Set share=True to create a public link