Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -101,6 +101,34 @@ def detect_video(video):
|
|
101 |
# Release resources
|
102 |
cap.release()
|
103 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
104 |
label_id_offset = 0
|
105 |
REPO_ID = "apailang/mytfodmodel"
|
106 |
detection_model = load_model()
|
@@ -138,16 +166,26 @@ a = os.path.join(os.path.dirname(__file__), "data/a.mp4") # Video
|
|
138 |
b = os.path.join(os.path.dirname(__file__), "data/b.mp4") # Video
|
139 |
c = os.path.join(os.path.dirname(__file__), "data/c.mp4") # Video
|
140 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
141 |
stt_demo = gr.Interface(
|
142 |
-
fn=
|
143 |
-
inputs=
|
144 |
-
|
145 |
examples=[
|
146 |
[a],
|
147 |
[b],
|
148 |
[c],
|
149 |
],
|
150 |
-
cache_examples=
|
151 |
)
|
152 |
demo = gr.TabbedInterface([tts_demo, stt_demo], ["Image", "Video"])
|
153 |
|
|
|
101 |
# Release resources
|
102 |
cap.release()
|
103 |
|
104 |
+
|
105 |
+
def show_preds_video(video_path):
|
106 |
+
cap = cv2.VideoCapture(video_path)
|
107 |
+
while(cap.isOpened()):
|
108 |
+
ret, frame = cap.read()
|
109 |
+
if ret:
|
110 |
+
frame_copy = frame.copy()
|
111 |
+
outputs = detection_model.predict(source=frame)
|
112 |
+
results = outputs[0].cpu().numpy()
|
113 |
+
for i, det in enumerate(results.boxes.xyxy):
|
114 |
+
cv2.rectangle(
|
115 |
+
frame_copy,
|
116 |
+
(int(det[0]), int(det[1])),
|
117 |
+
(int(det[2]), int(det[3])),
|
118 |
+
color=(0, 0, 255),
|
119 |
+
thickness=2,
|
120 |
+
lineType=cv2.LINE_AA
|
121 |
+
)
|
122 |
+
yield cv2.cvtColor(frame_copy, cv2.COLOR_BGR2RGB)
|
123 |
+
|
124 |
+
inputs_video = [
|
125 |
+
gr.components.Video(type="filepath", label="Input Video"),
|
126 |
+
|
127 |
+
]
|
128 |
+
outputs_video = [
|
129 |
+
gr.components.Image(type="numpy", label="Output Image"),
|
130 |
+
]
|
131 |
+
|
132 |
label_id_offset = 0
|
133 |
REPO_ID = "apailang/mytfodmodel"
|
134 |
detection_model = load_model()
|
|
|
166 |
b = os.path.join(os.path.dirname(__file__), "data/b.mp4") # Video
|
167 |
c = os.path.join(os.path.dirname(__file__), "data/c.mp4") # Video
|
168 |
|
169 |
+
|
170 |
+
# interface_video = gr.Interface(
|
171 |
+
# fn=show_preds_video,
|
172 |
+
# inputs=inputs_video,
|
173 |
+
# outputs=outputs_video,
|
174 |
+
# title="Pothole detector",
|
175 |
+
# examples=video_path,
|
176 |
+
# cache_examples=False,
|
177 |
+
# )
|
178 |
+
|
179 |
stt_demo = gr.Interface(
|
180 |
+
fn=show_preds_video,
|
181 |
+
inputs=inputs_video,
|
182 |
+
outputs=outputs_video,
|
183 |
examples=[
|
184 |
[a],
|
185 |
[b],
|
186 |
[c],
|
187 |
],
|
188 |
+
cache_examples=False
|
189 |
)
|
190 |
demo = gr.TabbedInterface([tts_demo, stt_demo], ["Image", "Video"])
|
191 |
|