Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,45 +1,62 @@
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
import torch
|
| 3 |
from torchvision import transforms
|
| 4 |
-
from PIL import Image
|
| 5 |
-
from fashion_gan import FashionGAN # Reemplaza esto con la clase o el modelo real de FashionGAN
|
| 6 |
|
| 7 |
-
#
|
| 8 |
-
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
-
#
|
| 12 |
transform = transforms.Compose([
|
| 13 |
transforms.Resize((256, 256)),
|
| 14 |
-
transforms.ToTensor()
|
| 15 |
-
transforms.Normalize((0.5, 0.5, 0.5), (0.5, 0.5, 0.5)) # Normalización
|
| 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 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from PIL import Image
|
| 3 |
import torch
|
| 4 |
from torchvision import transforms
|
|
|
|
|
|
|
| 5 |
|
| 6 |
+
# Aquí deberías importar tu modelo real
|
| 7 |
+
# Este es un ejemplo genérico
|
| 8 |
+
class DummyFashionGAN(torch.nn.Module):
|
| 9 |
+
def forward(self, person, clothes):
|
| 10 |
+
# Este es solo un dummy para no lanzar errores
|
| 11 |
+
return person
|
| 12 |
+
|
| 13 |
+
# Cargar modelo (usa tu modelo real aquí)
|
| 14 |
+
model = DummyFashionGAN()
|
| 15 |
+
model.eval()
|
| 16 |
|
| 17 |
+
# Transformación de imágenes
|
| 18 |
transform = transforms.Compose([
|
| 19 |
transforms.Resize((256, 256)),
|
| 20 |
+
transforms.ToTensor()
|
|
|
|
| 21 |
])
|
| 22 |
|
| 23 |
+
# Función principal con depuración
|
| 24 |
+
def tryon(person_img, clothes_img):
|
| 25 |
+
try:
|
| 26 |
+
print("📤 Iniciando procesamiento de imágenes...")
|
| 27 |
+
|
| 28 |
+
person = transform(person_img).unsqueeze(0)
|
| 29 |
+
clothes = transform(clothes_img).unsqueeze(0)
|
| 30 |
+
|
| 31 |
+
print("✅ Imágenes cargadas y transformadas.")
|
| 32 |
+
|
| 33 |
+
with torch.no_grad():
|
| 34 |
+
output = model(person, clothes)
|
| 35 |
+
|
| 36 |
+
print("🎯 Generación de imagen completada.")
|
| 37 |
+
|
| 38 |
+
result = transforms.ToPILImage()(output.squeeze(0).clamp(0, 1))
|
| 39 |
+
return result
|
| 40 |
+
|
| 41 |
+
except Exception as e:
|
| 42 |
+
print("❌ Error durante el procesamiento:", str(e))
|
| 43 |
+
# Devolver una imagen roja como error
|
| 44 |
+
return Image.new("RGB", (256, 256), color="red")
|
| 45 |
+
|
| 46 |
+
# Interfaz de Gradio
|
| 47 |
+
demo = gr.Interface(
|
| 48 |
+
fn=tryon,
|
| 49 |
+
inputs=[
|
| 50 |
+
gr.Image(label="👤 Tu maniquí o imagen de cuerpo", type="pil"),
|
| 51 |
+
gr.Image(label="👕 Imagen de la prenda", type="pil")
|
| 52 |
+
],
|
| 53 |
+
outputs=gr.Image(label="🪄 Resultado: Prueba virtual"),
|
| 54 |
+
title="👗 Probador Virtual AI",
|
| 55 |
+
description="Sube una imagen tuya (o maniquí) y una prenda para probarla virtualmente. Esta es una demo."
|
| 56 |
)
|
| 57 |
|
| 58 |
+
# Lanzar app
|
| 59 |
+
if __name__ == "__main__":
|
| 60 |
+
demo.launch()
|
| 61 |
|
| 62 |
|