Update app.py
Browse files
app.py
CHANGED
@@ -1,15 +1,16 @@
|
|
1 |
import streamlit as st
|
2 |
-
from
|
3 |
from phi.agent import Agent
|
4 |
from phi.model.google import Gemini
|
5 |
from phi.tools.duckduckgo import DuckDuckGo
|
6 |
from google.generativeai import upload_file, get_file
|
7 |
import google.generativeai as genai
|
|
|
8 |
import time
|
9 |
-
import os
|
10 |
from pathlib import Path
|
11 |
-
import tempfile
|
12 |
from dotenv import load_dotenv
|
|
|
|
|
13 |
|
14 |
# Load environment variables
|
15 |
load_dotenv()
|
@@ -39,35 +40,34 @@ def initialize_agent():
|
|
39 |
# Initialize the agent
|
40 |
multimodal_Agent = initialize_agent()
|
41 |
|
42 |
-
|
43 |
-
from yt_dlp import YoutubeDL
|
44 |
-
|
45 |
-
import browser_cookie3
|
46 |
-
from yt_dlp import YoutubeDL
|
47 |
-
|
48 |
def download_youtube_video(youtube_url):
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
60 |
try:
|
61 |
-
# Download the video
|
62 |
-
|
63 |
-
ydl.download([youtube_url])
|
64 |
-
|
65 |
-
print("Download successful!")
|
66 |
|
|
|
67 |
except Exception as e:
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
|
72 |
# YouTube video URL input
|
73 |
youtube_url = st.text_input(
|
@@ -79,7 +79,7 @@ youtube_url = st.text_input(
|
|
79 |
if youtube_url:
|
80 |
try:
|
81 |
with st.spinner("Downloading and processing the YouTube video..."):
|
82 |
-
# Download video using
|
83 |
video_path = download_youtube_video(youtube_url)
|
84 |
|
85 |
# Display video
|
|
|
1 |
import streamlit as st
|
2 |
+
from pytube import YouTube
|
3 |
from phi.agent import Agent
|
4 |
from phi.model.google import Gemini
|
5 |
from phi.tools.duckduckgo import DuckDuckGo
|
6 |
from google.generativeai import upload_file, get_file
|
7 |
import google.generativeai as genai
|
8 |
+
|
9 |
import time
|
|
|
10 |
from pathlib import Path
|
|
|
11 |
from dotenv import load_dotenv
|
12 |
+
import os
|
13 |
+
import tempfile
|
14 |
|
15 |
# Load environment variables
|
16 |
load_dotenv()
|
|
|
40 |
# Initialize the agent
|
41 |
multimodal_Agent = initialize_agent()
|
42 |
|
43 |
+
# Function to download YouTube video using pytube
|
|
|
|
|
|
|
|
|
|
|
44 |
def download_youtube_video(youtube_url):
|
45 |
+
"""
|
46 |
+
Downloads a YouTube video using pytube.
|
47 |
+
|
48 |
+
Parameters:
|
49 |
+
- youtube_url: The URL of the YouTube video.
|
50 |
+
|
51 |
+
Returns:
|
52 |
+
- The path to the downloaded video file.
|
53 |
+
"""
|
54 |
+
# Initialize YouTube object using pytube
|
55 |
+
yt = YouTube(youtube_url)
|
56 |
+
|
57 |
+
# Get the highest resolution stream available
|
58 |
+
video_stream = yt.streams.get_highest_resolution()
|
59 |
+
|
60 |
+
# Temporary file for the video
|
61 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp4") as temp_video:
|
62 |
+
temp_video_path = temp_video.name
|
63 |
+
|
64 |
try:
|
65 |
+
# Download the video to the temporary file
|
66 |
+
video_stream.download(output_path=temp_video_path)
|
|
|
|
|
|
|
67 |
|
68 |
+
return temp_video_path # Return the video file path
|
69 |
except Exception as e:
|
70 |
+
raise RuntimeError(f"An error occurred while downloading the video: {str(e)}")
|
|
|
|
|
71 |
|
72 |
# YouTube video URL input
|
73 |
youtube_url = st.text_input(
|
|
|
79 |
if youtube_url:
|
80 |
try:
|
81 |
with st.spinner("Downloading and processing the YouTube video..."):
|
82 |
+
# Download video using pytube
|
83 |
video_path = download_youtube_video(youtube_url)
|
84 |
|
85 |
# Display video
|