Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from phi.agent import Agent
|
| 3 |
+
from phi.tools.youtube_tools import YouTubeTools
|
| 4 |
+
from phi.model.groq import Groq
|
| 5 |
+
from dotenv import load_dotenv
|
| 6 |
+
import os
|
| 7 |
+
from phi.tools.duckduckgo import DuckDuckGo
|
| 8 |
+
|
| 9 |
+
# Load environment variables
|
| 10 |
+
load_dotenv()
|
| 11 |
+
|
| 12 |
+
# Access the Groq API key
|
| 13 |
+
groq_api_key = os.getenv("GROQ_API_KEY")
|
| 14 |
+
|
| 15 |
+
# Initialize the agent (error handling remains)
|
| 16 |
+
try:
|
| 17 |
+
agent = Agent(
|
| 18 |
+
model=Groq(id="llama-3.3-70b-versatile", api_key=groq_api_key),
|
| 19 |
+
tools=[YouTubeTools(),DuckDuckGo()],
|
| 20 |
+
show_tool_calls=False,
|
| 21 |
+
get_video_captions=True,
|
| 22 |
+
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.",
|
| 23 |
+
)
|
| 24 |
+
except Exception as e:
|
| 25 |
+
st.error(f"Error initializing the agent: {e}")
|
| 26 |
+
st.stop()
|
| 27 |
+
|
| 28 |
+
st.title("YouTube Video Analyzer")
|
| 29 |
+
|
| 30 |
+
video_url = st.text_input("Enter YouTube Video URL:", "")
|
| 31 |
+
user_query = st.text_area("Enter your question about the video (optional):", "")
|
| 32 |
+
|
| 33 |
+
if st.button("Analyze"):
|
| 34 |
+
if video_url:
|
| 35 |
+
with st.spinner("Analyzing..."):
|
| 36 |
+
try:
|
| 37 |
+
if user_query:
|
| 38 |
+
prompt = f"""Analyze the video for content and context. Provide a detailed summary. Search the internet for similar topics discussed in the uploaded video.
|
| 39 |
+
|
| 40 |
+
Respond to the following query using video insights and supplementary web research:
|
| 41 |
+
|
| 42 |
+
{user_query}
|
| 43 |
+
|
| 44 |
+
Provide a detailed, user-friendly, and actionable response.
|
| 45 |
+
|
| 46 |
+
Video URL: {video_url}""" # Added Video URL for context
|
| 47 |
+
else:
|
| 48 |
+
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.
|
| 49 |
+
|
| 50 |
+
Video URL: {video_url}""" # Added Video URL for context
|
| 51 |
+
|
| 52 |
+
output = agent.run(prompt)
|
| 53 |
+
|
| 54 |
+
st.markdown(output.content)
|
| 55 |
+
|
| 56 |
+
except Exception as e:
|
| 57 |
+
st.error(f"Error generating output: {e}")
|
| 58 |
+
st.stop()
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
else:
|
| 62 |
+
st.warning("Please enter a YouTube video URL.")
|