Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,26 +1,31 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
import importlib
|
3 |
|
4 |
-
def
|
5 |
-
|
6 |
-
|
7 |
-
model_app.launch()
|
8 |
|
9 |
-
app = gr.
|
10 |
-
launch_model_app,
|
11 |
-
inputs=[
|
12 |
-
gr.inputs.Dropdown(
|
13 |
-
choices=[
|
14 |
-
("Model 1", "app_model_1"),
|
15 |
-
("Model 2", "app_model_2"),
|
16 |
-
("Model 3", "app_model_3")
|
17 |
-
],
|
18 |
-
label="Select Model"
|
19 |
-
)
|
20 |
-
],
|
21 |
-
outputs=None,
|
22 |
-
title="Choose Object Detection Model",
|
23 |
-
theme="compact"
|
24 |
-
)
|
25 |
|
26 |
-
app
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# app.py
|
2 |
import gradio as gr
|
3 |
import importlib
|
4 |
|
5 |
+
def load_model(model_name):
|
6 |
+
module = importlib.import_module(model_name)
|
7 |
+
return module
|
|
|
8 |
|
9 |
+
app = gr.Blocks()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
+
with app:
|
12 |
+
gr.Markdown("## Object Detection using TensorFlow Lite Models")
|
13 |
+
with gr.Row():
|
14 |
+
model_choice = gr.Dropdown(label="Select Model", choices=["model_1", "model_2", "model_3"])
|
15 |
+
image_input = gr.Image(type="pil", label="Upload an image")
|
16 |
+
image_output = gr.Image(type="pil", label="Detection Result")
|
17 |
+
video_input = gr.Video(label="Upload a video")
|
18 |
+
video_output = gr.Video(label="Detection Result")
|
19 |
+
|
20 |
+
def image_detection(model_name, input_image):
|
21 |
+
model = load_model(model_name)
|
22 |
+
return model.detect_image(input_image)
|
23 |
+
|
24 |
+
def video_detection(model_name, input_video):
|
25 |
+
model = load_model(model_name)
|
26 |
+
return model.detect_video(input_video)
|
27 |
+
|
28 |
+
gr.Button("Submit Image").click(fn=image_detection, inputs=[model_choice, image_input], outputs=image_output)
|
29 |
+
gr.Button("Submit Video").click(fn=video_detection, inputs=[model_choice, video_input], outputs=video_output)
|
30 |
+
|
31 |
+
app.launch()
|