Spaces:
Build error
Build error
Commit ·
d3a35cb
1
Parent(s): 89e42b0
computer vision 1
Browse files
app.py
CHANGED
|
@@ -6,7 +6,8 @@ import os
|
|
| 6 |
from ultralytics import YOLO
|
| 7 |
|
| 8 |
file_urls = [
|
| 9 |
-
'https://lh3.googleusercontent.com/a2iyhpYl4Jgzc0r7MYgXQI1BGwkutp3rKuauNpkEbD3Z_HP-gf29M-wugKebKJQdl8ILtKWN-vOZAS9r1qMsI88=w16383'
|
|
|
|
| 10 |
]
|
| 11 |
|
| 12 |
def download_file(url, save_name):
|
|
@@ -50,42 +51,42 @@ interface_image = gr.Interface(
|
|
| 50 |
cache_examples=False,
|
| 51 |
)
|
| 52 |
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
|
| 72 |
-
|
| 73 |
-
|
| 74 |
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
|
|
|
| 6 |
from ultralytics import YOLO
|
| 7 |
|
| 8 |
file_urls = [
|
| 9 |
+
'https://lh3.googleusercontent.com/a2iyhpYl4Jgzc0r7MYgXQI1BGwkutp3rKuauNpkEbD3Z_HP-gf29M-wugKebKJQdl8ILtKWN-vOZAS9r1qMsI88=w16383',
|
| 10 |
+
'https://www.dropbox.com/s/7sjfwncffg8xej2/video_7.mp4?dl=1'
|
| 11 |
]
|
| 12 |
|
| 13 |
def download_file(url, save_name):
|
|
|
|
| 51 |
cache_examples=False,
|
| 52 |
)
|
| 53 |
|
| 54 |
+
def show_preds_video(video_path):
|
| 55 |
+
cap = cv2.VideoCapture(video_path)
|
| 56 |
+
while(cap.isOpened()):
|
| 57 |
+
ret, frame = cap.read()
|
| 58 |
+
if ret:
|
| 59 |
+
frame_copy = frame.copy()
|
| 60 |
+
outputs = model.predict(source=frame)
|
| 61 |
+
results = outputs[0].cpu().numpy()
|
| 62 |
+
for i, det in enumerate(results.boxes.xyxy):
|
| 63 |
+
cv2.rectangle(
|
| 64 |
+
frame_copy,
|
| 65 |
+
(int(det[0]), int(det[1])),
|
| 66 |
+
(int(det[2]), int(det[3])),
|
| 67 |
+
color=(0, 0, 255),
|
| 68 |
+
thickness=2,
|
| 69 |
+
lineType=cv2.LINE_AA
|
| 70 |
+
)
|
| 71 |
+
yield cv2.cvtColor(frame_copy, cv2.COLOR_BGR2RGB)
|
| 72 |
|
| 73 |
+
inputs_video = [
|
| 74 |
+
gr.components.Video(type="filepath", label="Input Video"),
|
| 75 |
|
| 76 |
+
]
|
| 77 |
+
outputs_video = [
|
| 78 |
+
gr.components.Image(type="numpy", label="Output Image"),
|
| 79 |
+
]
|
| 80 |
+
interface_video = gr.Interface(
|
| 81 |
+
fn=show_preds_video,
|
| 82 |
+
inputs=inputs_video,
|
| 83 |
+
outputs=outputs_video,
|
| 84 |
+
title="Video Processing ",
|
| 85 |
+
examples=video_path,
|
| 86 |
+
cache_examples=False,
|
| 87 |
+
)
|
| 88 |
|
| 89 |
+
gr.TabbedInterface(
|
| 90 |
+
[interface_image, interface_video],
|
| 91 |
+
tab_names=['Image inference', 'Video inference']
|
| 92 |
+
).queue().launch()
|