Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Podcast Generator #2094

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
78 changes: 78 additions & 0 deletions cookbook/examples/apps/podcast_generator/agents.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import os

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

# 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:
audio_content = audio_agent.run_response.response_audio.content

if audio_content:
write_audio_to_file(
audio=audio_content,
filename=audio_file_path,
)
return audio_file_path
return None
122 changes: 122 additions & 0 deletions cookbook/examples/apps/podcast_generator/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import streamlit as st
from agents import generate_podcast

# 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!**")
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash

############################################################################
# Generate requirements.txt from requirements.in
############################################################################

echo "Generating requirements.txt"

CURR_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"

UV_CUSTOM_COMPILE_COMMAND="./generate_requirements.sh" \
uv pip compile ${CURR_DIR}/requirements.in --no-cache --upgrade -o ${CURR_DIR}/requirements.txt
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.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
agno
openai
streamlit
duckduckgo-search
Loading