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