gnosticdev commited on
Commit
e018b67
·
verified ·
1 Parent(s): d2b50fe

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -15
app.py CHANGED
@@ -643,7 +643,7 @@ async def run_app_async(prompt_type, prompt_ia, prompt_manual, musica_file, sele
643
  input_text = prompt_ia if prompt_type == "Generar Guion con IA" else prompt_manual
644
  output_video = None
645
  output_file = None
646
- status_msg = gr.update(value="⏳ Procesando... Esto puede tomar hasta 1 hora.")
647
 
648
  if not input_text or not input_text.strip():
649
  logger.warning("Texto de entrada vacío.")
@@ -655,25 +655,49 @@ async def run_app_async(prompt_type, prompt_ia, prompt_manual, musica_file, sele
655
  selected_voice = DEFAULT_VOICE_ID
656
 
657
  try:
658
- logger.info("Iniciando generación de video...")
659
- video_path, download_url = await crear_video_async(prompt_type, input_text, selected_voice, musica_file)
660
- if video_path and os.path.exists(video_path):
661
- output_video = video_path
662
- output_file = video_path
663
- status_msg = gr.update(value=f"✅ Video generado exitosamente. Descarga: {download_url}")
664
- logger.info(f"Retornando video_path: {video_path}, URL: {download_url}")
665
- else:
666
- status_msg = gr.update(value="❌ Error: Falló la generación del video.")
667
- logger.error("No se generó video_path válido.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
668
  except ValueError as ve:
669
  logger.warning(f"Error de validación: {str(ve)}")
670
  status_msg = gr.update(value=f"⚠️ Error: {str(ve)}")
 
671
  except Exception as e:
672
  logger.critical(f"Error crítico: {str(e)}")
673
  status_msg = gr.update(value=f"❌ Error inesperado: {str(e)}")
674
- finally:
675
- logger.info("Finalizando run_app_async")
676
- return output_video, gr.File(value=output_file, label="Descargar Video"), status_msg
677
 
678
  def run_app(prompt_type, prompt_ia, prompt_manual, musica_file, selected_voice):
679
  return asyncio.run(run_app_async(prompt_type, prompt_ia, prompt_manual, musica_file, selected_voice))
@@ -741,7 +765,7 @@ with gr.Blocks(title="Generador de Videos con IA", theme=gr.themes.Soft()) as ap
741
  )
742
 
743
  generate_btn.click(
744
- fn=lambda: (None, None, gr.update(value="⏳ Procesando... Esto puede tomar hasta 1 hora.")),
745
  outputs=[video_output, file_output, status_output]
746
  ).then(
747
  fn=run_app,
 
643
  input_text = prompt_ia if prompt_type == "Generar Guion con IA" else prompt_manual
644
  output_video = None
645
  output_file = None
646
+ status_msg = gr.update(value="⏳ Iniciando generación de video...")
647
 
648
  if not input_text or not input_text.strip():
649
  logger.warning("Texto de entrada vacío.")
 
655
  selected_voice = DEFAULT_VOICE_ID
656
 
657
  try:
658
+ # Crear tarea para generar video
659
+ task = asyncio.create_task(crear_video_async(prompt_type, input_text, selected_voice, musica_file))
660
+
661
+ # Verificar progreso cada 5 segundos durante 10 minutos (600s)
662
+ timeout = 600
663
+ interval = 5
664
+ elapsed = 0
665
+ while elapsed < timeout:
666
+ if task.done():
667
+ video_path, download_url = await task
668
+ if video_path and os.path.exists(video_path):
669
+ output_video = video_path
670
+ output_file = video_path
671
+ status_msg = gr.update(value=f"✅ Video generado exitosamente. Descarga: {download_url}")
672
+ logger.info(f"Retornando video_path: {video_path}, URL: {download_url}")
673
+ return output_video, gr.File(value=output_file, label="Descargar Video"), status_msg
674
+ else:
675
+ status_msg = gr.update(value="❌ Error: Falló la generación del video.")
676
+ logger.error("No se generó video_path válido.")
677
+ return None, None, status_msg
678
+ await asyncio.sleep(interval)
679
+ elapsed += interval
680
+ status_msg = gr.update(value=f"⏳ Procesando... Tiempo transcurrido: {elapsed}s")
681
+ logger.debug(f"Esperando video, tiempo transcurrido: {elapsed}s")
682
+
683
+ # Si se excede el timeout
684
+ logger.error("Tiempo de espera excedido para la generación del video.")
685
+ status_msg = gr.update(value="❌ Error: Tiempo de espera excedido (10 minutos).")
686
+ task.cancel()
687
+ try:
688
+ await task
689
+ except asyncio.CancelledError:
690
+ pass
691
+ return None, None, status_msg
692
+
693
  except ValueError as ve:
694
  logger.warning(f"Error de validación: {str(ve)}")
695
  status_msg = gr.update(value=f"⚠️ Error: {str(ve)}")
696
+ return None, None, status_msg
697
  except Exception as e:
698
  logger.critical(f"Error crítico: {str(e)}")
699
  status_msg = gr.update(value=f"❌ Error inesperado: {str(e)}")
700
+ return None, None, status_msg
 
 
701
 
702
  def run_app(prompt_type, prompt_ia, prompt_manual, musica_file, selected_voice):
703
  return asyncio.run(run_app_async(prompt_type, prompt_ia, prompt_manual, musica_file, selected_voice))
 
765
  )
766
 
767
  generate_btn.click(
768
+ fn=lambda: (None, None, gr.update(value="⏳ Iniciando generación de video...")),
769
  outputs=[video_output, file_output, status_output]
770
  ).then(
771
  fn=run_app,