Spaces:
Runtime error
Runtime error
Commit
·
cc35739
1
Parent(s):
a3fa1e8
Update app.py
Browse files
app.py
CHANGED
|
@@ -20,10 +20,7 @@ def download_file(url, save_name):
|
|
| 20 |
|
| 21 |
for i, url in enumerate(file_urls):
|
| 22 |
if 'mp4' in file_urls[i]:
|
| 23 |
-
|
| 24 |
-
file_urls[i],
|
| 25 |
-
f"video.mp4"
|
| 26 |
-
)
|
| 27 |
else:
|
| 28 |
download_file(
|
| 29 |
file_urls[i],
|
|
@@ -32,7 +29,6 @@ for i, url in enumerate(file_urls):
|
|
| 32 |
|
| 33 |
model = YOLO('best.pt')
|
| 34 |
path = [['image_0.jpg'], ['image_1.jpg']]
|
| 35 |
-
video_path = [['video.mp4']]
|
| 36 |
|
| 37 |
def show_preds_image(image_path):
|
| 38 |
image = cv2.imread(image_path)
|
|
@@ -63,43 +59,7 @@ interface_image = gr.Interface(
|
|
| 63 |
examples=path,
|
| 64 |
cache_examples=False,
|
| 65 |
)
|
| 66 |
-
|
| 67 |
-
def show_preds_video(video_path):
|
| 68 |
-
cap = cv2.VideoCapture(video_path)
|
| 69 |
-
while(cap.isOpened()):
|
| 70 |
-
ret, frame = cap.read()
|
| 71 |
-
if ret:
|
| 72 |
-
frame_copy = frame.copy()
|
| 73 |
-
outputs = model.predict(source=frame)
|
| 74 |
-
results = outputs[0].cpu().numpy()
|
| 75 |
-
for i, det in enumerate(results.boxes.xyxy):
|
| 76 |
-
cv2.rectangle(
|
| 77 |
-
frame_copy,
|
| 78 |
-
(int(det[0]), int(det[1])),
|
| 79 |
-
(int(det[2]), int(det[3])),
|
| 80 |
-
color=(0, 0, 255),
|
| 81 |
-
thickness=2,
|
| 82 |
-
lineType=cv2.LINE_AA
|
| 83 |
-
)
|
| 84 |
-
yield cv2.cvtColor(frame_copy, cv2.COLOR_BGR2RGB)
|
| 85 |
-
|
| 86 |
-
inputs_video = [
|
| 87 |
-
gr.components.Video(type="filepath", label="Input Video"),
|
| 88 |
-
|
| 89 |
-
]
|
| 90 |
-
outputs_video = [
|
| 91 |
-
gr.components.Image(type="numpy", label="Output Image"),
|
| 92 |
-
]
|
| 93 |
-
interface_video = gr.Interface(
|
| 94 |
-
fn=show_preds_video,
|
| 95 |
-
inputs=inputs_video,
|
| 96 |
-
outputs=outputs_video,
|
| 97 |
-
title="Pothole detector",
|
| 98 |
-
examples=video_path,
|
| 99 |
-
cache_examples=False,
|
| 100 |
-
)
|
| 101 |
-
|
| 102 |
gr.TabbedInterface(
|
| 103 |
-
[interface_image
|
| 104 |
-
tab_names=['Image inference'
|
| 105 |
).queue().launch()
|
|
|
|
| 20 |
|
| 21 |
for i, url in enumerate(file_urls):
|
| 22 |
if 'mp4' in file_urls[i]:
|
| 23 |
+
print('enter the image data')
|
|
|
|
|
|
|
|
|
|
| 24 |
else:
|
| 25 |
download_file(
|
| 26 |
file_urls[i],
|
|
|
|
| 29 |
|
| 30 |
model = YOLO('best.pt')
|
| 31 |
path = [['image_0.jpg'], ['image_1.jpg']]
|
|
|
|
| 32 |
|
| 33 |
def show_preds_image(image_path):
|
| 34 |
image = cv2.imread(image_path)
|
|
|
|
| 59 |
examples=path,
|
| 60 |
cache_examples=False,
|
| 61 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
gr.TabbedInterface(
|
| 63 |
+
[interface_image],
|
| 64 |
+
tab_names=['Image inference']
|
| 65 |
).queue().launch()
|