Podcastking2 / apporiginal.py
gnosticdev's picture
Rename app.py to apporiginal.py
c4c8284 verified
Raw
History Blame Contribute Delete
2.48 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):
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='gstaff/sketch') as demo:
gr.Markdown("# Turn Any Article into a Podcast")
gr.Markdown("## Easily convert articles from URLs into listenable audio podcasts.")
gr.Markdown("### Instructions")
gr.Markdown("""
- **Step 1:** Paste the URL of the article you want to convert into the textbox.
- **Step 2:** Click on "Podcastify" to generate the podcast.
- **Step 3:** Listen to the podcast or view the conversation.
""")
gr.Markdown("""
- View the code at [GitHub - NarrateIt](https://github.com/EswarDivi/NarrateIt).
""")
with gr.Group():
text = gr.Textbox(label="Article Link", 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/gradio-mcp"],
inputs=text,
fn=synthesize_sync,
outputs=[conv_display, aud]
)
btn.click(synthesize_sync, inputs=[text], outputs=[conv_display, aud])
gr.Markdown("""
Note:
The initial version of Podcastify, which was purely local and used an open-source and on-device models, has been replaced by the current one. You can find it in the local branch.
Special thanks to:
- [gstaff/sketch](https://huggingface.co/spaces/gstaff/sketch) for the Sketch Theme.
- [Jina AI](https://jina.ai/reader/) for the web page parsing.
""")
demo.queue(api_open=True, default_concurrency_limit=15).launch(show_api=True)