Ntdeseb commited on
Commit
2be6459
·
1 Parent(s): 15c37e7

Arreglado formato de salida de video para Gradio

Browse files
Files changed (1) hide show
  1. app.py +19 -19
app.py CHANGED
@@ -397,7 +397,7 @@ def load_image_model(model_name):
397
 
398
  # Habilitar optimizaciones de memoria (más conservadoras)
399
  if hasattr(pipe, 'enable_attention_slicing'):
400
- pipe.enable_attention_slicing()
401
  print("✅ Attention slicing habilitado")
402
 
403
  # Deshabilitar CPU offload temporalmente (causa problemas con ZeroGPU)
@@ -418,7 +418,7 @@ def load_image_model(model_name):
418
  try:
419
  pipe.enable_xformers_memory_efficient_attention()
420
  print("✅ XFormers memory efficient attention habilitado")
421
- except Exception as e:
422
  print(f"⚠️ XFormers no disponible: {e}")
423
  print("🔄 Usando atención estándar")
424
 
@@ -438,7 +438,7 @@ def load_image_model(model_name):
438
 
439
  # Guardar en cache
440
  model_cache[model_name] = pipe
441
-
442
  except Exception as e:
443
  print(f"❌ Error cargando modelo {model_name}: {e}")
444
  print(f"🔍 Tipo de error: {type(e).__name__}")
@@ -446,8 +446,8 @@ def load_image_model(model_name):
446
  # Intentar cargar sin variant fp16 si falló
447
  if "variant" in str(e) and "fp16" in str(e):
448
  print("🔄 Reintentando sin variant fp16...")
449
- try:
450
- pipe = StableDiffusionPipeline.from_pretrained(
451
  model_name,
452
  torch_dtype=torch_dtype,
453
  use_auth_token=HF_TOKEN if HF_TOKEN and ("flux" in model_name.lower() or "black-forest" in model_name.lower()) else None
@@ -777,7 +777,7 @@ def generate_image(
777
 
778
  result = pipe(**generation_kwargs)
779
  image = result.images[0]
780
- else:
781
  print("✅ Imagen generada correctamente")
782
  else:
783
  print("❌ Error: Imagen vacía")
@@ -931,7 +931,7 @@ def generate_video(prompt, model_name, num_frames=16, num_inference_steps=20):
931
  print(f"Forma no reconocida: {video_frames.shape}")
932
  return None
933
  else:
934
- return video_frames
935
 
936
  except Exception as e:
937
  print(f"Error generando video: {str(e)}")
@@ -1369,7 +1369,7 @@ with gr.Blocks(title="Modelos Libres de IA", theme=gr.themes.Soft()) as demo:
1369
  update_model_info,
1370
  inputs=[image_model],
1371
  outputs=[model_info]
1372
- )
1373
 
1374
  image_btn.click(
1375
  generate_image,
@@ -1434,17 +1434,17 @@ with gr.Blocks(title="Modelos Libres de IA", theme=gr.themes.Soft()) as demo:
1434
  )
1435
 
1436
  # Agregar endpoint para generate_video_with_info dentro del contexto de Gradio
1437
- demo.load(
1438
- generate_video_with_info,
1439
- inputs=[
1440
- gr.Textbox(label="Prompt", placeholder="Describe el video..."),
1441
- gr.Dropdown(choices=list(MODELS["video"].keys()), label="Modelo"),
1442
- gr.Dropdown(choices=["speed", "balanced", "quality"], value="balanced", label="Optimización"),
1443
- gr.Image(label="Imagen de entrada (opcional)", type="pil")
1444
- ],
1445
- outputs=gr.Video(label="Video Generado", format="mp4"),
1446
- api_name="generate_video_with_info"
1447
- )
1448
 
1449
  # Configuración para Hugging Face Spaces
1450
  if __name__ == "__main__":
 
397
 
398
  # Habilitar optimizaciones de memoria (más conservadoras)
399
  if hasattr(pipe, 'enable_attention_slicing'):
400
+ pipe.enable_attention_slicing()
401
  print("✅ Attention slicing habilitado")
402
 
403
  # Deshabilitar CPU offload temporalmente (causa problemas con ZeroGPU)
 
418
  try:
419
  pipe.enable_xformers_memory_efficient_attention()
420
  print("✅ XFormers memory efficient attention habilitado")
421
+ except Exception as e:
422
  print(f"⚠️ XFormers no disponible: {e}")
423
  print("🔄 Usando atención estándar")
424
 
 
438
 
439
  # Guardar en cache
440
  model_cache[model_name] = pipe
441
+
442
  except Exception as e:
443
  print(f"❌ Error cargando modelo {model_name}: {e}")
444
  print(f"🔍 Tipo de error: {type(e).__name__}")
 
446
  # Intentar cargar sin variant fp16 si falló
447
  if "variant" in str(e) and "fp16" in str(e):
448
  print("🔄 Reintentando sin variant fp16...")
449
+ try:
450
+ pipe = StableDiffusionPipeline.from_pretrained(
451
  model_name,
452
  torch_dtype=torch_dtype,
453
  use_auth_token=HF_TOKEN if HF_TOKEN and ("flux" in model_name.lower() or "black-forest" in model_name.lower()) else None
 
777
 
778
  result = pipe(**generation_kwargs)
779
  image = result.images[0]
780
+ else:
781
  print("✅ Imagen generada correctamente")
782
  else:
783
  print("❌ Error: Imagen vacía")
 
931
  print(f"Forma no reconocida: {video_frames.shape}")
932
  return None
933
  else:
934
+ return video_frames
935
 
936
  except Exception as e:
937
  print(f"Error generando video: {str(e)}")
 
1369
  update_model_info,
1370
  inputs=[image_model],
1371
  outputs=[model_info]
1372
+ )
1373
 
1374
  image_btn.click(
1375
  generate_image,
 
1434
  )
1435
 
1436
  # Agregar endpoint para generate_video_with_info dentro del contexto de Gradio
1437
+ demo.load(
1438
+ generate_video_with_info,
1439
+ inputs=[
1440
+ gr.Textbox(label="Prompt", placeholder="Describe el video..."),
1441
+ gr.Dropdown(choices=list(MODELS["video"].keys()), label="Modelo"),
1442
+ gr.Dropdown(choices=["speed", "balanced", "quality"], value="balanced", label="Optimización"),
1443
+ gr.Image(label="Imagen de entrada (opcional)", type="pil")
1444
+ ],
1445
+ outputs=gr.Video(label="Video Generado", format="mp4"),
1446
+ api_name="generate_video_with_info"
1447
+ )
1448
 
1449
  # Configuración para Hugging Face Spaces
1450
  if __name__ == "__main__":