Download app.py from DAM222222/PRUEBA1: direct link, hf CLI and curl.
- Browser
- Download file 1.22 kB
-
https://huggingface.co/spaces/DAM222222/PRUEBA1/resolve/main/app.py
- Command line
-
hf download hf://spaces/DAM222222/PRUEBA1/app.py
-
curl -L -o app.py https://huggingface.co/spaces/DAM222222/PRUEBA1/resolve/main/app.py
1.22 kB
| import gradio as gr | |
| from PIL import Image | |
| import torch | |
| from model import VITONModel # Asegúrate de que 'model.py' esté presente y contenga la clase VITONModel | |
| # Cargar el modelo | |
| model = VITONModel("checkpoint/model.pth") | |
| model.eval() | |
| def virtual_tryon(photo, cloth): | |
| """ | |
| photo: Imagen de la persona (PIL Image) | |
| cloth: Imagen de la prenda (PIL Image) | |
| """ | |
| # Preprocesamiento de las imágenes | |
| photo_tensor = preprocess_image(photo) | |
| cloth_tensor = preprocess_image(cloth) | |
| # Inferencia | |
| with torch.no_grad(): | |
| result_tensor = model(photo_tensor, cloth_tensor) | |
| # Postprocesamiento | |
| result_image = postprocess_image(result_tensor) | |
| return result_image | |
| def preprocess_image(image): | |
| # Implementa el preprocesamiento necesario para tu modelo | |
| pass | |
| def postprocess_image(tensor): | |
| # Implementa el postprocesamiento necesario para tu modelo | |
| pass | |
| # Interfaz de Gradio | |
| iface = gr.Interface( | |
| fn=virtual_tryon, | |
| inputs=[gr.Image(type="filepath"), gr.Image(type="filepath")], | |
| outputs=gr.Image(type="pil"), | |
| title="Prueba Virtual de Ropa", | |
| description="Sube una foto y una prenda para ver cómo te quedaría puesta." | |
| ) | |
| iface.launch() | |