Podcastking2 / app.py
gnosticdev's picture
Update app.py
e6fe746 verified
raw
history blame
2.01 kB
import gradio as gr
import os
import asyncio
from conver import ConversationConfig, URLToAudioConverter
from dotenv import load_dotenv
load_dotenv()
def synthesize_sync(article_url, text_input, language="en"):
return asyncio.run(synthesize(article_url, text_input, language))
async def synthesize(article_url, text_input, language):
if not article_url and not text_input:
return "Error: Ingresa una URL o texto", None
try:
config = ConversationConfig()
converter = URLToAudioConverter(config, llm_api_key=os.environ.get("TOGETHER_API_KEY"))
# Voces humanizadas (inglés) o español
voices = {
"en": ("en-US-AvaMultilingualNeural", "en-US-AndrewMultilingualNeural"),
"es": ("es-ES-AlvaroNeural", "es-ES-ElviraNeural")
}
voice1, voice2 = voices.get(language, voices["en"])
if text_input:
output_file, conversation = await converter.text_to_audio(text_input, voice1, voice2)
else:
output_file, conversation = await converter.url_to_audio(article_url, voice1, voice2)
return conversation, output_file
except Exception as e:
return f"Error: {str(e)}", None
with gr.Blocks(theme='gstaff/sketch') as demo:
gr.Markdown("# 🎙 Podcast Converter (Human Voices)")
with gr.Group():
text_url = gr.Textbox(label="Article URL (optional)", placeholder="https://...")
text_input = gr.Textbox(label="Or paste text directly", lines=5, placeholder="Type here...")
language = gr.Dropdown(["en", "es"], label="Language", value="en")
btn = gr.Button("Generate Podcast", variant="primary")
with gr.Row():
conv_display = gr.Textbox(label="Conversation", interactive=False, lines=10)
aud = gr.Audio(label="Podcast", interactive=False)
btn.click(
synthesize_sync,
inputs=[text_url, text_input, language],
outputs=[conv_display, aud]
)
demo.launch()