jonathanagustin
commited on
Commit
•
8b391b7
1
Parent(s):
068f4f8
Update app.py
Browse files
app.py
CHANGED
@@ -112,7 +112,20 @@ class SearchService:
|
|
112 |
return None
|
113 |
|
114 |
|
115 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
116 |
def __init__(self):
|
117 |
logging.getLogger().setLevel(logging.DEBUG)
|
118 |
self.model = YOLO("yolov8x.pt")
|
@@ -121,7 +134,7 @@ class LiveStreamAnnotator:
|
|
121 |
"open-sans.zip",
|
122 |
)
|
123 |
self.current_page_token = None
|
124 |
-
self.streams =
|
125 |
# Gradio UI Elements
|
126 |
initial_gallery_items = [
|
127 |
(stream["thumbnail_url"], stream["title"]) for stream in self.streams
|
@@ -129,16 +142,17 @@ class LiveStreamAnnotator:
|
|
129 |
self.gallery = gr.Gallery(
|
130 |
label="Live YouTube Videos",
|
131 |
value=initial_gallery_items,
|
132 |
-
show_label=
|
133 |
columns=[3],
|
134 |
rows=[10],
|
135 |
object_fit="contain",
|
136 |
height="auto",
|
|
|
137 |
)
|
138 |
self.search_input = gr.Textbox(label="Search Live YouTube Videos")
|
139 |
self.stream_input = gr.Textbox(label="URL of Live YouTube Video")
|
140 |
self.output_image = gr.AnnotatedImage(show_label=False)
|
141 |
-
self.search_button = gr.Button("Search")
|
142 |
self.submit_button = gr.Button("Detect Objects", variant="primary", size="lg")
|
143 |
self.prev_page_button = gr.Button("Previous Page", interactive=False)
|
144 |
self.next_page_button = gr.Button("Next Page", interactive=False)
|
@@ -198,7 +212,7 @@ class LiveStreamAnnotator:
|
|
198 |
error_image = np.zeros((1920, 1080, 3), dtype=np.uint8)
|
199 |
pil_image = Image.fromarray(error_image)
|
200 |
draw = ImageDraw.Draw(pil_image)
|
201 |
-
font = ImageFont.truetype(
|
202 |
text_size = draw.textsize(message, font=font)
|
203 |
position = ((1920 - text_size[0]) // 2, (1080 - text_size[1]) // 2)
|
204 |
draw.text(position, message, (0, 0, 255), font=font)
|
@@ -232,16 +246,17 @@ class LiveStreamAnnotator:
|
|
232 |
"<center><h1><b>Object Detection in Live YouTube Streams</b></h1></center>"
|
233 |
)
|
234 |
with gr.Column():
|
235 |
-
self.stream_input.render()
|
236 |
with gr.Group():
|
237 |
-
|
238 |
-
|
|
|
|
|
239 |
with gr.Group():
|
240 |
with gr.Row():
|
241 |
self.search_input.render()
|
242 |
self.search_button.render()
|
243 |
-
|
244 |
-
|
245 |
|
246 |
@self.gallery.select(
|
247 |
inputs=None, outputs=[self.output_image, self.stream_input]
|
@@ -274,7 +289,7 @@ class LiveStreamAnnotator:
|
|
274 |
def annotate_stream(url):
|
275 |
return self.capture_frame(url)
|
276 |
|
277 |
-
app.queue().launch(show_api=False)
|
278 |
|
279 |
if __name__ == "__main__":
|
280 |
-
|
|
|
112 |
return None
|
113 |
|
114 |
|
115 |
+
INITIAL_STREAMS = []
|
116 |
+
for result in SearchService.search("world live cams", SearchFilter.LIVE):
|
117 |
+
INITIAL_STREAMS.append(
|
118 |
+
{
|
119 |
+
"thumbnail_url": result["thumbnail_urls"][-1]
|
120 |
+
if result["thumbnail_urls"]
|
121 |
+
else "",
|
122 |
+
"title": result["title"],
|
123 |
+
"video_id": result["video_id"],
|
124 |
+
"label": result["video_id"],
|
125 |
+
}
|
126 |
+
)
|
127 |
+
|
128 |
+
class YouTubeObjectDetection:
|
129 |
def __init__(self):
|
130 |
logging.getLogger().setLevel(logging.DEBUG)
|
131 |
self.model = YOLO("yolov8x.pt")
|
|
|
134 |
"open-sans.zip",
|
135 |
)
|
136 |
self.current_page_token = None
|
137 |
+
self.streams = INITIAL_STREAMS
|
138 |
# Gradio UI Elements
|
139 |
initial_gallery_items = [
|
140 |
(stream["thumbnail_url"], stream["title"]) for stream in self.streams
|
|
|
142 |
self.gallery = gr.Gallery(
|
143 |
label="Live YouTube Videos",
|
144 |
value=initial_gallery_items,
|
145 |
+
show_label=True,
|
146 |
columns=[3],
|
147 |
rows=[10],
|
148 |
object_fit="contain",
|
149 |
height="auto",
|
150 |
+
allow_preview=False,
|
151 |
)
|
152 |
self.search_input = gr.Textbox(label="Search Live YouTube Videos")
|
153 |
self.stream_input = gr.Textbox(label="URL of Live YouTube Video")
|
154 |
self.output_image = gr.AnnotatedImage(show_label=False)
|
155 |
+
self.search_button = gr.Button("Search", size="lg")
|
156 |
self.submit_button = gr.Button("Detect Objects", variant="primary", size="lg")
|
157 |
self.prev_page_button = gr.Button("Previous Page", interactive=False)
|
158 |
self.next_page_button = gr.Button("Next Page", interactive=False)
|
|
|
212 |
error_image = np.zeros((1920, 1080, 3), dtype=np.uint8)
|
213 |
pil_image = Image.fromarray(error_image)
|
214 |
draw = ImageDraw.Draw(pil_image)
|
215 |
+
font = ImageFont.truetype(self.font_path, 24)
|
216 |
text_size = draw.textsize(message, font=font)
|
217 |
position = ((1920 - text_size[0]) // 2, (1080 - text_size[1]) // 2)
|
218 |
draw.text(position, message, (0, 0, 255), font=font)
|
|
|
246 |
"<center><h1><b>Object Detection in Live YouTube Streams</b></h1></center>"
|
247 |
)
|
248 |
with gr.Column():
|
|
|
249 |
with gr.Group():
|
250 |
+
with gr.Row():
|
251 |
+
self.stream_input.render()
|
252 |
+
self.submit_button.render()
|
253 |
+
self.output_image.render()
|
254 |
with gr.Group():
|
255 |
with gr.Row():
|
256 |
self.search_input.render()
|
257 |
self.search_button.render()
|
258 |
+
with gr.Row():
|
259 |
+
self.gallery.render()
|
260 |
|
261 |
@self.gallery.select(
|
262 |
inputs=None, outputs=[self.output_image, self.stream_input]
|
|
|
289 |
def annotate_stream(url):
|
290 |
return self.capture_frame(url)
|
291 |
|
292 |
+
return app.queue().launch(show_api=False)
|
293 |
|
294 |
if __name__ == "__main__":
|
295 |
+
YouTubeObjectDetection().render()
|