rathodj080898 commited on
Commit
0a094cc
·
verified ·
1 Parent(s): ef6dcd0

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +105 -0
  2. requirements.txt +5 -0
app.py ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from phi.agent import Agent
3
+ from phi.model.google import Gemini
4
+ from phi.tools.duckduckgo import DuckDuckGo
5
+ from google.generativeai import upload_file, get_file
6
+ import google.generativeai as genai
7
+ import time
8
+ from pathlib import Path
9
+ import tempfile
10
+ from dotenv import load_dotenv
11
+ load_dotenv()
12
+ import os
13
+
14
+ API_KEY = os.getenv("GOOGLE_API_KEY")
15
+ if API_KEY:
16
+ genai.configure(api_key = API_KEY)
17
+
18
+ # Page Configuration
19
+ st.set_page_config(
20
+ page_title="Multimodal AI Agent - Video Summarizer",
21
+ page_icon="(1f4f9_videocamera) ",
22
+ layout="wide"
23
+ )
24
+
25
+ st.title("Phidata Multimodal AI Summarizer Agent (1f4f9_videocamera) ")
26
+ st.header("Powered by Gemini 2.0 Flash Exp")
27
+
28
+ @st.cache_resource
29
+ def initialize_agent():
30
+ return Agent(
31
+ name = "Video AI Summarizer",
32
+ model = Gemini(id="gemini-2.0-exp"),
33
+ tools = [DuckDuckGo()],
34
+ markdown = True
35
+ )
36
+
37
+ # Initialize Agent
38
+ multimodal_agent = initialize_agent()
39
+
40
+ # File uploader
41
+ video_file = st.file_uploader(
42
+ "Upload a video file", type=['mp4', 'mov', 'avi'], help="Upload a video for AI Analysis"
43
+ )
44
+ if video_file:
45
+ with tempfile.NamedTemporaryFile(delete=False, suffix='.mp4') as temp_video:
46
+ temp_video.write(video_file.read())
47
+ video_path = temp_video.name
48
+
49
+ st.video(video_path, format="video/mp4", start_time=0)
50
+
51
+ user_query = st.text_area(
52
+ "What insights are you seeking from the video?",
53
+ placeholder="Ask anything about the video content. The AI Agent will analyze and gather additional information",
54
+ help="Provide specific question or insights you want from the video."
55
+ )
56
+
57
+ if st.button("Analyze video", key="analyze_video_button"):
58
+ if not user_query:
59
+ st.warning("Please enter a question or insight to analyze the video.")
60
+ else:
61
+ try:
62
+ with st.spinner("Processing video and gathering insights..."):
63
+ #Upload and process video file
64
+ processed_video = upload_file(video_path)
65
+ while processed_video.state.name == "PROCESSING":
66
+ time.sleep(1)
67
+ processed_video = get_file(processed_video.name)
68
+
69
+ #prompt generation for analysis
70
+ analyses_prompt = (f"""
71
+ Analyze the uploaded video for content and context.
72
+ Respond the following query using the video insights and supplimentary web research
73
+ {user_query}
74
+
75
+ Provide a detailed, user-friendly and actionable response.
76
+ """
77
+ )
78
+
79
+ #AI agent processing
80
+ response = multimodal_agent.run(analyses_prompt, video = [processed_video])
81
+
82
+ #Display the result
83
+ st.subheader("Analysis result")
84
+ st.markdown(response.content)
85
+
86
+ except Exception as error:
87
+ st.error(f"An error occured during analysis: {error}")
88
+ finally:
89
+ # Clean temporary file
90
+ Path(video_path).unlink(missing_ok=True)
91
+ else:
92
+ st.info("Upload a video file to begin analysis")
93
+
94
+ # Customize text are heihght
95
+
96
+ st.markdown(
97
+ """
98
+ <style>
99
+ .stTextArea textarea {
100
+ height: 100px;
101
+ }
102
+ </style>
103
+ """,
104
+ unsafe_allow_html=True
105
+ )
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ streamlit
2
+ phidata
3
+ google-generativeai
4
+ openai
5
+ duckduckgo-search