Spaces:
Build error
Build error
Commit
·
3906f18
1
Parent(s):
6feb524
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,13 +1,16 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import cv2
|
| 3 |
-
import requests
|
| 4 |
-
import os
|
| 5 |
from ultralytics import YOLO
|
| 6 |
|
| 7 |
model = YOLO('best.pt')
|
| 8 |
-
|
| 9 |
-
def show_preds(video_path):
|
| 10 |
cap = cv2.VideoCapture(video_path)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
while True:
|
| 12 |
ret, frame = cap.read()
|
| 13 |
if ret:
|
|
@@ -23,24 +26,25 @@ def show_preds(video_path):
|
|
| 23 |
thickness=2,
|
| 24 |
lineType=cv2.LINE_AA
|
| 25 |
)
|
|
|
|
| 26 |
yield cv2.cvtColor(frame_copy, cv2.COLOR_BGR2RGB)
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
input_video = [
|
| 29 |
-
gr.
|
| 30 |
]
|
| 31 |
-
|
| 32 |
-
gr.
|
| 33 |
]
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
|
|
|
| 38 |
title='Pothole Detection',
|
| 39 |
-
|
| 40 |
-
cache_examples=False,
|
| 41 |
)
|
| 42 |
|
| 43 |
-
|
| 44 |
-
[interface_video],
|
| 45 |
-
tab_names=['Video Inference']
|
| 46 |
-
).queue().launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import cv2
|
|
|
|
|
|
|
| 3 |
from ultralytics import YOLO
|
| 4 |
|
| 5 |
model = YOLO('best.pt')
|
| 6 |
+
|
| 7 |
+
def show_preds(video_path, output_path):
|
| 8 |
cap = cv2.VideoCapture(video_path)
|
| 9 |
+
width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
|
| 10 |
+
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
|
| 11 |
+
fps = cap.get(cv2.CAP_PROP_FPS)
|
| 12 |
+
fourcc = cv2.VideoWriter_fourcc(*'h264')
|
| 13 |
+
writer = cv2.VideoWriter(output_path, fourcc, fps, (width, height))
|
| 14 |
while True:
|
| 15 |
ret, frame = cap.read()
|
| 16 |
if ret:
|
|
|
|
| 26 |
thickness=2,
|
| 27 |
lineType=cv2.LINE_AA
|
| 28 |
)
|
| 29 |
+
writer.write(frame_copy)
|
| 30 |
yield cv2.cvtColor(frame_copy, cv2.COLOR_BGR2RGB)
|
| 31 |
+
else:
|
| 32 |
+
break
|
| 33 |
+
writer.release()
|
| 34 |
|
| 35 |
input_video = [
|
| 36 |
+
gr.inputs.Video(type='file', label='Input Video'),
|
| 37 |
]
|
| 38 |
+
output_video = [
|
| 39 |
+
gr.outputs.Video(type='file', label='Output Video'),
|
| 40 |
]
|
| 41 |
+
|
| 42 |
+
interface = gr.Interface(
|
| 43 |
+
show_preds,
|
| 44 |
+
inputs=input_video, # type: ignore
|
| 45 |
+
outputs=output_video, # type: ignore
|
| 46 |
title='Pothole Detection',
|
| 47 |
+
description='Potholes Detection using YOLOv8',
|
|
|
|
| 48 |
)
|
| 49 |
|
| 50 |
+
interface.queue().launch()
|
|
|
|
|
|
|
|
|