Agregado SD 3.5 Large (Premium) al Space - Modelo de alta calidad con soporte completo
Browse files
app.py
CHANGED
|
@@ -107,6 +107,9 @@ MODELS = {
|
|
| 107 |
"black-forest-labs/FLUX.1-dev": "FLUX.1 Dev (Requiere acceso)",
|
| 108 |
"black-forest-labs/FLUX.1-schnell": "FLUX.1 Schnell (Requiere acceso)",
|
| 109 |
|
|
|
|
|
|
|
|
|
|
| 110 |
# 📦 Modelos adicionales
|
| 111 |
"CompVis/ldm-text2im-large-256": "Latent Diffusion Model 256"
|
| 112 |
},
|
|
@@ -234,6 +237,41 @@ def load_image_model(model_name):
|
|
| 234 |
safety_checker=None
|
| 235 |
)
|
| 236 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 237 |
# Configuración especial para SD 2.1 (problemático)
|
| 238 |
elif "stable-diffusion-2-1" in model_name:
|
| 239 |
try:
|
|
@@ -656,6 +694,11 @@ def generate_image(prompt, model_name, negative_prompt="", seed=0, width=1024, h
|
|
| 656 |
guidance_scale = max(3.5, min(guidance_scale, 7.5))
|
| 657 |
num_inference_steps = max(15, num_inference_steps)
|
| 658 |
print(f"🔐 Modelo FLUX - Ajustando parámetros: guidance={guidance_scale}, steps={num_inference_steps}")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 659 |
|
| 660 |
generator = torch.Generator(device=device).manual_seed(seed)
|
| 661 |
|
|
|
|
| 107 |
"black-forest-labs/FLUX.1-dev": "FLUX.1 Dev (Requiere acceso)",
|
| 108 |
"black-forest-labs/FLUX.1-schnell": "FLUX.1 Schnell (Requiere acceso)",
|
| 109 |
|
| 110 |
+
# 🌟 Modelos Premium de Alta Calidad
|
| 111 |
+
"stabilityai/stable-diffusion-3.5-large": "🌟 SD 3.5 Large (Alta Calidad)",
|
| 112 |
+
|
| 113 |
# 📦 Modelos adicionales
|
| 114 |
"CompVis/ldm-text2im-large-256": "Latent Diffusion Model 256"
|
| 115 |
},
|
|
|
|
| 237 |
safety_checker=None
|
| 238 |
)
|
| 239 |
|
| 240 |
+
# Configuración especial para SD 3.5 Large (Premium)
|
| 241 |
+
elif "stable-diffusion-3.5-large" in model_name:
|
| 242 |
+
try:
|
| 243 |
+
from diffusers import StableDiffusion3Pipeline
|
| 244 |
+
print("🌟 Cargando SD 3.5 Large (Premium)...")
|
| 245 |
+
print(f"🔧 Modelo: {model_name}")
|
| 246 |
+
|
| 247 |
+
# SD 3.5 Large requiere bfloat16 para mejor rendimiento
|
| 248 |
+
pipe = StableDiffusion3Pipeline.from_pretrained(
|
| 249 |
+
model_name,
|
| 250 |
+
torch_dtype=torch.bfloat16 if torch.cuda.is_available() else torch.float32,
|
| 251 |
+
use_auth_token=HF_TOKEN if HF_TOKEN else None
|
| 252 |
+
)
|
| 253 |
+
|
| 254 |
+
print("✅ SD 3.5 Large cargado exitosamente")
|
| 255 |
+
|
| 256 |
+
except Exception as e:
|
| 257 |
+
print(f"❌ Error cargando SD 3.5 Large: {e}")
|
| 258 |
+
print(f"🔍 Tipo de error: {type(e).__name__}")
|
| 259 |
+
|
| 260 |
+
# Si es un error de autenticación, dar instrucciones específicas
|
| 261 |
+
if "401" in str(e) or "unauthorized" in str(e).lower():
|
| 262 |
+
print("🔐 Error de autenticación. Asegúrate de:")
|
| 263 |
+
print(" 1. Tener acceso al modelo SD 3.5 Large en Hugging Face")
|
| 264 |
+
print(" 2. Configurar HF_TOKEN en las variables de entorno del Space")
|
| 265 |
+
print(" 3. Que el token tenga permisos para acceder a modelos gated")
|
| 266 |
+
|
| 267 |
+
# Fallback a SDXL
|
| 268 |
+
print("🔄 Fallback a SDXL...")
|
| 269 |
+
pipe = StableDiffusionPipeline.from_pretrained(
|
| 270 |
+
"stabilityai/stable-diffusion-xl-base-1.0",
|
| 271 |
+
torch_dtype=torch_dtype,
|
| 272 |
+
safety_checker=None
|
| 273 |
+
)
|
| 274 |
+
|
| 275 |
# Configuración especial para SD 2.1 (problemático)
|
| 276 |
elif "stable-diffusion-2-1" in model_name:
|
| 277 |
try:
|
|
|
|
| 694 |
guidance_scale = max(3.5, min(guidance_scale, 7.5))
|
| 695 |
num_inference_steps = max(15, num_inference_steps)
|
| 696 |
print(f"🔐 Modelo FLUX - Ajustando parámetros: guidance={guidance_scale}, steps={num_inference_steps}")
|
| 697 |
+
elif "stable-diffusion-3.5-large" in model_name:
|
| 698 |
+
# SD 3.5 Large funciona mejor con guidance_scale entre 3.5-4.5 y 28 steps
|
| 699 |
+
guidance_scale = max(3.5, min(guidance_scale, 4.5))
|
| 700 |
+
num_inference_steps = max(28, num_inference_steps)
|
| 701 |
+
print(f"🌟 SD 3.5 Large - Ajustando parámetros: guidance={guidance_scale}, steps={num_inference_steps}")
|
| 702 |
|
| 703 |
generator = torch.Generator(device=device).manual_seed(seed)
|
| 704 |
|