Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,29 +6,8 @@ from dotenv import load_dotenv
|
|
| 6 |
|
| 7 |
load_dotenv()
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
return "Error: Ingresa una URL o texto", None
|
| 12 |
-
|
| 13 |
-
try:
|
| 14 |
-
config = ConversationConfig()
|
| 15 |
-
converter = URLToAudioConverter(config, llm_api_key=os.environ.get("TOGETHER_API_KEY"))
|
| 16 |
-
|
| 17 |
-
# Voces humanizadas
|
| 18 |
-
voices = {
|
| 19 |
-
"en": ("en-US-AvaMultilingualNeural", "en-US-AndrewMultilingualNeural"),
|
| 20 |
-
"es": ("es-ES-AlvaroNeural", "es-ES-ElviraNeural")
|
| 21 |
-
}
|
| 22 |
-
voice1, voice2 = voices.get(language, voices["en"])
|
| 23 |
-
|
| 24 |
-
if text_input:
|
| 25 |
-
output_file, conversation = await converter.text_to_audio(text_input, voice1, voice2)
|
| 26 |
-
else:
|
| 27 |
-
output_file, conversation = await converter.url_to_audio(article_url, voice1, voice2)
|
| 28 |
-
|
| 29 |
-
return conversation, output_file
|
| 30 |
-
except Exception as e:
|
| 31 |
-
return f"Error: {str(e)}", None
|
| 32 |
|
| 33 |
async def synthesize(article_url, text_input, language="en", skip_llm=False):
|
| 34 |
if not article_url and not text_input:
|
|
@@ -38,6 +17,7 @@ async def synthesize(article_url, text_input, language="en", skip_llm=False):
|
|
| 38 |
config = ConversationConfig()
|
| 39 |
converter = URLToAudioConverter(config, llm_api_key=os.environ.get("TOGETHER_API_KEY"))
|
| 40 |
|
|
|
|
| 41 |
voices = {
|
| 42 |
"en": ("en-US-AvaMultilingualNeural", "en-US-AndrewMultilingualNeural"),
|
| 43 |
"es": ("es-ES-AlvaroNeural", "es-ES-ElviraNeural")
|
|
@@ -46,7 +26,8 @@ async def synthesize(article_url, text_input, language="en", skip_llm=False):
|
|
| 46 |
|
| 47 |
# Modo sin LLM (texto exacto)
|
| 48 |
if skip_llm and text_input:
|
| 49 |
-
|
|
|
|
| 50 |
|
| 51 |
# Procesamiento normal (con LLM)
|
| 52 |
if text_input:
|
|
@@ -58,12 +39,23 @@ async def synthesize(article_url, text_input, language="en", skip_llm=False):
|
|
| 58 |
except Exception as e:
|
| 59 |
return f"Error: {str(e)}", None
|
| 60 |
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
|
| 69 |
demo.launch()
|
|
|
|
| 6 |
|
| 7 |
load_dotenv()
|
| 8 |
|
| 9 |
+
def synthesize_sync(article_url, text_input, language, skip_llm):
|
| 10 |
+
return asyncio.run(synthesize(article_url, text_input, language, skip_llm))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
async def synthesize(article_url, text_input, language="en", skip_llm=False):
|
| 13 |
if not article_url and not text_input:
|
|
|
|
| 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")
|
|
|
|
| 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 |
+
return conversation, output_file
|
| 31 |
|
| 32 |
# Procesamiento normal (con LLM)
|
| 33 |
if text_input:
|
|
|
|
| 39 |
except Exception as e:
|
| 40 |
return f"Error: {str(e)}", None
|
| 41 |
|
| 42 |
+
with gr.Blocks(theme='gstaff/sketch') as demo:
|
| 43 |
+
gr.Markdown("# 🎙 Podcast Converter")
|
| 44 |
+
with gr.Group():
|
| 45 |
+
text_url = gr.Textbox(label="URL (opcional)", placeholder="https://...")
|
| 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():
|
| 52 |
+
conv_display = gr.Textbox(label="Conversación", interactive=False, lines=10)
|
| 53 |
+
aud = gr.Audio(label="Audio Generado", interactive=False)
|
| 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()
|