File size: 2,090 Bytes
505333f
 
 
8b52aba
 
174a123
 
7db932e
8b52aba
 
 
 
7db932e
 
 
 
505333f
 
 
 
 
 
 
 
 
 
edc5fcf
7db932e
edc5fcf
505333f
8b52aba
505333f
 
 
4ad3bee
 
 
 
 
 
505333f
 
4ad3bee
 
505333f
4ad3bee
 
505333f
 
4ad3bee
505333f
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
41
42
43
44
45
46
47
48
49
50
51
52
import gradio as gr
from gradio_client import Client, file

# Function to perform virtual try-on based on the selected model
def virtual_try_on(background, garment, garment_desc, denoise_steps, seed, model_choice):
    print(f"Model selected: {model_choice}")  # Debugging line to confirm the model choice
    
    # Initialize the client based on the selected model
    if model_choice == "IDM-VTON":
        client = Client("yisol/IDM-VTON")
    elif model_choice == "Virtual-Try-On":
        client = Client("Nymbo/Virtual-Try-On")
    else:
        raise ValueError("Model choice not recognized")  # Handle any unexpected model choice

    # Make the prediction using the selected model's API
    result = client.predict(
        dict={"background": file(background) if background else None, "layers": [], "composite": None},
        garm_img=file(garment),
        garment_des=garment_desc,
        is_checked=True,
        is_checked_crop=False,
        denoise_steps=denoise_steps,
        seed=seed,
        api_name="/tryon"
    )
    
    # Return the resulting images
    return result[0], result[1]  # First output: image, Second output: masked image

# Gradio interface
iface = gr.Interface(
    fn=virtual_try_on,
    inputs=[
        gr.Radio(choices=["IDM-VTON", "Virtual-Try-On"], label="اختر النموذج", value="IDM-VTON"),
        gr.Image(type="filepath", label="صورة الشخص"),
        gr.Image(type="filepath", label="صورة الملابس"),
        gr.Textbox(label="وصف الملابس (اختياري)"),
        gr.Slider(minimum=1, maximum=50, value=30, label="عدد خطوات التنقية"),
        gr.Slider(minimum=0, maximum=100, value=42, label="البذرة")
    ],
    outputs=[
        gr.Image(label="الصورة الناتجة"),
        gr.Image(label="الصورة المقنعة الناتجة")
    ],
    title="تجربة الملابس الافتراضية",
    description="اختر بين نموذجين لتجربة الملابس الافتراضية ورفع الصور."
)

# Launch the interface
iface.launch()