Update app.py
Browse files12345678910111213141523 unmodified lines39404142434445464748495051525354555657585960616263646566676869707172735 unmodified lines79808182838485import streamlit as stfrom yt_dlp import YoutubeDLfrom phi.agent import Agentfrom phi.model.google import Geminifrom phi.tools.duckduckgo import DuckDuckGofrom google.generativeai import upload_file, get_fileimport google.generativeai as genaiimport timeimport osfrom pathlib import Pathimport tempfilefrom dotenv import load_dotenv# Load environment variablesload_dotenv()23 unmodified lines# Initialize the agentmultimodal_Agent = initialize_agent()import tempfilefrom yt_dlp import YoutubeDLimport browser_cookie3from yt_dlp import YoutubeDLdef download_youtube_video(youtube_url):# Extract cookies from browser (Chrome, Firefox, etc.)cookies = browser_cookie3.load()# yt-dlp optionsydl_opts = {'format': 'bestvideo+bestaudio/best', # Download best video and audio'outtmpl': 'downloaded_video.mp4', # Output file path'cookies': cookies, # Use cookies directly from browser'quiet': True, # Suppress yt-dlp output}try:# Download the videowith YoutubeDL(ydl_opts) as ydl:ydl.download([youtube_url])print("Download successful!")except Exception as e:print(f"An error occurred: {str(e)}")# YouTube video URL inputyoutube_url = st.text_input(5 unmodified linesif youtube_url:try:with st.spinner("Downloading and processing the YouTube video..."):# Download video using yt-dlpvideo_path = download_youtube_video(youtube_url)# Display video1234567891011121314151623 unmodified lines404142434445464748495051525354555657585960616263646566676869707172735 unmodified lines79808182838485import streamlit as stfrom pytube import YouTubefrom phi.agent import Agentfrom phi.model.google import Geminifrom phi.tools.duckduckgo import DuckDuckGofrom google.generativeai import upload_file, get_fileimport google.generativeai as genaiimport timefrom pathlib import Pathfrom dotenv import load_dotenvimport osimport tempfile# Load environment variablesload_dotenv()23 unmodified lines# Initialize the agentmultimodal_Agent = initialize_agent()# Function to download YouTube video using pytubedef download_youtube_video(youtube_url):"""Downloads a YouTube video using pytube.Parameters:- youtube_url: The URL of the YouTube video.Returns:- The path to the downloaded video file."""# Initialize YouTube object using pytubeyt = YouTube(youtube_url)# Get the highest resolution stream availablevideo_stream = yt.streams.get_highest_resolution()# Temporary file for the videowith tempfile.NamedTemporaryFile(delete=False, suffix=".mp4") as temp_video:temp_video_path = temp_video.nametry:# Download the video to the temporary filevideo_stream.download(output_path=temp_video_path)return temp_video_path # Return the video file pathexcept Exception as e:raise RuntimeError(f"An error occurred while downloading the video: {str(e)}")# YouTube video URL inputyoutube_url = st.text_input(5 unmodified linesif youtube_url:try:with st.spinner("Downloading and processing the YouTube video..."):# Download video using pytubevideo_path = download_youtube_video(youtube_url)# Display video
app.py+29-29