File size: 2,306 Bytes
622bb3c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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.")