Spaces:
Running
Running
File size: 5,394 Bytes
6df9adf 200a5eb 6df9adf 200a5eb 6df9adf 200a5eb 790d0c2 6df9adf 200a5eb 6df9adf 200a5eb 6df9adf 841f853 6df9adf 200a5eb 6df9adf 200a5eb 6df9adf 200a5eb 6ce1d52 200a5eb 6ce1d52 1834974 6ce1d52 841f853 1834974 6df9adf 200a5eb 6df9adf 841f853 |
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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 |
import streamlit as st
from phi.agent import Agent
from phi.model.google import Gemini
from phi.tools.duckduckgo import DuckDuckGo
from google.generativeai import upload_file, get_file
import google.generativeai as genai
import time
from pathlib import Path
import tempfile
from dotenv import load_dotenv
load_dotenv()
import os
API_KEY = os.getenv("GOOGLE_API_KEY")
if API_KEY:
genai.configure(api_key=API_KEY)
# Page configuration
st.set_page_config(
page_title="Multimodal AI Agent Video Notes Writer",
page_icon="π₯",
layout="wide"
)
st.title("Phidata Video AI Notes Writer π₯π€π¬")
st.header("Powered by Gemini 2.0 Flash Exp")
@st.cache_resource
def initialize_agent():
return Agent(
name="Video AI Notes-Writer",
model=Gemini(id="gemini-2.0-flash-exp"),
tools=[DuckDuckGo()],
markdown=True,
)
# Initialize the agent
multimodal_Agent = initialize_agent()
# File uploader
video_file = st.file_uploader(
"Upload a video file", type=['mp4'], help="Upload a video for AI analysis"
)
if video_file:
with tempfile.NamedTemporaryFile(delete=False, suffix='.mp4') as temp_video:
temp_video.write(video_file.read())
video_path = temp_video.name
st.video(video_path, format="video/mp4", start_time=0)
user_query = st.text_area(
"What insights are you seeking from the video?",
value="Generate detailed student-style notes from this video in paragraph format, with thorough explanations of concepts and ideas.",
help="Provide specific questions or insights you want from the video."
)
if st.button("π Analyze Video", key="analyze_video_button"):
if not user_query:
st.warning("Please enter a question or insight to analyze the video.")
else:
try:
with st.spinner("Processing video and creating detailed notes..."):
# Upload and process video file
processed_video = upload_file(video_path)
while processed_video.state.name == "PROCESSING":
time.sleep(1)
processed_video = get_file(processed_video.name)
# Enhanced prompt for detailed student-style notes with improved structure
analysis_prompt = (
f"""
Analyze the uploaded video thoroughly and generate EXTREMELY DETAILED STUDENT NOTES in full paragraph format.
Your notes should:
- Begin with a comprehensive introduction that outlines the topic and objectives.
- Divide the content into clearly labelled sections with headings and subheadings (e.g., "Introduction", "Main Concepts", "Detailed Explanations", and "Conclusion").
- Provide detailed explanations of key concepts, ensuring each section includes a narrative summary of its key takeaways.
- Include smooth transitions between sections and paragraphs for a cohesive flow.
- Reference and explain any visual aids, diagrams, or slides mentioned in the lecture.
- Incorporate reflective questions or critical insights to prompt further analysis of the material.
- Maintain a student-friendly yet rigorous tone, similar to well-structured textbook content.
- Conclude with a summary paragraph that captures the main ideas.
- Remember to include every point discussed in the video. Never ever miss a point discussed in a video.
- The Notes should be in detail, it should help the user to know whatever content is present in the video.
- If there is a mathematical expression you need to write it down
-If there is a code then you have to write it down.
IMPORTANT: DO NOT use bullet points or lists. Present all information in well-developed and explained paragraphs.
Additional context/question from user: {user_query}
The final output should resemble detailed, structured textbook content that thoroughly explains all concepts from the video.
"""
)
# AI agent processing
response = multimodal_Agent.run(analysis_prompt, videos=[processed_video])
# Display the result
st.subheader("π Detailed Notes")
st.markdown(response.content)
# Simple download option
st.download_button(
label="Download Notes",
data=response.content,
file_name="video_notes.md",
mime="text/markdown",
)
except Exception as error:
st.error(f"An error occurred during analysis: {error}")
finally:
# Clean up temporary video file
Path(video_path).unlink(missing_ok=True)
else:
st.info("Upload a video file to begin analysis.")
|