Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -732,7 +732,7 @@ def crear_video(prompt_type, input_text, musica_file=None):
|
|
| 732 |
except Exception as e:
|
| 733 |
logger.warning(f"Error ajustando duración del audio final: {str(e)}")
|
| 734 |
|
| 735 |
-
|
| 736 |
logger.info("Renderizando video final...")
|
| 737 |
video_final = video_base.set_audio(final_audio)
|
| 738 |
|
|
@@ -744,14 +744,13 @@ def crear_video(prompt_type, input_text, musica_file=None):
|
|
| 744 |
output_path = os.path.join(temp_dir_intermediate, output_filename)
|
| 745 |
logger.info(f"Escribiendo video final a: {output_path}")
|
| 746 |
|
| 747 |
-
# Verificar que output_path sea válido
|
| 748 |
if not output_path or not isinstance(output_path, str):
|
| 749 |
logger.critical(f"output_path no es válido: {output_path}")
|
| 750 |
raise ValueError("El nombre del archivo de salida no es válido.")
|
| 751 |
|
| 752 |
try:
|
| 753 |
video_final.write_videofile(
|
| 754 |
-
filename=output_path,
|
| 755 |
fps=24,
|
| 756 |
threads=4,
|
| 757 |
codec="libx264",
|
|
@@ -843,16 +842,16 @@ def run_app(prompt_type, prompt_ia, prompt_manual, musica_file):
|
|
| 843 |
logger.info("="*80)
|
| 844 |
logger.info("SOLICITUD RECIBIDA EN INTERFAZ")
|
| 845 |
|
| 846 |
-
# Elegir el texto de entrada basado en el prompt_type
|
| 847 |
input_text = prompt_ia if prompt_type == "Generar Guion con IA" else prompt_manual
|
| 848 |
|
| 849 |
output_video = None
|
| 850 |
-
output_file = None
|
| 851 |
status_msg = gr.update(value="⏳ Procesando...", interactive=False)
|
| 852 |
|
| 853 |
if not input_text or not input_text.strip():
|
| 854 |
logger.warning("Texto de entrada vacío.")
|
| 855 |
-
|
|
|
|
| 856 |
|
| 857 |
logger.info(f"Tipo de entrada: {prompt_type}")
|
| 858 |
logger.debug(f"Texto de entrada: '{input_text[:100]}...'")
|
|
@@ -869,7 +868,7 @@ def run_app(prompt_type, prompt_ia, prompt_manual, musica_file):
|
|
| 869 |
logger.info(f"crear_video retornó path: {video_path}")
|
| 870 |
logger.info(f"Tamaño del archivo de video retornado: {os.path.getsize(video_path)} bytes")
|
| 871 |
output_video = video_path
|
| 872 |
-
output_file = video_path
|
| 873 |
status_msg = gr.update(value="✅ Video generado exitosamente.", interactive=False)
|
| 874 |
else:
|
| 875 |
logger.error(f"crear_video no retornó un path válido o el archivo no existe: {video_path}")
|
|
@@ -885,7 +884,6 @@ def run_app(prompt_type, prompt_ia, prompt_manual, musica_file):
|
|
| 885 |
logger.info("Fin del handler run_app.")
|
| 886 |
return output_video, output_file, status_msg
|
| 887 |
|
| 888 |
-
# Interfaz de Gradio
|
| 889 |
with gr.Blocks(title="Generador de Videos con IA", theme=gr.themes.Soft(), css="""
|
| 890 |
.gradio-container {max-width: 800px; margin: auto;}
|
| 891 |
h1 {text-align: center;}
|
|
@@ -963,10 +961,6 @@ with gr.Blocks(title="Generador de Videos con IA", theme=gr.themes.Soft(), css="
|
|
| 963 |
run_app,
|
| 964 |
inputs=[prompt_type, prompt_ia, prompt_manual, musica_input],
|
| 965 |
outputs=[video_output, file_output, status_output]
|
| 966 |
-
).then(
|
| 967 |
-
lambda video_path, file_path, status_msg: gr.update(visible=file_path is not None),
|
| 968 |
-
inputs=[video_output, file_output, status_output],
|
| 969 |
-
outputs=[file_output]
|
| 970 |
)
|
| 971 |
|
| 972 |
gr.Markdown("### Instrucciones:")
|
|
|
|
| 732 |
except Exception as e:
|
| 733 |
logger.warning(f"Error ajustando duración del audio final: {str(e)}")
|
| 734 |
|
| 735 |
+
# 7. Crear video final
|
| 736 |
logger.info("Renderizando video final...")
|
| 737 |
video_final = video_base.set_audio(final_audio)
|
| 738 |
|
|
|
|
| 744 |
output_path = os.path.join(temp_dir_intermediate, output_filename)
|
| 745 |
logger.info(f"Escribiendo video final a: {output_path}")
|
| 746 |
|
|
|
|
| 747 |
if not output_path or not isinstance(output_path, str):
|
| 748 |
logger.critical(f"output_path no es válido: {output_path}")
|
| 749 |
raise ValueError("El nombre del archivo de salida no es válido.")
|
| 750 |
|
| 751 |
try:
|
| 752 |
video_final.write_videofile(
|
| 753 |
+
filename=output_path,
|
| 754 |
fps=24,
|
| 755 |
threads=4,
|
| 756 |
codec="libx264",
|
|
|
|
| 842 |
logger.info("="*80)
|
| 843 |
logger.info("SOLICITUD RECIBIDA EN INTERFAZ")
|
| 844 |
|
|
|
|
| 845 |
input_text = prompt_ia if prompt_type == "Generar Guion con IA" else prompt_manual
|
| 846 |
|
| 847 |
output_video = None
|
| 848 |
+
output_file = gr.update(value=None, visible=False)
|
| 849 |
status_msg = gr.update(value="⏳ Procesando...", interactive=False)
|
| 850 |
|
| 851 |
if not input_text or not input_text.strip():
|
| 852 |
logger.warning("Texto de entrada vacío.")
|
| 853 |
+
status_msg = gr.update(value="⚠️ Por favor, ingresa texto para el guion o el tema.", interactive=False)
|
| 854 |
+
return output_video, output_file, status_msg
|
| 855 |
|
| 856 |
logger.info(f"Tipo de entrada: {prompt_type}")
|
| 857 |
logger.debug(f"Texto de entrada: '{input_text[:100]}...'")
|
|
|
|
| 868 |
logger.info(f"crear_video retornó path: {video_path}")
|
| 869 |
logger.info(f"Tamaño del archivo de video retornado: {os.path.getsize(video_path)} bytes")
|
| 870 |
output_video = video_path
|
| 871 |
+
output_file = gr.update(value=video_path, visible=True)
|
| 872 |
status_msg = gr.update(value="✅ Video generado exitosamente.", interactive=False)
|
| 873 |
else:
|
| 874 |
logger.error(f"crear_video no retornó un path válido o el archivo no existe: {video_path}")
|
|
|
|
| 884 |
logger.info("Fin del handler run_app.")
|
| 885 |
return output_video, output_file, status_msg
|
| 886 |
|
|
|
|
| 887 |
with gr.Blocks(title="Generador de Videos con IA", theme=gr.themes.Soft(), css="""
|
| 888 |
.gradio-container {max-width: 800px; margin: auto;}
|
| 889 |
h1 {text-align: center;}
|
|
|
|
| 961 |
run_app,
|
| 962 |
inputs=[prompt_type, prompt_ia, prompt_manual, musica_input],
|
| 963 |
outputs=[video_output, file_output, status_output]
|
|
|
|
|
|
|
|
|
|
|
|
|
| 964 |
)
|
| 965 |
|
| 966 |
gr.Markdown("### Instrucciones:")
|