Spaces:
Sleeping
Sleeping
| """ | |
| Módulo generador de imágenes Sofía Rivera. | |
| Conectar aquí tu modelo real de IA. | |
| """ | |
| from PIL import Image, ImageDraw, ImageFont | |
| # Listas disponibles para el dropdown en app.py | |
| available_styles = ["Realista", "Anime", "Artístico", "Fotografía profesional"] | |
| available_outfits = [ | |
| "Bikini rojo playa", | |
| "Vestido noche elegante", | |
| "Ropa deportiva gym", | |
| "Jeans casual camiseta blanca" | |
| ] | |
| available_locations = [ | |
| "Playa atardecer", | |
| "Gym moderno", | |
| "Restaurante lujo", | |
| "Departamento ciudad", | |
| "Montañas naturaleza" | |
| ] | |
| def generate_sofia_image(prompt, style="realistic", size=(512, 768)): | |
| """ | |
| Genera imagen de Sofía Rivera según prompt. | |
| Args: | |
| prompt: Descripción textual | |
| style: Estilo visual (realista/anime/etc) | |
| size: Tamaño imagen (ancho, alto) | |
| Returns: | |
| str: Ruta al archivo de imagen generado | |
| """ | |
| # ====== IMPLEMENTACIÓN PLACEHOLDER ====== | |
| # Aquí conectarías tu modelo real de generación de imágenes | |
| try: | |
| # Crear imagen placeholder temporal | |
| img = Image.new('RGB', size, color=(73, 109, 137)) | |
| draw = ImageDraw.Draw(img) | |
| # Añadir texto placeholder (remover cuando tengas modelo real) | |
| text = f"Sofía Rivera\n{style} style" | |
| # Intentar cargar fuente (fallback si no existe) | |
| try: | |
| font = ImageFont.truetype("arial.ttf", 30) | |
| except: | |
| font = ImageFont.load_default() | |
| # Calcular posición texto centrado | |
| text_bbox = draw.textbbox((0, 0), text, font=font) | |
| text_width = text_bbox[2] - text_bbox[0] | |
| text_height = text_bbox[3] - text_bbox[1] | |
| x = (size[0] - text_width) // 2 | |
| y = (size[1] - text_height) // 2 | |
| # Dibujar texto | |
| draw.text((x, y), | |
| f"Sofía Rivera\n{style} style\n{prompt[:50]}...", | |
| fill=(255, 255, 255), | |
| font=font, | |
| align="center") | |
| # Guardar imagen temporal | |
| import tempfile | |
| temp_file = tempfile.NamedTemporaryFile(suffix='.jpg', delete=False) | |
| img.save(temp_file.name, 'JPEG') | |
| return temp_file.name | |
| except Exception as e: | |
| print(f"Error en generación de imagen: {e}") | |
| # Fallback: imagen completamente negra con error | |
| img = Image.new('RGB', size, color=(0, 0, 0)) | |
| temp_file = tempfile.NamedTemporaryFile(suffix='.jpg', delete=False) | |
| img.save(temp_file.name, 'JPEG') | |
| return temp_file.name | |
| # Función auxiliar para app.py (mantener compatibilidad) | |
| def generate_content(style, outfit, location): | |
| """Wrapper para la interfaz principal""" | |
| prompt = f"sofía rivera {style} style wearing {outfit} at {location}, professional photo" | |
| return generate_sofia_image(prompt, style=style.lower()) | |