Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -36,7 +36,7 @@ import numpy as np
|
|
| 36 |
from ultralytics import YOLO
|
| 37 |
import streamlink
|
| 38 |
from PIL import Image
|
| 39 |
-
from youtubesearchpython import
|
| 40 |
import imageio.v3 as iio
|
| 41 |
|
| 42 |
logging.basicConfig(level=logging.DEBUG)
|
|
@@ -67,14 +67,20 @@ class SearchService:
|
|
| 67 |
"""
|
| 68 |
results = []
|
| 69 |
# Apply live filter if needed
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
return results
|
| 79 |
|
| 80 |
@staticmethod
|
|
@@ -170,6 +176,10 @@ class LiveYouTubeObjectDetector:
|
|
| 170 |
reader = iio.imiter(stream_url, plugin='ffmpeg', fps=1)
|
| 171 |
loop = asyncio.get_event_loop()
|
| 172 |
frame = await loop.run_in_executor(None, next, reader, None)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
return frame
|
| 174 |
except StopIteration:
|
| 175 |
logging.warning("Could not read frame from stream.")
|
|
|
|
| 36 |
from ultralytics import YOLO
|
| 37 |
import streamlink
|
| 38 |
from PIL import Image
|
| 39 |
+
from youtubesearchpython import CustomSearch, SearchMode
|
| 40 |
import imageio.v3 as iio
|
| 41 |
|
| 42 |
logging.basicConfig(level=logging.DEBUG)
|
|
|
|
| 67 |
"""
|
| 68 |
results = []
|
| 69 |
# Apply live filter if needed
|
| 70 |
+
if live:
|
| 71 |
+
# Use CustomSearch with SearchMode.live to filter live videos
|
| 72 |
+
search = CustomSearch(query, SearchMode.live, limit=20)
|
| 73 |
+
else:
|
| 74 |
+
# Use CustomSearch with default mode for regular videos
|
| 75 |
+
search = CustomSearch(query, SearchMode.videos, limit=20)
|
| 76 |
+
for result in search.result()['result']:
|
| 77 |
+
if 'video' in result:
|
| 78 |
+
video = result['video']
|
| 79 |
+
results.append({
|
| 80 |
+
'video_id': video['id'],
|
| 81 |
+
'thumbnail_url': video['thumbnails'][-1]['url'],
|
| 82 |
+
'title': video['title'],
|
| 83 |
+
})
|
| 84 |
return results
|
| 85 |
|
| 86 |
@staticmethod
|
|
|
|
| 176 |
reader = iio.imiter(stream_url, plugin='ffmpeg', fps=1)
|
| 177 |
loop = asyncio.get_event_loop()
|
| 178 |
frame = await loop.run_in_executor(None, next, reader, None)
|
| 179 |
+
if frame is None:
|
| 180 |
+
return None
|
| 181 |
+
# Resize frame if needed
|
| 182 |
+
frame = cv2.resize(frame, (1280, 720))
|
| 183 |
return frame
|
| 184 |
except StopIteration:
|
| 185 |
logging.warning("Could not read frame from stream.")
|