eusholli commited on
Commit
d815415
1 Parent(s): c82ab41

Added YouTube URL option

Browse files
Files changed (2) hide show
  1. app.py +27 -16
  2. requirements.txt +3 -4
app.py CHANGED
@@ -1,11 +1,8 @@
 
1
  from ultralytics import YOLO
2
- import torch
3
- import tensorflow as tf
4
  import time
5
  import os
6
  import logging
7
- from pathlib import Path
8
- from typing import List
9
 
10
  import av
11
  import cv2
@@ -16,7 +13,6 @@ from streamlit_webrtc import WebRtcMode, webrtc_streamer
16
  from utils.download import download_file
17
  from utils.turn import get_ice_servers
18
 
19
- from mtcnn import MTCNN # Import MTCNN for face detection
20
  from PIL import Image, ImageDraw # Import PIL for image processing
21
  from transformers import pipeline # Import Hugging Face transformers pipeline
22
 
@@ -98,17 +94,6 @@ def analyze_frame(frame: np.ndarray):
98
  # Suppress FFmpeg logs
99
  os.environ["FFMPEG_LOG_LEVEL"] = "quiet"
100
 
101
- # Suppress TensorFlow or PyTorch progress bars
102
-
103
- tf.get_logger().setLevel("ERROR")
104
- os.environ["TF_CPP_MIN_LOG_LEVEL"] = "3"
105
-
106
- # Suppress PyTorch logs
107
-
108
- logging.getLogger().setLevel(logging.WARNING)
109
- torch.set_num_threads(1)
110
- logging.getLogger("torch").setLevel(logging.ERROR)
111
-
112
  # Suppress Streamlit logs using the logging module
113
  logging.getLogger("streamlit").setLevel(logging.ERROR)
114
 
@@ -205,6 +190,10 @@ with col1:
205
  st.subheader("Or Enter Image URL")
206
  image_url = st.text_input("Image URL")
207
 
 
 
 
 
208
  # File uploader for videos
209
  st.subheader("Upload a Video")
210
  uploaded_video = st.file_uploader(
@@ -324,6 +313,28 @@ def process_video(video_path):
324
  cap.release() # Release the video capture object
325
 
326
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
327
  # If a video is uploaded or a URL is provided, process the video
328
  if uploaded_video is not None or video_url:
329
  analysis_init() # Initialize the analysis UI
 
1
+ import yt_dlp
2
  from ultralytics import YOLO
 
 
3
  import time
4
  import os
5
  import logging
 
 
6
 
7
  import av
8
  import cv2
 
13
  from utils.download import download_file
14
  from utils.turn import get_ice_servers
15
 
 
16
  from PIL import Image, ImageDraw # Import PIL for image processing
17
  from transformers import pipeline # Import Hugging Face transformers pipeline
18
 
 
94
  # Suppress FFmpeg logs
95
  os.environ["FFMPEG_LOG_LEVEL"] = "quiet"
96
 
 
 
 
 
 
 
 
 
 
 
 
97
  # Suppress Streamlit logs using the logging module
98
  logging.getLogger("streamlit").setLevel(logging.ERROR)
99
 
 
190
  st.subheader("Or Enter Image URL")
191
  image_url = st.text_input("Image URL")
192
 
193
+ # Text input for video URL
194
+ st.subheader("Enter a YouTube URL")
195
+ youtube_url = st.text_input("YouTube URL")
196
+
197
  # File uploader for videos
198
  st.subheader("Upload a Video")
199
  uploaded_video = st.file_uploader(
 
313
  cap.release() # Release the video capture object
314
 
315
 
316
+ # Function to get the video stream URL from YouTube using yt-dlp
317
+
318
+
319
+ def get_youtube_stream_url(youtube_url):
320
+ ydl_opts = {
321
+ 'format': 'best[ext=mp4]',
322
+ 'quiet': True,
323
+ }
324
+ with yt_dlp.YoutubeDL(ydl_opts) as ydl:
325
+ info_dict = ydl.extract_info(youtube_url, download=False)
326
+ stream_url = info_dict['url']
327
+ return stream_url
328
+
329
+
330
+ # If a YouTube URL is provided, process the video
331
+ if youtube_url:
332
+ analysis_init() # Initialize the analysis UI
333
+
334
+ stream_url = get_youtube_stream_url(youtube_url)
335
+
336
+ process_video(stream_url) # Process the video
337
+
338
  # If a video is uploaded or a URL is provided, process the video
339
  if uploaded_video is not None or video_url:
340
  analysis_init() # Initialize the analysis UI
requirements.txt CHANGED
@@ -2,10 +2,9 @@ streamlit
2
  opencv-python-headless
3
  numpy
4
  transformers
5
- torch
6
  setuptools
7
- tensorflow
8
- tf-keras
9
  streamlit_webrtc
10
  twilio
11
- ultralytics
 
 
 
2
  opencv-python-headless
3
  numpy
4
  transformers
 
5
  setuptools
 
 
6
  streamlit_webrtc
7
  twilio
8
+ ultralytics
9
+ yt-dlp
10
+ watchdog