Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -48,10 +48,10 @@ def load_model2():
|
|
48 |
threshold = 0.50
|
49 |
|
50 |
def predict(pilimg,video_in_filepath,threshold):
|
51 |
-
|
52 |
image_np = pil_image_as_numpy_array(pilimg)
|
53 |
-
|
54 |
-
|
55 |
video_reader = cv2.VideoCapture(video_in_filepath)
|
56 |
|
57 |
nb_frames = int(video_reader.get(cv2.CAP_PROP_FRAME_COUNT))
|
@@ -59,10 +59,9 @@ def predict(pilimg,video_in_filepath,threshold):
|
|
59 |
frame_w = int(video_reader.get(cv2.CAP_PROP_FRAME_WIDTH))
|
60 |
fps = video_reader.get(cv2.CAP_PROP_FPS)
|
61 |
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
video_out_filepath = None
|
66 |
video_writer = cv2.VideoWriter(video_out_filepath,
|
67 |
cv2.VideoWriter_fourcc(*'mp4v'),
|
68 |
fps,
|
@@ -91,8 +90,8 @@ def predict(pilimg,video_in_filepath,threshold):
|
|
91 |
video_writer.release()
|
92 |
cv2.destroyAllWindows()
|
93 |
cv2.waitKey(1)
|
94 |
-
|
95 |
-
|
96 |
|
97 |
|
98 |
def predict2(image_np,threshold):
|
@@ -179,7 +178,7 @@ gr.Interface(fn=predict,
|
|
179 |
title="Facemask & Glasses",
|
180 |
description="Model: ssd_mobilenet_v2_320x320",
|
181 |
theme=gr.themes.Soft(primary_hue="blue", secondary_hue="sky"),
|
182 |
-
cache_examples = True,
|
183 |
examples=[["test_samples/image489.png",None,0.55], ["test_samples/image825.png",None,0.55], ["test_samples/image833.png",None,0.55], ["test_samples/image846.png",None,0.55], [None,"test_samples/test_video.mp4",0.55]]
|
184 |
).launch(share=True)
|
185 |
|
|
|
48 |
threshold = 0.50
|
49 |
|
50 |
def predict(pilimg,video_in_filepath,threshold):
|
51 |
+
if pilimg:
|
52 |
image_np = pil_image_as_numpy_array(pilimg)
|
53 |
+
return predict2(image_np,threshold),None
|
54 |
+
else:
|
55 |
video_reader = cv2.VideoCapture(video_in_filepath)
|
56 |
|
57 |
nb_frames = int(video_reader.get(cv2.CAP_PROP_FRAME_COUNT))
|
|
|
59 |
frame_w = int(video_reader.get(cv2.CAP_PROP_FRAME_WIDTH))
|
60 |
fps = video_reader.get(cv2.CAP_PROP_FPS)
|
61 |
|
62 |
+
|
63 |
+
video_out_filepath = 'detected.mp4'
|
64 |
+
|
|
|
65 |
video_writer = cv2.VideoWriter(video_out_filepath,
|
66 |
cv2.VideoWriter_fourcc(*'mp4v'),
|
67 |
fps,
|
|
|
90 |
video_writer.release()
|
91 |
cv2.destroyAllWindows()
|
92 |
cv2.waitKey(1)
|
93 |
+
return None,video_out_filepath
|
94 |
+
|
95 |
|
96 |
|
97 |
def predict2(image_np,threshold):
|
|
|
178 |
title="Facemask & Glasses",
|
179 |
description="Model: ssd_mobilenet_v2_320x320",
|
180 |
theme=gr.themes.Soft(primary_hue="blue", secondary_hue="sky"),
|
181 |
+
#cache_examples = True,
|
182 |
examples=[["test_samples/image489.png",None,0.55], ["test_samples/image825.png",None,0.55], ["test_samples/image833.png",None,0.55], ["test_samples/image846.png",None,0.55], [None,"test_samples/test_video.mp4",0.55]]
|
183 |
).launch(share=True)
|
184 |
|