Spaces:
Sleeping
Sleeping
ranggaaldosas
commited on
Commit
•
0783c95
1
Parent(s):
f5759c2
Update app.py
Browse files
app.py
CHANGED
@@ -58,24 +58,39 @@ interface_image = gr.Interface(
|
|
58 |
|
59 |
|
60 |
# For video processing, it's best to process and then show the output video.
|
61 |
-
# This is a simplified placeholder for video processing, indicating where to include the video processing logic.
|
62 |
def show_preds_video(video_path):
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
|
68 |
-
|
69 |
-
# Define the Gradio interface for video input
|
70 |
interface_video = gr.Interface(
|
71 |
fn=show_preds_video,
|
72 |
-
inputs=
|
73 |
-
outputs=
|
74 |
-
title="Pothole Detector
|
75 |
examples=example_vids,
|
76 |
cache_examples=False,
|
77 |
)
|
78 |
-
|
79 |
# Combine the interfaces into a tabbed interface
|
80 |
gr.TabbedInterface(
|
81 |
[interface_image, interface_video], tab_names=["Image Inference", "Video Inference"]
|
|
|
58 |
|
59 |
|
60 |
# For video processing, it's best to process and then show the output video.
|
|
|
61 |
def show_preds_video(video_path):
|
62 |
+
cap = cv2.VideoCapture(video_path)
|
63 |
+
while(cap.isOpened()):
|
64 |
+
ret, frame = cap.read()
|
65 |
+
if ret:
|
66 |
+
frame_copy = frame.copy()
|
67 |
+
outputs = model.predict(source=frame)
|
68 |
+
results = outputs[0].cpu().numpy()
|
69 |
+
for det in results.boxes.xyxy:
|
70 |
+
cv2.rectangle(
|
71 |
+
frame_copy,
|
72 |
+
(int(det[0]), int(det[1])),
|
73 |
+
(int(det[2]), int(det[3])),
|
74 |
+
color=(0, 0, 255),
|
75 |
+
thickness=2,
|
76 |
+
lineType=cv2.LINE_AA
|
77 |
+
)
|
78 |
+
yield cv2.cvtColor(frame_copy, cv2.COLOR_BGR2RGB)
|
79 |
+
else:
|
80 |
+
break
|
81 |
+
cap.release()
|
82 |
+
|
83 |
+
inputs_video = gr.components.Video(label="Input Video")
|
84 |
+
outputs_video = gr.components.Image(label="Output Image", type="numpy")
|
85 |
|
|
|
|
|
86 |
interface_video = gr.Interface(
|
87 |
fn=show_preds_video,
|
88 |
+
inputs=inputs_video,
|
89 |
+
outputs=outputs_video,
|
90 |
+
title="Pothole Detector",
|
91 |
examples=example_vids,
|
92 |
cache_examples=False,
|
93 |
)
|
|
|
94 |
# Combine the interfaces into a tabbed interface
|
95 |
gr.TabbedInterface(
|
96 |
[interface_image, interface_video], tab_names=["Image Inference", "Video Inference"]
|