File size: 1,091 Bytes
f89d3ba
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from PIL import Image
import requests
from io import BytesIO

def try_on(user_image, clothing_choice):
    clothing_urls = {
        "Red Dress": "https://i.ibb.co/S3ddkZq/red-dress.png",
        "Moroccan Caftan": "https://i.ibb.co/xhZ4m6W/caftan.png",
        "Black Jacket": "https://i.ibb.co/pKRCsm2/jacket.png"
    }

    response = requests.get(clothing_urls[clothing_choice])
    clothing_img = Image.open(BytesIO(response.content)).convert("RGBA")

    user_img = user_image.convert("RGBA")
    clothing_img = clothing_img.resize(user_img.size)
    blended = Image.alpha_composite(user_img, clothing_img)
    return blended

demo = gr.Interface(
    fn=try_on,
    inputs=[
        gr.Image(type="pil", label="📷 ارفع صورتك"),
        gr.Radio(["Red Dress", "Moroccan Caftan", "Black Jacket"], label="👗 اختر اللباس")
    ],
    outputs=gr.Image(type="pil", label="📸 النتيجة"),
    title="🧥 تجربة اللباس الافتراضي",
    description="جرب لباساً افتراضياً على صورتك"
)

demo.launch()