added YouTube URL option
Browse files- app.py +29 -16
- requirements.txt +6 -5
app.py
CHANGED
|
@@ -1,10 +1,7 @@
|
|
| 1 |
-
import torch
|
| 2 |
-
import tensorflow as tf
|
| 3 |
import time
|
| 4 |
import os
|
| 5 |
import logging
|
| 6 |
-
|
| 7 |
-
from typing import List, NamedTuple
|
| 8 |
|
| 9 |
import av
|
| 10 |
import cv2
|
|
@@ -21,6 +18,7 @@ from transformers import pipeline # Import Hugging Face transformers pipeline
|
|
| 21 |
|
| 22 |
import requests
|
| 23 |
from io import BytesIO # Import for handling byte streams
|
|
|
|
| 24 |
|
| 25 |
|
| 26 |
# CHANGE CODE BELOW HERE, USE TO REPLACE WITH YOUR WANTED ANALYSIS.
|
|
@@ -132,17 +130,6 @@ def analyze_sentiment(face):
|
|
| 132 |
# Suppress FFmpeg logs
|
| 133 |
os.environ["FFMPEG_LOG_LEVEL"] = "quiet"
|
| 134 |
|
| 135 |
-
# Suppress TensorFlow or PyTorch progress bars
|
| 136 |
-
|
| 137 |
-
tf.get_logger().setLevel("ERROR")
|
| 138 |
-
os.environ["TF_CPP_MIN_LOG_LEVEL"] = "3"
|
| 139 |
-
|
| 140 |
-
# Suppress PyTorch logs
|
| 141 |
-
|
| 142 |
-
logging.getLogger().setLevel(logging.WARNING)
|
| 143 |
-
torch.set_num_threads(1)
|
| 144 |
-
logging.getLogger("torch").setLevel(logging.ERROR)
|
| 145 |
-
|
| 146 |
# Suppress Streamlit logs using the logging module
|
| 147 |
logging.getLogger("streamlit").setLevel(logging.ERROR)
|
| 148 |
|
|
@@ -239,7 +226,11 @@ with col1:
|
|
| 239 |
st.subheader("Or Enter Image URL")
|
| 240 |
image_url = st.text_input("Image URL")
|
| 241 |
|
| 242 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
| 243 |
st.subheader("Upload a Video")
|
| 244 |
uploaded_video = st.file_uploader(
|
| 245 |
"Choose a video...", type=["mp4", "avi", "mov", "mkv"]
|
|
@@ -358,6 +349,28 @@ def process_video(video_path):
|
|
| 358 |
|
| 359 |
cap.release() # Release the video capture object
|
| 360 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 361 |
|
| 362 |
# If a video is uploaded or a URL is provided, process the video
|
| 363 |
if uploaded_video is not None or video_url:
|
|
|
|
|
|
|
|
|
|
| 1 |
import time
|
| 2 |
import os
|
| 3 |
import logging
|
| 4 |
+
|
|
|
|
| 5 |
|
| 6 |
import av
|
| 7 |
import cv2
|
|
|
|
| 18 |
|
| 19 |
import requests
|
| 20 |
from io import BytesIO # Import for handling byte streams
|
| 21 |
+
import yt_dlp
|
| 22 |
|
| 23 |
|
| 24 |
# CHANGE CODE BELOW HERE, USE TO REPLACE WITH YOUR WANTED ANALYSIS.
|
|
|
|
| 130 |
# Suppress FFmpeg logs
|
| 131 |
os.environ["FFMPEG_LOG_LEVEL"] = "quiet"
|
| 132 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 133 |
# Suppress Streamlit logs using the logging module
|
| 134 |
logging.getLogger("streamlit").setLevel(logging.ERROR)
|
| 135 |
|
|
|
|
| 226 |
st.subheader("Or Enter Image URL")
|
| 227 |
image_url = st.text_input("Image URL")
|
| 228 |
|
| 229 |
+
# Text input for YouTube URL
|
| 230 |
+
st.subheader("Enter a YouTube URL")
|
| 231 |
+
youtube_url = st.text_input("YouTube URL")
|
| 232 |
+
|
| 233 |
+
# File uploader for videos
|
| 234 |
st.subheader("Upload a Video")
|
| 235 |
uploaded_video = st.file_uploader(
|
| 236 |
"Choose a video...", type=["mp4", "avi", "mov", "mkv"]
|
|
|
|
| 349 |
|
| 350 |
cap.release() # Release the video capture object
|
| 351 |
|
| 352 |
+
# Function to get the video stream URL from YouTube using yt-dlp
|
| 353 |
+
|
| 354 |
+
|
| 355 |
+
def get_youtube_stream_url(youtube_url):
|
| 356 |
+
ydl_opts = {
|
| 357 |
+
'format': 'best[ext=mp4]',
|
| 358 |
+
'quiet': True,
|
| 359 |
+
}
|
| 360 |
+
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
| 361 |
+
info_dict = ydl.extract_info(youtube_url, download=False)
|
| 362 |
+
stream_url = info_dict['url']
|
| 363 |
+
return stream_url
|
| 364 |
+
|
| 365 |
+
|
| 366 |
+
# If a YouTube URL is provided, process the video
|
| 367 |
+
if youtube_url:
|
| 368 |
+
analysis_init() # Initialize the analysis UI
|
| 369 |
+
|
| 370 |
+
stream_url = get_youtube_stream_url(youtube_url)
|
| 371 |
+
|
| 372 |
+
process_video(stream_url) # Process the video
|
| 373 |
+
|
| 374 |
|
| 375 |
# If a video is uploaded or a URL is provided, process the video
|
| 376 |
if uploaded_video is not None or video_url:
|
requirements.txt
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
|
|
|
|
|
| 1 |
streamlit
|
| 2 |
opencv-python-headless
|
| 3 |
numpy
|
| 4 |
transformers
|
| 5 |
-
torch
|
| 6 |
-
mtcnn
|
| 7 |
setuptools
|
| 8 |
-
tensorflow
|
| 9 |
-
tf-keras
|
| 10 |
streamlit_webrtc
|
| 11 |
-
twilio
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
tensorboard==2.16.2
|
| 2 |
+
tf-keras
|
| 3 |
streamlit
|
| 4 |
opencv-python-headless
|
| 5 |
numpy
|
| 6 |
transformers
|
|
|
|
|
|
|
| 7 |
setuptools
|
|
|
|
|
|
|
| 8 |
streamlit_webrtc
|
| 9 |
+
twilio
|
| 10 |
+
mtcnn
|
| 11 |
+
yt-dlp
|
| 12 |
+
watchdog
|