Spaces:
Building
Building
Update app.py
Browse files
app.py
CHANGED
@@ -1,6 +1,12 @@
|
|
1 |
import gradio as gr
|
2 |
-
from tts_module import get_voices, text_to_speech
|
3 |
from pexels_api import search_pexels
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
5 |
# Forzar instalación de moviepy si no está disponible
|
6 |
def install(package):
|
@@ -21,13 +27,6 @@ except ImportError:
|
|
21 |
except ImportError:
|
22 |
raise ImportError("Error crítico: No se pudo instalar moviepy.editor. Verifica las dependencias.")
|
23 |
|
24 |
-
import asyncio
|
25 |
-
import os
|
26 |
-
import requests
|
27 |
-
import tempfile
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
# Ajustar música de fondo
|
32 |
def adjust_background_music(video_duration, music_file):
|
33 |
music = AudioFileClip(music_file)
|
@@ -62,12 +61,12 @@ def process_input(text, txt_file, mp3_file, prompt, selected_voice):
|
|
62 |
else:
|
63 |
return "No input provided", None
|
64 |
|
65 |
-
voices = asyncio.run(get_voices())
|
66 |
if selected_voice not in voices:
|
67 |
return f"La voz '{selected_voice}' no es válida. Por favor, seleccione una de las siguientes voces: {', '.join(voices.keys())}", None
|
68 |
|
69 |
try:
|
70 |
-
audio_file = asyncio.run(text_to_speech(final_text, selected_voice))
|
71 |
except Exception as e:
|
72 |
return f"Error con la voz seleccionada: {e}", None
|
73 |
|
@@ -95,7 +94,6 @@ def process_input(text, txt_file, mp3_file, prompt, selected_voice):
|
|
95 |
except Exception as e:
|
96 |
return f"Error durante el procesamiento: {e}", None
|
97 |
|
98 |
-
|
99 |
# Interfaz Gradio
|
100 |
with gr.Blocks() as demo:
|
101 |
gr.Markdown("# Text-to-Video Generator")
|
@@ -105,7 +103,7 @@ with gr.Blocks() as demo:
|
|
105 |
txt_file_input = gr.File(label="Or upload a .txt file", file_types=[".txt"])
|
106 |
mp3_file_input = gr.File(label="Upload background music (.mp3)", file_types=[".mp3"])
|
107 |
prompt_input = gr.Textbox(label="Or enter a prompt to generate text")
|
108 |
-
voices = asyncio.run(get_voices())
|
109 |
voice_dropdown = gr.Dropdown(choices=list(voices.keys()), label="Select Voice")
|
110 |
|
111 |
with gr.Column():
|
|
|
1 |
import gradio as gr
|
2 |
+
from tts_module import get_voices, text_to_speech # Importamos desde el nuevo tts_module.py
|
3 |
from pexels_api import search_pexels
|
4 |
+
from moviepy.editor import AudioFileClip, VideoFileClip, CompositeAudioClip, concatenate_audioclips
|
5 |
+
|
6 |
+
import asyncio
|
7 |
+
import os
|
8 |
+
import requests
|
9 |
+
import tempfile
|
10 |
|
11 |
# Forzar instalación de moviepy si no está disponible
|
12 |
def install(package):
|
|
|
27 |
except ImportError:
|
28 |
raise ImportError("Error crítico: No se pudo instalar moviepy.editor. Verifica las dependencias.")
|
29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
# Ajustar música de fondo
|
31 |
def adjust_background_music(video_duration, music_file):
|
32 |
music = AudioFileClip(music_file)
|
|
|
61 |
else:
|
62 |
return "No input provided", None
|
63 |
|
64 |
+
voices = asyncio.run(get_voices()) # Obtener voces disponibles
|
65 |
if selected_voice not in voices:
|
66 |
return f"La voz '{selected_voice}' no es válida. Por favor, seleccione una de las siguientes voces: {', '.join(voices.keys())}", None
|
67 |
|
68 |
try:
|
69 |
+
audio_file = asyncio.run(text_to_speech(final_text, selected_voice)) # Generar audio con edge_tts
|
70 |
except Exception as e:
|
71 |
return f"Error con la voz seleccionada: {e}", None
|
72 |
|
|
|
94 |
except Exception as e:
|
95 |
return f"Error durante el procesamiento: {e}", None
|
96 |
|
|
|
97 |
# Interfaz Gradio
|
98 |
with gr.Blocks() as demo:
|
99 |
gr.Markdown("# Text-to-Video Generator")
|
|
|
103 |
txt_file_input = gr.File(label="Or upload a .txt file", file_types=[".txt"])
|
104 |
mp3_file_input = gr.File(label="Upload background music (.mp3)", file_types=[".mp3"])
|
105 |
prompt_input = gr.Textbox(label="Or enter a prompt to generate text")
|
106 |
+
voices = asyncio.run(get_voices()) # Obtener voces disponibles al iniciar
|
107 |
voice_dropdown = gr.Dropdown(choices=list(voices.keys()), label="Select Voice")
|
108 |
|
109 |
with gr.Column():
|