File size: 999 Bytes
ebd8091 | 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 | import gradio as gr
from diffusers import StableDiffusionInpaintPipeline
import torch
from PIL import Image
pipe = StableDiffusionInpaintPipeline.from_pretrained(
"runwayml/stable-diffusion-inpainting",
torch_dtype=torch.float32
)
pipe = pipe.to("cpu")
def try_on(person_img, cloth_img):
person = person_img.resize((512, 512))
mask = Image.new("L", (512, 512), 0)
for x in range(150, 360):
for y in range(150, 400):
mask.putpixel((x, y), 255)
prompt = "a person wearing a t-shirt, realistic clothing fit"
result = pipe(
prompt=prompt,
image=person,
mask_image=mask
).images[0]
return result
demo = gr.Interface(
fn=try_on,
inputs=[
gr.Image(type="pil", label="Foto de la persona"),
gr.Image(type="pil", label="Imagen del polo")
],
outputs=gr.Image(type="pil", label="Resultado"),
title="Virtual Try-On",
description="Sube una foto y prueba un polo con IA"
)
demo.launch() |