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, skip_llm): return asyncio.run(synthesize(article_url, text_input, language, skip_llm)) async def synthesize(article_url, text_input, language="en", skip_llm=False): 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 voices = { "en": ("en-US-AvaMultilingualNeural", "en-US-AndrewMultilingualNeural"), "es": ("es-ES-AlvaroNeural", "es-ES-ElviraNeural") } voice1, voice2 = voices.get(language, voices["en"]) # Modo sin LLM (texto exacto) if skip_llm and text_input: output_file, conversation = await converter.raw_text_to_audio(text_input, voice1, voice2) return conversation, output_file # Procesamiento normal (con LLM) 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") with gr.Group(): text_url = gr.Textbox(label="URL (opcional)", placeholder="https://...") text_input = gr.Textbox(label="Texto manual", lines=5, placeholder="Pega tu texto aquĆ­...") language = gr.Dropdown(["en", "es"], label="Idioma", value="en") skip_llm = gr.Checkbox(label="šŸ”“ Modo libre (sin filtros LLM)", value=False) btn = gr.Button("Generar Podcast", variant="primary") with gr.Row(): conv_display = gr.Textbox(label="Conversación", interactive=False, lines=10) aud = gr.Audio(label="Audio Generado", interactive=False) btn.click( synthesize_sync, inputs=[text_url, text_input, language, skip_llm], outputs=[conv_display, aud] ) demo.launch()