Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,46 +1,45 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import
|
|
|
|
| 3 |
from PIL import Image
|
| 4 |
-
import
|
| 5 |
|
| 6 |
-
#
|
| 7 |
-
|
|
|
|
| 8 |
|
| 9 |
-
#
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
if response.status_code == 200:
|
| 22 |
-
# Suponiendo que la respuesta es una imagen generada (puede variar según el modelo)
|
| 23 |
-
output_image = Image.open(io.BytesIO(response.content))
|
| 24 |
-
return output_image
|
| 25 |
-
else:
|
| 26 |
-
return "Error al procesar las imágenes, intente nuevamente."
|
| 27 |
-
except Exception as e:
|
| 28 |
-
return f"Error: {str(e)}"
|
| 29 |
|
| 30 |
# Crear la interfaz de Gradio
|
| 31 |
iface = gr.Interface(
|
| 32 |
-
fn=
|
| 33 |
-
inputs=[
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
],
|
| 37 |
-
outputs=gr.Image(type="pil", label="Resultado del Probador Virtual"),
|
| 38 |
-
title="Probador Virtual AI",
|
| 39 |
-
description="Sube una foto de tu maniquí y una prenda para probarla en tiempo real con TryOnGAN."
|
| 40 |
)
|
| 41 |
|
| 42 |
-
#
|
| 43 |
-
|
| 44 |
-
iface.launch()
|
| 45 |
|
| 46 |
|
|
|
|
| 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 |
+
# Cargar el modelo preentrenado
|
| 8 |
+
fashion_gan_model = FashionGAN()
|
| 9 |
+
fashion_gan_model.load_state_dict(torch.load("fashion_gan_pretrained.pth")) # Cargar el modelo preentrenado
|
| 10 |
|
| 11 |
+
# Definir la transformación de imágenes
|
| 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 |
+
def try_on_virtual_outfit(person_image, outfit_image):
|
| 19 |
+
# Transformar las imágenes
|
| 20 |
+
person_image = transform(person_image).unsqueeze(0)
|
| 21 |
+
outfit_image = transform(outfit_image).unsqueeze(0)
|
| 22 |
+
|
| 23 |
+
# Pasar las imágenes por el modelo
|
| 24 |
+
generated_image = fashion_gan_model(person_image, outfit_image) # Esto depende de cómo se implementa FashionGAN
|
| 25 |
+
|
| 26 |
+
# Convertir la salida a imagen
|
| 27 |
+
generated_image = generated_image.squeeze(0).permute(1, 2, 0).detach().numpy()
|
| 28 |
+
generated_image = (generated_image * 255).astype('uint8')
|
| 29 |
|
| 30 |
+
# Convertir a una imagen PIL
|
| 31 |
+
generated_image = Image.fromarray(generated_image)
|
| 32 |
+
return generated_image
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
# Crear la interfaz de Gradio
|
| 35 |
iface = gr.Interface(
|
| 36 |
+
fn=try_on_virtual_outfit, # Función que procesará las imágenes
|
| 37 |
+
inputs=[gr.Image(type="pil", label="Imagen del maniquí"), gr.Image(type="pil", label="Imagen de la prenda")],
|
| 38 |
+
outputs=gr.Image(type="pil", label="Prueba de la prenda virtual"),
|
| 39 |
+
live=True
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
)
|
| 41 |
|
| 42 |
+
# Iniciar la aplicación
|
| 43 |
+
iface.launch()
|
|
|
|
| 44 |
|
| 45 |
|