Spaces:
Runtime error
Runtime error
update application
Browse files
app.py
CHANGED
@@ -3,7 +3,6 @@ import numpy as np
|
|
3 |
import torch
|
4 |
import cv2
|
5 |
import os
|
6 |
-
from random import randint
|
7 |
from vision.ssd.mobilenetv1_ssd import create_mobilenetv1_ssd, create_mobilenetv1_ssd_predictor
|
8 |
|
9 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
@@ -44,6 +43,15 @@ def detection(image):
|
|
44 |
s = f"Found {len(probs)} objects"
|
45 |
return image, s
|
46 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
title = " AISeed AI Application Demo "
|
48 |
description = "# A Demo of Deep Learning for Object Detection"
|
49 |
example_list = [["examples/" + example] for example in os.listdir("examples")]
|
@@ -51,18 +59,35 @@ example_list = [["examples/" + example] for example in os.listdir("examples")]
|
|
51 |
with gr.Blocks() as demo:
|
52 |
demo.title = title
|
53 |
gr.Markdown(description)
|
54 |
-
with gr.
|
55 |
-
with gr.
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
if __name__ == "__main__":
|
68 |
demo.launch()
|
|
|
3 |
import torch
|
4 |
import cv2
|
5 |
import os
|
|
|
6 |
from vision.ssd.mobilenetv1_ssd import create_mobilenetv1_ssd, create_mobilenetv1_ssd_predictor
|
7 |
|
8 |
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
|
|
43 |
s = f"Found {len(probs)} objects"
|
44 |
return image, s
|
45 |
|
46 |
+
def video_detection(frames):
|
47 |
+
out = cv2.VideoWriter('outpy.avi',cv2.VideoWriter_fourcc('M','J','P','G'), 30, (640, 320))
|
48 |
+
for frame in frames:
|
49 |
+
out.write(frame)
|
50 |
+
|
51 |
+
out.release()
|
52 |
+
return "outpy.avi"
|
53 |
+
|
54 |
+
|
55 |
title = " AISeed AI Application Demo "
|
56 |
description = "# A Demo of Deep Learning for Object Detection"
|
57 |
example_list = [["examples/" + example] for example in os.listdir("examples")]
|
|
|
59 |
with gr.Blocks() as demo:
|
60 |
demo.title = title
|
61 |
gr.Markdown(description)
|
62 |
+
with gr.Tabs():
|
63 |
+
with gr.TabItem("for Images"):
|
64 |
+
with gr.Row():
|
65 |
+
with gr.Column():
|
66 |
+
im = gr.Image(label="Input Image")
|
67 |
+
im_2 = gr.Image(label="Output Image")
|
68 |
+
with gr.Column():
|
69 |
+
text = gr.Textbox(label="Number of objects")
|
70 |
+
btn1 = gr.Button(value="Who wears mask?")
|
71 |
+
btn1.click(detection, inputs=[im], outputs=[im_2, text])
|
72 |
+
|
73 |
+
gr.Examples(examples=example_list,
|
74 |
+
inputs=[im],
|
75 |
+
outputs=[im_2])
|
76 |
+
# with gr.TabItem("for Videos"):
|
77 |
+
# with gr.Row():
|
78 |
+
# with gr.Column():
|
79 |
+
# text1 = gr.Textbox(label="Number of objects")
|
80 |
+
# with gr.Column():
|
81 |
+
# text2 = gr.Textbox(label="Number of objects")
|
82 |
+
|
83 |
+
with gr.Tab("for streaming"):
|
84 |
+
with gr.Row():
|
85 |
+
with gr.Column():
|
86 |
+
input_video = gr.Video(source="webcam", label="Input")
|
87 |
+
btn3 = gr.Button(value="Who wears mask?")
|
88 |
+
output_video = gr.Video(label="Output Video")
|
89 |
+
btn3.click(video_detection, inputs=[input_video], outputs=[output_video])
|
90 |
+
|
91 |
+
|
92 |
if __name__ == "__main__":
|
93 |
demo.launch()
|