Spaces:
Sleeping
Sleeping
Update modules/image_gen.py
Browse files- modules/image_gen.py +80 -0
modules/image_gen.py
CHANGED
|
@@ -14,4 +14,84 @@ available_outfits = [
|
|
| 14 |
"Jeans casual camiseta blanca"
|
| 15 |
]
|
| 16 |
available_locations = [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
"Jeans casual camiseta blanca"
|
| 15 |
]
|
| 16 |
available_locations = [
|
| 17 |
+
"Playa atardecer",
|
| 18 |
+
"Gym moderno",
|
| 19 |
+
"Restaurante lujo",
|
| 20 |
+
"Departamento ciudad",
|
| 21 |
+
"Montañas naturaleza"
|
| 22 |
+
]
|
| 23 |
+
|
| 24 |
+
def generate_sofia_image(prompt, style="realistic", size=(512, 768)):
|
| 25 |
+
"""
|
| 26 |
+
Genera imagen de Sofía Rivera según prompt.
|
| 27 |
+
|
| 28 |
+
Args:
|
| 29 |
+
prompt: Descripción textual
|
| 30 |
+
style: Estilo visual (realista/anime/etc)
|
| 31 |
+
size: Tamaño imagen (ancho, alto)
|
| 32 |
+
|
| 33 |
+
Returns:
|
| 34 |
+
str: Ruta al archivo de imagen generado
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
"""
|
| 38 |
|
| 39 |
+
# ====== IMPLEMENTACIÓN PLACEHOLDER ======
|
| 40 |
+
# Aquí conectarías tu modelo real de generación de imágenes
|
| 41 |
+
|
| 42 |
+
try:
|
| 43 |
+
# Crear imagen placeholder temporal
|
| 44 |
+
img = Image.new('RGB', size, color=(73, 109, 137))
|
| 45 |
+
|
| 46 |
+
draw = ImageDraw.Draw(img)
|
| 47 |
+
|
| 48 |
+
# Añadir texto placeholder (remover cuando tengas modelo real)
|
| 49 |
+
text = f"Sofía Rivera\n{style} style"
|
| 50 |
+
|
| 51 |
+
# Intentar cargar fuente (fallback si no existe)
|
| 52 |
+
try:
|
| 53 |
+
font = ImageFont.truetype("arial.ttf", 30)
|
| 54 |
+
except:
|
| 55 |
+
font = ImageFont.load_default()
|
| 56 |
+
|
| 57 |
+
# Calcular posición texto centrado
|
| 58 |
+
text_bbox = draw.textbbox((0, 0), text, font=font)
|
| 59 |
+
text_width = text_bbox[2] - text_bbox[0]
|
| 60 |
+
|
| 61 |
+
text_height = text_bbox[3] - text_bbox[1]
|
| 62 |
+
|
| 63 |
+
x = (size[0] - text_width) // 2
|
| 64 |
+
y = (size[1] - text_height) // 2
|
| 65 |
+
|
| 66 |
+
# Dibujar texto
|
| 67 |
+
draw.text((x, y),
|
| 68 |
+
f"Sofía Rivera\n{style} style\n{prompt[:50]}...",
|
| 69 |
+
fill=(255, 255, 255),
|
| 70 |
+
font=font,
|
| 71 |
+
align="center")
|
| 72 |
+
|
| 73 |
+
# Guardar imagen temporal
|
| 74 |
+
import tempfile
|
| 75 |
+
temp_file = tempfile.NamedTemporaryFile(suffix='.jpg', delete=False)
|
| 76 |
+
img.save(temp_file.name, 'JPEG')
|
| 77 |
+
|
| 78 |
+
return temp_file.name
|
| 79 |
+
|
| 80 |
+
except Exception as e:
|
| 81 |
+
print(f"Error en generación de imagen: {e}")
|
| 82 |
+
|
| 83 |
+
# Fallback: imagen completamente negra con error
|
| 84 |
+
img = Image.new('RGB', size, color=(0, 0, 0))
|
| 85 |
+
temp_file = tempfile.NamedTemporaryFile(suffix='.jpg', delete=False)
|
| 86 |
+
img.save(temp_file.name, 'JPEG')
|
| 87 |
+
|
| 88 |
+
return temp_file.name
|
| 89 |
+
|
| 90 |
+
# Función auxiliar para app.py (mantener compatibilidad)
|
| 91 |
+
def generate_content(style, outfit, location):
|
| 92 |
+
"""Wrapper para la interfaz principal"""
|
| 93 |
+
|
| 94 |
+
prompt = f"sofía rivera {style} style wearing {outfit} at {location}, professional photo"
|
| 95 |
+
|
| 96 |
+
return generate_sofia_image(prompt, style=style.lower())
|
| 97 |
+
|