File size: 1,133 Bytes
4c753e2
 
 
 
 
9251258
4c753e2
 
 
 
9251258
4c753e2
 
9251258
 
 
 
4c753e2
9251258
4c753e2
9251258
 
 
4c753e2
 
9251258
4c753e2
9251258
 
 
 
 
 
 
4c753e2
 
 
9251258
4c753e2
 
 
9251258
 
4c753e2
 
9251258
4c753e2
 
 
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
import gradio as gr
from diffusers import StableDiffusionInpaintPipeline
import torch
from PIL import Image

# 🔥 cargar modelo
pipe = StableDiffusionInpaintPipeline.from_pretrained(
    "runwayml/stable-diffusion-inpainting",
    torch_dtype=torch.float32
)

pipe = pipe.to("cpu")

# 🔥 optimización (IMPORTANTE)
pipe.enable_attention_slicing()

# 🔧 función principal
def try_on(person_img, cloth_img):
    person = person_img.resize((384, 384))  # más rápido

    mask = Image.new("L", (384, 384), 0)
    for x in range(100, 280):
        for y in range(120, 300):
            mask.putpixel((x, y), 255)

    prompt = "a person wearing a t-shirt"

    with torch.no_grad():
        result = pipe(
            prompt=prompt,
            image=person,
            mask_image=mask,
            num_inference_steps=20
        ).images[0]

    return result

# 🎨 interfaz
demo = gr.Interface(
    fn=try_on,
    inputs=[
        gr.Image(type="pil", label="Foto persona"),
        gr.Image(type="pil", label="Prenda")
    ],
    outputs=gr.Image(type="pil", label="Resultado"),
    title="TIENDA DE ROPA",
)

demo.launch()