Skip to content

Commit

Permalink
Podcast Generator
Browse files Browse the repository at this point in the history
## Description

Podcast Generator: Generate a 2-4 min podcast from any topic using models and agents

Please check the options that are relevant:

- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] Model update
- [ ] Infrastructure change

## Checklist

- [X] My code follows Phidata's style guidelines and best practices
- [X] I have performed a self-review of my code
- [X] I have added docstrings and comments for complex logic
- [X] My changes generate no new warnings or errors
- [ ] I have added cookbook examples for my new addition (if needed)
- [X] I have updated requirements.txt/pyproject.toml (if needed)
- [X] I have verified my changes in a clean environment
  • Loading branch information
Itz-Antaripa committed Feb 12, 2025
1 parent 551aadb commit 1b35aed
Show file tree
Hide file tree
Showing 5 changed files with 232 additions and 0 deletions.
Empty file.
117 changes: 117 additions & 0 deletions cookbook/examples/apps/podcast_generator/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import streamlit as st
from podcast import generate_podcast # type: ignore

# Streamlit App Configuration
st.set_page_config(
page_title="Podify AI 🎙️",
page_icon="🎧",
layout="wide",
)

# Sidebar Section
with st.sidebar:
st.title("🎧 Podify AI")
st.markdown("AI voices to generate an **engaging podcast**!")

# Voice Selection
voice_options = ["alloy", "echo", "fable", "onyx", "nova", "shimmer"]
selected_voice = st.selectbox("🎤 Choose a Voice:", voice_options, index=0)

st.markdown("---")
st.subheader("🔥 Suggested Topics:")
trending_topics = [
"🎭 Impact of AI on Creativity and Art",
"💡 Elon Musk vs Sam Altman",
"🏥 Using AI in healthcare",
"🚀 The Future of Space Exploration",
]

# Create row-wise aligned buttons
num_cols = 1 # Change this to 3 for three buttons in a row
cols = st.columns(num_cols) # Define columns

for i, topic in enumerate(trending_topics):
with cols[i % num_cols]: # Distribute buttons evenly across columns
if st.button(topic):
st.session_state["topic"] = topic
st.session_state["generate"] = True

st.markdown("---")
st.subheader("ℹ️ About")
st.markdown(
"""
- Enter a **topic** <br>
- **Select a voice** <br>
- **Click Generate Podcast** <br>
- **Listen & Download** the AI-generated audio
""",
unsafe_allow_html=True,
)

# Main Content
st.title("Podify AI🎙️")
st.markdown(":orange_heart: **powered by Agno**")

st.markdown(
"Create high-quality podcasts on **any topic**! Simply enter a topic and let Podify AI generate a professional podcast with **realistic AI voices**. 🚀"
)

# Get pre-selected topic from sidebar
pre_selected_topic = st.session_state.get("topic", "")

# Input for Podcast Topic
topic = st.text_input(
"📖 **Enter Your Podcast Topic Below:**",
placeholder="E.g., How AI is Changing the Job Market",
value=pre_selected_topic,
)

# Check if auto-generation is triggered
generate_now = st.session_state.get("generate", False)


# Generate Podcast Function
def generate_and_display_podcast(topic):
with st.spinner("⏳ Generating Podcast... This may take up to 2 minute..."):
audio_path = generate_podcast(topic, selected_voice)

if audio_path:
st.success("✅ Podcast generated successfully!")

st.subheader("🎧 Your AI Podcast")
st.audio(audio_path, format="audio/wav")

with open(audio_path, "rb") as audio_file:
st.download_button("⬇️ Download Podcast", audio_file, file_name="podcast.wav", mime="audio/wav")

else:
st.error("❌ Failed to generate podcast. Please try again.")


# Auto-generate podcast if a trending topic is selected
if generate_now and topic:
generate_and_display_podcast(topic)
st.session_state["generate"] = False # Reset the flag after generation

# Manual Generate Podcast Button
if st.button("🎬 Generate Podcast"):
if topic:
generate_and_display_podcast(topic)
else:
st.warning("⚠️ Please enter a topic before generating.")

# Footer Section
st.markdown("---")
st.markdown(
"""
🌟 **Features:**
- 🎙️ AI-generated podcast scripts based on **real-time research**.
- 🗣️ Multiple **realistic voices** for narration.
- 📥 **Download & share** your podcasts instantly.
📢 **Disclaimer:** AI-generated content is based on available online data and may not always be accurate.
""",
unsafe_allow_html=True,
)
st.markdown("---")
st.markdown(":orange_heart: **Thank you for using Podify AI!**")
70 changes: 70 additions & 0 deletions cookbook/examples/apps/podcast_generator/podcast.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import os
from dotenv import load_dotenv

from agno.tools.duckduckgo import DuckDuckGoTools
from agno.agent import Agent
from agno.models.openai import OpenAIChat
from agno.utils.audio import write_audio_to_file

# Load environment variables
load_dotenv()

# OpenAI API Key
OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")

os.makedirs("tmp", exist_ok=True)


def generate_podcast(topic, voice="alloy"):
"""
Generates a podcast script using a agnodata Agent and converts it to speech using OpenAI TTS.
Args:
topic (str): The topic of the podcast.
voice (str): Voice model for OpenAI TTS. Options: ["alloy", "echo", "fable", "onyx", "nova", "shimmer"]
"""

# Create a agnodata agent to generate the podcast script
audio_agent = Agent(
system_message="You are a podcast scriptwriter specializing in concise and engaging narratives. Your task is to research a given topic using Exa and DuckDuckGo, gather relevant insights, and compose a short, compelling podcast script.",
instructions="""### **Instructions:**
1. **Research Phase:**
- Use Exa and DuckDuckGo to gather the most recent and relevant information on the given topic.
- Prioritize trustworthy sources such as news sites, academic articles, or well-established blogs.
- Identify key points, statistics, expert opinions, and interesting facts.
2. **Scripting Phase:**
- Write a concise podcast script in a conversational tone.
- Begin with a strong hook to capture the listener's attention.
- Present the key insights in an engaging, easy-to-follow manner.
- Include a smooth transition between ideas to maintain narrative flow.
- End with a closing remark that summarizes the main takeaways and encourages further curiosity.
### **Formatting Guidelines:**
- Use simple, engaging language.
- Keep the script under 300 words (around 2 minutes of audio).
- Write in a natural, spoken format, avoiding overly formal or technical jargon.
- Start with a short intro of the topic, then cover the main content, and conclude.
### **Example Output:**
#### **Today we will be covering the topic The Future of AI in Healthcare**
"Imagine walking into a hospital where AI instantly diagnoses your illness, prescribes treatment, and even assists in surgery. Sounds like science fiction? Well, it’s closer to reality than you think! Welcome to today’s episode, where we explore how AI is revolutionizing healthcare."
"AI is making waves in medical research, diagnostics, and patient care. For instance, Google’s DeepMind developed an AI that can detect over 50 eye diseases with a single scan—just as accurately as top doctors! Meanwhile, robotic surgeries assisted by AI are reducing complications and recovery time for patients. But it's not just about tech—AI is also addressing healthcare accessibility. In rural areas, AI-powered chatbots provide medical advice where doctors are scarce."
"While AI in healthcare is promising, it also raises ethical concerns. Who takes responsibility for a wrong diagnosis? How do we ensure data privacy? These are crucial questions for the future. One thing’s for sure—AI is here to stay, and it’s reshaping medicine as we know it. Thanks for tuning in, and see you next time!"
""",
model=OpenAIChat(
id="gpt-4o-audio-preview", modalities=["text", "audio"], audio={"voice": voice, "format": "wav"}
),
tools=[DuckDuckGoTools()],
)

# Generate the podcast script
audio_agent.run(f"Write the content of podcast for the topic: {topic}")
audio_file_path = "tmp/generated_podcast.wav"
if audio_agent.run_response.response_audio is not None and "data" in audio_agent.run_response.response_audio:
write_audio_to_file(audio=audio_agent.run_response.response_audio["data"], filename=audio_file_path)
return audio_file_path

return None
41 changes: 41 additions & 0 deletions cookbook/examples/apps/podcast_generator/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Podify AI 🎙

Podify AI is an AI-powered podcast agent that generates high-quality podcasts on any topic.
It uses real-time search using DuckDuckGo and AI-generated narration to create professional podcast scripts with realistic voices.

🎧 Enter a topic → model writes a script → narrates it → you listen & download!

## Features

- **AI-Generated Podcasts**: Automatically researches & generates podcast scripts.
- **Realistic AI Voices**: Choose from multiple AI voices for narration.
- **Download & Share**: Save and share your generated podcasts.
- **Real-Time Research**: Uses DuckDuckGo for up-to-date insights.
---

## Setup Instructions

### 1. Create a virtual environment

```shell
python3 -m venv ~/.venvs/podifyenv
source ~/.venvs/podifyenv/bin/activate
```

### 2. Install requirements

```shell
pip install -r cookbook/examples/apps/podcast_generator/requirements.txt
```

### 3. Export `OPENAI_API_KEY`

```shell
export OPENAI_API_KEY=***
```

### 4. Run Streamlit App

```shell
streamlit run cookbook/examples/apps/podcast_generator/app.py
```
4 changes: 4 additions & 0 deletions cookbook/examples/apps/podcast_generator/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
agno==0.1.2
openai
streamlit
duckduckgo-search

0 comments on commit 1b35aed

Please sign in to comment.