Spaces:
Running
Running
File size: 5,399 Bytes
9431860 083a014 9431860 083a014 9431860 083a014 9431860 083a014 9431860 083a014 9431860 236b4e0 9431860 58ddc5a 9431860 083a014 9431860 236b4e0 9431860 236b4e0 9431860 236b4e0 9431860 083a014 9431860 083a014 9431860 236b4e0 9431860 236b4e0 9431860 236b4e0 9431860 |
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 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
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
import os
from phi.model.groq import Groq
from phi.tools.youtube_tools import YouTubeTools
# Load environment variables
load_dotenv()
# Configure API keys
API_KEY = os.getenv("GOOGLE_API_KEY")
groq_api_key = os.getenv("GROQ_API_KEY")
if API_KEY:
genai.configure(api_key=API_KEY)
# Page configuration
st.set_page_config(
page_title="Multimodal AI Applications",
page_icon="🌐",
layout="wide"
)
# Custom CSS for UI Styling
def load_custom_css():
st.markdown(
"""
<style>
.stButton>button {
width: 100%;
height: 50px;
font-size: 18px;
font-weight: bold;
background: rgba(255, 255, 255, 0.2);
border-radius: 12px;
border: 2px solid rgba(255, 255, 255, 0.5);
box-shadow: 0px 4px 10px rgba(0, 0, 0, 0.2);
}
.stTextInput>div>div>input, .stTextArea>div>textarea {
background: rgba(255, 255, 255, 0.1);
border-radius: 8px;
border: 1px solid rgba(255, 255, 255, 0.3);
color: white;
padding: 10px;
}
</style>
""",
unsafe_allow_html=True
)
load_custom_css()
st.markdown("# 🎥 Video Transcription and AI Summary")
st.markdown("Upload a video or provide a YouTube link to get a transcription and AI-generated summary.")
# Tabs for the two applications
tab1, tab2 = st.tabs(["📤 Video Upload", "🔗 YouTube Video Analysis"])
# Tab 1: Video Summarizer with Gemini
with tab1:
st.subheader("Phidata Video AI Summarizer Agent 🎥")
@st.cache_resource
def initialize_agent():
return Agent(
name="Video AI Summarizer",
model=Gemini(id="gemini-2.0-flash-exp"),
tools=[DuckDuckGo()],
markdown=True,
)
multimodal_Agent = initialize_agent()
video_file = st.file_uploader("Upload a video file", type=['mp4'])
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?", "")
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..."):
processed_video = upload_file(video_path)
while processed_video.state.name == "PROCESSING":
time.sleep(1)
processed_video = get_file(processed_video.name)
prompt = f"""
Analyze the uploaded video and provide a summary.
Respond to: {user_query}
"""
response = multimodal_Agent.run(prompt, videos=[processed_video])
st.subheader("Analysis Result")
st.markdown(response.content)
except Exception as error:
st.error(f"Error: {error}")
finally:
Path(video_path).unlink(missing_ok=True)
else:
st.info("Upload a video file to begin analysis.")
# Tab 2: YouTube Video Analyzer with Groq
with tab2:
st.subheader("YouTube Video Analyzer 🎬")
try:
youtube_agent = Agent(
model=Groq(id="llama3-8b-8192", api_key=groq_api_key),
tools=[YouTubeTools(), DuckDuckGo()],
show_tool_calls=True,
get_video_captions=True,
get_video_data=True,
description="Analyze YouTube videos for content, key points, and web research.",
)
except Exception as e:
st.error(f"Error initializing the agent: {e}")
st.stop()
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 Video", key="analyze_video_button"):
if video_url:
with st.spinner("Analyzing..."):
try:
prompt = f"""
Analyze the YouTube video.
Provide a detailed summary with key points.
{f'Respond to: {user_query}' if user_query else ''}
Video URL: {video_url}
"""
output = youtube_agent.run(prompt)
st.subheader("Analysis Result")
st.markdown(output.content)
except Exception as e:
st.error(f"Error: {e}")
else:
st.warning("Please enter a YouTube video URL.") |