Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -15,6 +15,7 @@ import math
|
|
15 |
import shutil
|
16 |
import json
|
17 |
from collections import Counter
|
|
|
18 |
|
19 |
# Configuración de logging
|
20 |
logging.basicConfig(
|
@@ -98,7 +99,7 @@ def get_voice_choices():
|
|
98 |
choices = []
|
99 |
for region, voices in VOCES_DISPONIBLES.items():
|
100 |
for voice_id, voice_name in voices.items():
|
101 |
-
choices.append((f"{voice_name} ({region})", voice_id))
|
102 |
return choices
|
103 |
|
104 |
# Obtener las voces al inicio del script
|
@@ -336,7 +337,7 @@ def extract_visual_keywords_from_script(script_text):
|
|
336 |
logger.info(f"Palabras clave finales: {top_keywords}")
|
337 |
return top_keywords
|
338 |
|
339 |
-
def
|
340 |
logger.info("="*80)
|
341 |
logger.info(f"INICIANDO CREACIÓN DE VIDEO | Tipo: {prompt_type}")
|
342 |
logger.debug(f"Input: '{input_text[:100]}...'")
|
@@ -372,7 +373,7 @@ def crear_video(prompt_type, input_text, selected_voice, musica_file=None):
|
|
372 |
continue
|
373 |
tried_voices.add(current_voice)
|
374 |
logger.info(f"Intentando TTS con voz: {current_voice}...")
|
375 |
-
tts_success =
|
376 |
if tts_success:
|
377 |
break
|
378 |
|
@@ -558,7 +559,7 @@ def crear_video(prompt_type, input_text, selected_voice, musica_file=None):
|
|
558 |
except:
|
559 |
logger.warning(f"No se pudo eliminar {path}")
|
560 |
|
561 |
-
def
|
562 |
logger.info("="*80)
|
563 |
logger.info("SOLICITUD RECIBIDA EN INTERFAZ")
|
564 |
input_text = prompt_ia if prompt_type == "Generar Guion con IA" else prompt_manual
|
@@ -576,11 +577,11 @@ def run_app(prompt_type, prompt_ia, prompt_manual, musica_file, selected_voice):
|
|
576 |
selected_voice = DEFAULT_VOICE_ID
|
577 |
|
578 |
try:
|
579 |
-
video_path =
|
580 |
if video_path and os.path.exists(video_path):
|
581 |
output_video = video_path
|
582 |
output_file = video_path
|
583 |
-
status_msg = gr.update(value="✅ Video generado exitosamente.")
|
584 |
else:
|
585 |
status_msg = gr.update(value="❌ Error: Falló la generación del video.")
|
586 |
except ValueError as ve:
|
@@ -591,6 +592,9 @@ def run_app(prompt_type, prompt_ia, prompt_manual, musica_file, selected_voice):
|
|
591 |
status_msg = gr.update(value=f"❌ Error inesperado: {str(e)}")
|
592 |
return output_video, output_file, status_msg
|
593 |
|
|
|
|
|
|
|
594 |
# Interfaz de Gradio
|
595 |
with gr.Blocks(title="Generador de Videos con IA", theme=gr.themes.Soft()) as app:
|
596 |
gr.Markdown("# 🎬 Generador Automático de Videos con IA")
|
@@ -673,8 +677,8 @@ with gr.Blocks(title="Generador de Videos con IA", theme=gr.themes.Soft()) as ap
|
|
673 |
3. Sube música (opcional).
|
674 |
4. Selecciona la voz.
|
675 |
5. Haz clic en "✨ Generar Video".
|
676 |
-
6. Revisa el estado
|
677 |
-
7. Consulta `video_generator_full.log` para
|
678 |
""")
|
679 |
|
680 |
if __name__ == "__main__":
|
@@ -687,7 +691,7 @@ if __name__ == "__main__":
|
|
687 |
except Exception as e:
|
688 |
logger.critical(f"Fallo en dependencias: {e}")
|
689 |
raise
|
690 |
-
os.environ['GRADIO_SERVER_TIMEOUT'] = '
|
691 |
logger.info("Iniciando aplicación Gradio...")
|
692 |
try:
|
693 |
app.launch(server_name="0.0.0.0", server_port=7860, share=False)
|
|
|
15 |
import shutil
|
16 |
import json
|
17 |
from collections import Counter
|
18 |
+
import time
|
19 |
|
20 |
# Configuración de logging
|
21 |
logging.basicConfig(
|
|
|
99 |
choices = []
|
100 |
for region, voices in VOCES_DISPONIBLES.items():
|
101 |
for voice_id, voice_name in voices.items():
|
102 |
+
choices.append((f " {voice_name} ({region})", voice_id))
|
103 |
return choices
|
104 |
|
105 |
# Obtener las voces al inicio del script
|
|
|
337 |
logger.info(f"Palabras clave finales: {top_keywords}")
|
338 |
return top_keywords
|
339 |
|
340 |
+
async def crear_video_async(prompt_type, input_text, selected_voice, musica_file=None):
|
341 |
logger.info("="*80)
|
342 |
logger.info(f"INICIANDO CREACIÓN DE VIDEO | Tipo: {prompt_type}")
|
343 |
logger.debug(f"Input: '{input_text[:100]}...'")
|
|
|
373 |
continue
|
374 |
tried_voices.add(current_voice)
|
375 |
logger.info(f"Intentando TTS con voz: {current_voice}...")
|
376 |
+
tts_success = await text_to_speech(guion, voz_path, current_voice)
|
377 |
if tts_success:
|
378 |
break
|
379 |
|
|
|
559 |
except:
|
560 |
logger.warning(f"No se pudo eliminar {path}")
|
561 |
|
562 |
+
async def run_app_async(prompt_type, prompt_ia, prompt_manual, musica_file, selected_voice):
|
563 |
logger.info("="*80)
|
564 |
logger.info("SOLICITUD RECIBIDA EN INTERFAZ")
|
565 |
input_text = prompt_ia if prompt_type == "Generar Guion con IA" else prompt_manual
|
|
|
577 |
selected_voice = DEFAULT_VOICE_ID
|
578 |
|
579 |
try:
|
580 |
+
video_path = await crear_video_async(prompt_type, input_text, selected_voice, musica_file)
|
581 |
if video_path and os.path.exists(video_path):
|
582 |
output_video = video_path
|
583 |
output_file = video_path
|
584 |
+
status_msg = gr.update(value="✅ Video generado exitosamente. Descarga disponible en /tmp.")
|
585 |
else:
|
586 |
status_msg = gr.update(value="❌ Error: Falló la generación del video.")
|
587 |
except ValueError as ve:
|
|
|
592 |
status_msg = gr.update(value=f"❌ Error inesperado: {str(e)}")
|
593 |
return output_video, output_file, status_msg
|
594 |
|
595 |
+
def run_app(prompt_type, prompt_ia, prompt_manual, musica_file, selected_voice):
|
596 |
+
return asyncio.run(run_app_async(prompt_type, prompt_ia, prompt_manual, musica_file, selected_voice))
|
597 |
+
|
598 |
# Interfaz de Gradio
|
599 |
with gr.Blocks(title="Generador de Videos con IA", theme=gr.themes.Soft()) as app:
|
600 |
gr.Markdown("# 🎬 Generador Automático de Videos con IA")
|
|
|
677 |
3. Sube música (opcional).
|
678 |
4. Selecciona la voz.
|
679 |
5. Haz clic en "✨ Generar Video".
|
680 |
+
6. Revisa el estado. Si el video se genera, estará disponible en /tmp.
|
681 |
+
7. Consulta `video_generator_full.log` para detalles.
|
682 |
""")
|
683 |
|
684 |
if __name__ == "__main__":
|
|
|
691 |
except Exception as e:
|
692 |
logger.critical(f"Fallo en dependencias: {e}")
|
693 |
raise
|
694 |
+
os.environ['GRADIO_SERVER_TIMEOUT'] = '3600'
|
695 |
logger.info("Iniciando aplicación Gradio...")
|
696 |
try:
|
697 |
app.launch(server_name="0.0.0.0", server_port=7860, share=False)
|