Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from diffusers import StableDiffusionInpaintPipeline
|
| 3 |
+
import torch
|
| 4 |
+
from PIL import Image
|
| 5 |
+
|
| 6 |
+
pipe = StableDiffusionInpaintPipeline.from_pretrained(
|
| 7 |
+
"runwayml/stable-diffusion-inpainting",
|
| 8 |
+
torch_dtype=torch.float32
|
| 9 |
+
)
|
| 10 |
+
pipe = pipe.to("cpu")
|
| 11 |
+
|
| 12 |
+
def try_on(person_img, cloth_img):
|
| 13 |
+
person = person_img.resize((512, 512))
|
| 14 |
+
|
| 15 |
+
mask = Image.new("L", (512, 512), 0)
|
| 16 |
+
for x in range(150, 360):
|
| 17 |
+
for y in range(150, 400):
|
| 18 |
+
mask.putpixel((x, y), 255)
|
| 19 |
+
|
| 20 |
+
prompt = "a person wearing a t-shirt, realistic clothing fit"
|
| 21 |
+
|
| 22 |
+
result = pipe(
|
| 23 |
+
prompt=prompt,
|
| 24 |
+
image=person,
|
| 25 |
+
mask_image=mask
|
| 26 |
+
).images[0]
|
| 27 |
+
|
| 28 |
+
return result
|
| 29 |
+
|
| 30 |
+
demo = gr.Interface(
|
| 31 |
+
fn=try_on,
|
| 32 |
+
inputs=[
|
| 33 |
+
gr.Image(type="pil", label="Foto de la persona"),
|
| 34 |
+
gr.Image(type="pil", label="Imagen del polo")
|
| 35 |
+
],
|
| 36 |
+
outputs=gr.Image(type="pil", label="Resultado"),
|
| 37 |
+
title="Virtual Try-On",
|
| 38 |
+
description="Sube una foto y prueba un polo con IA"
|
| 39 |
+
)
|
| 40 |
+
|
| 41 |
+
demo.launch()
|