Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -3,13 +3,36 @@ import os
|
|
3 |
import asyncio
|
4 |
from conver import ConversationConfig, URLToAudioConverter
|
5 |
from dotenv import load_dotenv
|
|
|
6 |
|
7 |
load_dotenv()
|
8 |
|
9 |
-
|
10 |
-
|
|
|
11 |
|
12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
if not article_url and not text_input:
|
14 |
return "Error: Ingresa una URL o texto", None
|
15 |
|
@@ -17,24 +40,22 @@ async def synthesize(article_url, text_input, language="en", skip_llm=False):
|
|
17 |
config = ConversationConfig()
|
18 |
converter = URLToAudioConverter(config, llm_api_key=os.environ.get("TOGETHER_API_KEY"))
|
19 |
|
20 |
-
# Voces humanizadas
|
21 |
voices = {
|
22 |
"en": ("en-US-AvaMultilingualNeural", "en-US-AndrewMultilingualNeural"),
|
23 |
"es": ("es-ES-AlvaroNeural", "es-ES-ElviraNeural")
|
24 |
}
|
25 |
voice1, voice2 = voices.get(language, voices["en"])
|
26 |
|
27 |
-
# Modo sin LLM (texto exacto)
|
28 |
if skip_llm and text_input:
|
29 |
output_file, conversation = await converter.raw_text_to_audio(text_input, voice1, voice2)
|
30 |
-
|
31 |
-
|
32 |
-
# Procesamiento normal (con LLM)
|
33 |
-
if text_input:
|
34 |
output_file, conversation = await converter.text_to_audio(text_input, voice1, voice2)
|
35 |
else:
|
36 |
output_file, conversation = await converter.url_to_audio(article_url, voice1, voice2)
|
37 |
-
|
|
|
|
|
|
|
38 |
return conversation, output_file
|
39 |
except Exception as e:
|
40 |
return f"Error: {str(e)}", None
|
@@ -46,6 +67,7 @@ with gr.Blocks(theme='gstaff/sketch') as demo:
|
|
46 |
text_input = gr.Textbox(label="Texto manual", lines=5, placeholder="Pega tu texto aquí...")
|
47 |
language = gr.Dropdown(["en", "es"], label="Idioma", value="en")
|
48 |
skip_llm = gr.Checkbox(label="🔴 Modo libre (sin filtros LLM)", value=False)
|
|
|
49 |
btn = gr.Button("Generar Podcast", variant="primary")
|
50 |
|
51 |
with gr.Row():
|
@@ -54,8 +76,8 @@ with gr.Blocks(theme='gstaff/sketch') as demo:
|
|
54 |
|
55 |
btn.click(
|
56 |
synthesize_sync,
|
57 |
-
inputs=[text_url, text_input, language, skip_llm],
|
58 |
outputs=[conv_display, aud]
|
59 |
)
|
60 |
|
61 |
-
demo.launch()
|
|
|
3 |
import asyncio
|
4 |
from conver import ConversationConfig, URLToAudioConverter
|
5 |
from dotenv import load_dotenv
|
6 |
+
from pydub import AudioSegment
|
7 |
|
8 |
load_dotenv()
|
9 |
|
10 |
+
MUSICA_FONDO = "musica.mp3"
|
11 |
+
TAG1 = "tag.mp3"
|
12 |
+
TAG2 = "tag2.mp3"
|
13 |
|
14 |
+
def mezclar_musica_y_tags(audio_path: str) -> str:
|
15 |
+
podcast_audio = AudioSegment.from_file(audio_path)
|
16 |
+
musica_fondo = AudioSegment.from_file(MUSICA_FONDO).apply_gain(-15)
|
17 |
+
tag1_audio = AudioSegment.from_file(TAG1).apply_gain(-5)
|
18 |
+
tag2_audio = AudioSegment.from_file(TAG2).apply_gain(-5)
|
19 |
+
|
20 |
+
duracion_podcast = len(podcast_audio)
|
21 |
+
repeticiones = (duracion_podcast // len(musica_fondo)) + 1
|
22 |
+
musica_fondo_loop = musica_fondo * repeticiones
|
23 |
+
musica_fondo_loop = musica_fondo_loop[:duracion_podcast]
|
24 |
+
|
25 |
+
mezcla = musica_fondo_loop.overlay(podcast_audio)
|
26 |
+
mezcla = tag1_audio + mezcla + tag2_audio
|
27 |
+
|
28 |
+
output_path = audio_path.replace(".mp3", "_con_musica.mp3")
|
29 |
+
mezcla.export(output_path, format="mp3")
|
30 |
+
return output_path
|
31 |
+
|
32 |
+
def synthesize_sync(article_url, text_input, language, skip_llm, agregar_musica):
|
33 |
+
return asyncio.run(synthesize(article_url, text_input, language, skip_llm, agregar_musica))
|
34 |
+
|
35 |
+
async def synthesize(article_url, text_input, language="en", skip_llm=False, agregar_musica=False):
|
36 |
if not article_url and not text_input:
|
37 |
return "Error: Ingresa una URL o texto", None
|
38 |
|
|
|
40 |
config = ConversationConfig()
|
41 |
converter = URLToAudioConverter(config, llm_api_key=os.environ.get("TOGETHER_API_KEY"))
|
42 |
|
|
|
43 |
voices = {
|
44 |
"en": ("en-US-AvaMultilingualNeural", "en-US-AndrewMultilingualNeural"),
|
45 |
"es": ("es-ES-AlvaroNeural", "es-ES-ElviraNeural")
|
46 |
}
|
47 |
voice1, voice2 = voices.get(language, voices["en"])
|
48 |
|
|
|
49 |
if skip_llm and text_input:
|
50 |
output_file, conversation = await converter.raw_text_to_audio(text_input, voice1, voice2)
|
51 |
+
elif text_input:
|
|
|
|
|
|
|
52 |
output_file, conversation = await converter.text_to_audio(text_input, voice1, voice2)
|
53 |
else:
|
54 |
output_file, conversation = await converter.url_to_audio(article_url, voice1, voice2)
|
55 |
+
|
56 |
+
if agregar_musica:
|
57 |
+
output_file = mezclar_musica_y_tags(output_file)
|
58 |
+
|
59 |
return conversation, output_file
|
60 |
except Exception as e:
|
61 |
return f"Error: {str(e)}", None
|
|
|
67 |
text_input = gr.Textbox(label="Texto manual", lines=5, placeholder="Pega tu texto aquí...")
|
68 |
language = gr.Dropdown(["en", "es"], label="Idioma", value="en")
|
69 |
skip_llm = gr.Checkbox(label="🔴 Modo libre (sin filtros LLM)", value=False)
|
70 |
+
agregar_musica = gr.Checkbox(label="🎵 Agregar música de fondo y cortinillas", value=False)
|
71 |
btn = gr.Button("Generar Podcast", variant="primary")
|
72 |
|
73 |
with gr.Row():
|
|
|
76 |
|
77 |
btn.click(
|
78 |
synthesize_sync,
|
79 |
+
inputs=[text_url, text_input, language, skip_llm, agregar_musica],
|
80 |
outputs=[conv_display, aud]
|
81 |
)
|
82 |
|
83 |
+
demo.launch()
|