Spaces:
Sleeping
Sleeping
changed the gradio UI, increased the interactivity.
Browse files
app.py
CHANGED
@@ -2,21 +2,36 @@ import gradio as gr
|
|
2 |
|
3 |
from detection_pipeline import DetectionModel
|
4 |
|
5 |
-
|
|
|
|
|
6 |
|
7 |
def predict(image, threshold):
|
|
|
8 |
preds = model(image)
|
9 |
-
|
10 |
|
11 |
-
|
|
|
|
|
12 |
return output
|
13 |
|
14 |
|
|
|
|
|
|
|
|
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
inputs=[gr.Image(label="Input"), gr.Slider(0, 1, .3, step=.05, label="Threshold")],
|
19 |
-
outputs=gr.Image(label="Output")
|
20 |
-
)
|
21 |
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
from detection_pipeline import DetectionModel
|
4 |
|
5 |
+
if gr.NO_RELOAD:
|
6 |
+
model = DetectionModel()
|
7 |
+
preds = []
|
8 |
|
9 |
def predict(image, threshold):
|
10 |
+
global preds
|
11 |
preds = model(image)
|
12 |
+
return filter_preds(image, threshold)
|
13 |
|
14 |
+
def filter_preds(image, threshold):
|
15 |
+
preds_ = list(filter(lambda x: x[4] > threshold/100, preds))
|
16 |
+
output = model.visualize(image, preds_)
|
17 |
return output
|
18 |
|
19 |
|
20 |
+
with gr.Blocks() as interface:
|
21 |
+
with gr.Row():
|
22 |
+
with gr.Column():
|
23 |
+
image = gr.Image(label="Input")
|
24 |
|
25 |
+
with gr.Column():
|
26 |
+
output = gr.Image(label="Output")
|
|
|
|
|
|
|
27 |
|
28 |
+
with gr.Row():
|
29 |
+
with gr.Column():
|
30 |
+
threshold = gr.Slider(0, 100, 30, step=5, label="Threshold")
|
31 |
+
threshold.release(filter_preds, inputs=[image, threshold], outputs=output)
|
32 |
+
with gr.Column():
|
33 |
+
button = gr.Button(value="Detect")
|
34 |
+
button.click(predict, [image, threshold], output)
|
35 |
+
|
36 |
+
if __name__ == "__main__":
|
37 |
+
interface.launch()
|