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): return asyncio.run(synthesize(article_url)) async def synthesize(article_url): if not article_url: return "Please provide a valid URL.", None try: config = ConversationConfig() converter = URLToAudioConverter(config, llm_api_key=os.environ.get("TOGETHER_API_KEY")) output_file, conversation = await converter.url_to_audio( article_url, "en-US-AvaMultilingualNeural", "en-US-AndrewMultilingualNeural" ) return conversation, output_file except Exception as e: return f"Error: {str(e)}", None with gr.Blocks(theme='soft') as demo: with gr.Group(): text = gr.Textbox(label="Link: Article, Blog, News...", placeholder="Enter the article URL here...") btn = gr.Button("Podcastify", variant="primary") with gr.Row(): conv_display = gr.Textbox(label="Conversation", interactive=False, lines=10) aud = gr.Audio(label="Generated Podcast", interactive=False) gr.Examples( examples=["https://huggingface.co/blog/openfree/cycle-navigator"], inputs=text, fn=synthesize_sync, outputs=[conv_display, aud] ) btn.click(synthesize_sync, inputs=[text], outputs=[conv_display, aud]) demo.queue(api_open=True, default_concurrency_limit=15).launch(show_api=True)