Spaces:
Sleeping
Sleeping
Download app.py from DAM222222/PROBARROPA: direct link, hf CLI and curl.
- Browser
- Download file 1.13 kB
-
https://huggingface.co/spaces/DAM222222/PROBARROPA/resolve/main/app.py
- Command line
-
hf download hf://spaces/DAM222222/PROBARROPA/app.py
-
curl -L -o app.py https://huggingface.co/spaces/DAM222222/PROBARROPA/resolve/main/app.py
1.13 kB
| 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() |