Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from tts_module import text_to_speech # M贸dulo para TTS
|
3 |
+
from video_module import generate_video # M贸dulo para generar video
|
4 |
+
from music_module import adjust_background_music # M贸dulo para manejar m煤sica
|
5 |
+
|
6 |
+
def process_input(text, txt_file, mp3_file, prompt):
|
7 |
+
# Paso 1: Obtener el texto final
|
8 |
+
if text.strip(): # Prioridad al texto escrito directamente
|
9 |
+
final_text = text
|
10 |
+
elif txt_file is not None: # Luego al archivo .txt
|
11 |
+
final_text = txt_file.decode("utf-8")
|
12 |
+
elif prompt.strip(): # Finalmente, usar el prompt para generar texto
|
13 |
+
# Aqu铆 ir铆a la llamada al modelo gpt2 para generar el guion
|
14 |
+
final_text = "Generated text from prompt" # Placeholder
|
15 |
+
else:
|
16 |
+
return "No input provided", None
|
17 |
+
|
18 |
+
# Paso 2: Convertir texto a voz con edge_tts
|
19 |
+
audio_file = text_to_speech(final_text)
|
20 |
+
|
21 |
+
# Paso 3: Generar el video
|
22 |
+
video_file = generate_video(final_text)
|
23 |
+
|
24 |
+
# Paso 4: Ajustar la m煤sica de fondo
|
25 |
+
if mp3_file is not None:
|
26 |
+
music_clip = adjust_background_music(video_file.duration, mp3_file.name)
|
27 |
+
else:
|
28 |
+
music_clip = None
|
29 |
+
|
30 |
+
# Paso 5: Combinar todos los elementos
|
31 |
+
final_video = combine_audio_video(audio_file, video_file, music_clip)
|
32 |
+
|
33 |
+
return final_video
|
34 |
+
|
35 |
+
# Interfaz Gradio
|
36 |
+
with gr.Blocks() as demo:
|
37 |
+
gr.Markdown("# Text-to-Video Generator")
|
38 |
+
with gr.Row():
|
39 |
+
with gr.Column():
|
40 |
+
text_input = gr.Textbox(label="Write your text here", lines=5)
|
41 |
+
txt_file_input = gr.File(label="Or upload a .txt file", file_types=[".txt"])
|
42 |
+
mp3_file_input = gr.File(label="Upload background music (.mp3)", file_types=[".mp3"])
|
43 |
+
prompt_input = gr.Textbox(label="Or enter a prompt to generate text")
|
44 |
+
with gr.Column():
|
45 |
+
output_video = gr.Video(label="Generated Video")
|
46 |
+
|
47 |
+
btn = gr.Button("Generate Video")
|
48 |
+
btn.click(process_input, inputs=[text_input, txt_file_input, mp3_file_input, prompt_input], outputs=output_video)
|
49 |
+
|
50 |
+
demo.launch()
|