ivanfioravanti commited on
Commit
f0b2bc6
β€’
0 Parent(s):

Initial commit

Browse files
Files changed (4) hide show
  1. .gitattributes +35 -0
  2. README.md +14 -0
  3. app.py +81 -0
  4. requirements.txt +5 -0
.gitattributes ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz filter=lfs diff=lfs merge=lfs -text
33
+ *.zip filter=lfs diff=lfs merge=lfs -text
34
+ *.zst filter=lfs diff=lfs merge=lfs -text
35
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: Phidata Multimodal AI Agent
3
+ emoji: πŸš€
4
+ colorFrom: green
5
+ colorTo: gray
6
+ sdk: streamlit
7
+ sdk_version: 1.41.1
8
+ app_file: app.py
9
+ pinned: false
10
+ license: mit
11
+ short_description: Phidata Multimodal AI Agent
12
+ ---
13
+
14
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
app.py ADDED
@@ -0,0 +1,81 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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 time
7
+ from pathlib import Path
8
+ import tempfile
9
+
10
+ st.set_page_config(
11
+ page_title="Multimodal AI Agent",
12
+ page_icon="πŸŽ₯",
13
+ layout="wide"
14
+ )
15
+
16
+ st.title("Phidata Multimodal AI Agent πŸŽ₯πŸŽ€πŸ’¬")
17
+ st.header("Powered by Gemini 2.0 Flash Exp")
18
+
19
+ @st.cache_resource
20
+ def initialize_agent():
21
+ return Agent(
22
+ name="Multimodal Analyst",
23
+ model=Gemini(id="gemini-2.0-flash-exp"),
24
+ tools=[DuckDuckGo()],
25
+ markdown=True,
26
+ )
27
+
28
+ agent = initialize_agent()
29
+
30
+ uploaded_file = st.file_uploader("Upload a video file", type=['mp4', 'mov', 'avi'])
31
+
32
+ if uploaded_file:
33
+ with tempfile.NamedTemporaryFile(delete=False, suffix='.mp4') as tmp_file:
34
+ tmp_file.write(uploaded_file.read())
35
+ upload_path = tmp_file.name
36
+
37
+ st.video(upload_path)
38
+
39
+ user_prompt = st.text_area(
40
+ "What are you looking for in this video?",
41
+ placeholder="Ask anything about the video - AI Agent will analyze everything and search the web if needed",
42
+ help="You can ask questions about the video content and get information from the web"
43
+ )
44
+
45
+ if st.button("Analyze"):
46
+ if not user_prompt:
47
+ st.warning("Please enter your question.")
48
+ else:
49
+ try:
50
+ with st.spinner("Analyzing video and searching the web..."):
51
+ video_file = upload_file(upload_path)
52
+ while video_file.state.name == "PROCESSING":
53
+ time.sleep(1)
54
+ video_file = get_file(video_file.name)
55
+
56
+ prompt = f"""
57
+ First analyze the video and then answer this question using both
58
+ the video analysis and web research, question: {user_prompt}
59
+
60
+ Provide a comprehensive response focusing on practical, actionable information.
61
+ """
62
+
63
+ result = agent.run(prompt, videos=[video_file])
64
+
65
+ st.subheader("Result")
66
+ st.markdown(result.content)
67
+
68
+ except Exception as e:
69
+ st.error(f"An error occurred: {str(e)}")
70
+ finally:
71
+ Path(upload_path).unlink(missing_ok=True)
72
+ else:
73
+ st.info("Please upload a video to begin analysis.")
74
+
75
+ st.markdown("""
76
+ <style>
77
+ .stTextArea textarea {
78
+ height: 100px;
79
+ }
80
+ </style>
81
+ """, unsafe_allow_html=True)
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ streamlit
2
+ phidata
3
+ google-generativeai
4
+ openai
5
+ duckduckgo-search