Manasa1's picture
Create app.py
622bb3c verified
import streamlit as st
from phi.agent import Agent
from phi.tools.youtube_tools import YouTubeTools
from phi.model.groq import Groq
from dotenv import load_dotenv
import os
from phi.tools.duckduckgo import DuckDuckGo
# Load environment variables
load_dotenv()
# Access the Groq API key
groq_api_key = os.getenv("GROQ_API_KEY")
# Initialize the agent (error handling remains)
try:
agent = Agent(
model=Groq(id="llama-3.3-70b-versatile", api_key=groq_api_key),
tools=[YouTubeTools(),DuckDuckGo()],
show_tool_calls=False,
get_video_captions=True,
description="You are a YouTube agent. Obtain the captions of a YouTube video, analyze its content and context, provide summaries, conduct web research on similar topics, and answer user questions.",
)
except Exception as e:
st.error(f"Error initializing the agent: {e}")
st.stop()
st.title("YouTube Video Analyzer")
video_url = st.text_input("Enter YouTube Video URL:", "")
user_query = st.text_area("Enter your question about the video (optional):", "")
if st.button("Analyze"):
if video_url:
with st.spinner("Analyzing..."):
try:
if user_query:
prompt = f"""Analyze the video for content and context. Provide a detailed summary. Search the internet for similar topics discussed in the uploaded video.
Respond to the following query using video insights and supplementary web research:
{user_query}
Provide a detailed, user-friendly, and actionable response.
Video URL: {video_url}""" # Added Video URL for context
else:
prompt = f"""Analyze the uploaded video for content and context. Provide a detailed summary. Search the internet for similar topics discussed in the uploaded video.
Video URL: {video_url}""" # Added Video URL for context
output = agent.run(prompt)
st.markdown(output.content)
except Exception as e:
st.error(f"Error generating output: {e}")
st.stop()
else:
st.warning("Please enter a YouTube video URL.")