Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,16 +1,90 @@
|
|
1 |
import gradio as gr
|
2 |
-
import torch
|
3 |
from ultralytics import YOLO
|
4 |
|
5 |
-
#
|
6 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
|
8 |
-
# Define
|
9 |
-
def
|
10 |
-
|
11 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
-
# Create Gradio interface
|
14 |
-
image_input = gr.inputs.Image()
|
15 |
-
gr.Interface(predict_image, image_input, "image").launch()
|
16 |
|
|
|
1 |
import gradio as gr
|
|
|
2 |
from ultralytics import YOLO
|
3 |
|
4 |
+
# Define function to perform prediction with YOLOv9 model
|
5 |
+
def predict_image(image, model_path, image_size, conf_threshold, iou_threshold):
|
6 |
+
# Load YOLO model
|
7 |
+
model = YOLO(model_path)
|
8 |
+
|
9 |
+
# Perform inference with YOLO model
|
10 |
+
results = model(image, size=image_size, conf=conf_threshold, iou=iou_threshold)
|
11 |
+
|
12 |
+
# Render the output
|
13 |
+
output_image = results.render()
|
14 |
+
|
15 |
+
return output_image[0]
|
16 |
|
17 |
+
# Define Gradio interface
|
18 |
+
def app():
|
19 |
+
with gr.Blocks():
|
20 |
+
with gr.Row():
|
21 |
+
with gr.Column():
|
22 |
+
img_path = gr.Image(type="filepath", label="Image")
|
23 |
+
model_path = gr.Dropdown(
|
24 |
+
label="Model",
|
25 |
+
choices=[
|
26 |
+
"yolov9c-seg.pt",
|
27 |
+
"yolov5m.pt",
|
28 |
+
"yolov5l.pt",
|
29 |
+
"yolov5x.pt",
|
30 |
+
],
|
31 |
+
value="yolov5s.pt",
|
32 |
+
)
|
33 |
+
image_size = gr.Slider(
|
34 |
+
label="Image Size",
|
35 |
+
minimum=320,
|
36 |
+
maximum=1280,
|
37 |
+
step=32,
|
38 |
+
value=640,
|
39 |
+
)
|
40 |
+
conf_threshold = gr.Slider(
|
41 |
+
label="Confidence Threshold",
|
42 |
+
minimum=0.1,
|
43 |
+
maximum=1.0,
|
44 |
+
step=0.1,
|
45 |
+
value=0.4,
|
46 |
+
)
|
47 |
+
iou_threshold = gr.Slider(
|
48 |
+
label="IoU Threshold",
|
49 |
+
minimum=0.1,
|
50 |
+
maximum=1.0,
|
51 |
+
step=0.1,
|
52 |
+
value=0.5,
|
53 |
+
)
|
54 |
+
yolov9_infer = gr.Button(value="Submit")
|
55 |
+
|
56 |
+
with gr.Column():
|
57 |
+
output_numpy = gr.Image(type="numpy", label="Output")
|
58 |
+
|
59 |
+
yolov9_infer.click(
|
60 |
+
fn=predict_image,
|
61 |
+
inputs=[
|
62 |
+
img_path,
|
63 |
+
model_path,
|
64 |
+
image_size,
|
65 |
+
conf_threshold,
|
66 |
+
iou_threshold,
|
67 |
+
],
|
68 |
+
outputs=[output_numpy],
|
69 |
+
)
|
70 |
+
|
71 |
+
gradio_app = gr.Blocks()
|
72 |
+
with gradio_app:
|
73 |
+
gr.HTML(
|
74 |
+
"""
|
75 |
+
<h1 style='text-align: center'>
|
76 |
+
YOLOv9 Base Model
|
77 |
+
</h1>
|
78 |
+
""")
|
79 |
+
gr.HTML(
|
80 |
+
"""
|
81 |
+
<h3 style='text-align: center'>
|
82 |
+
</h3>
|
83 |
+
""")
|
84 |
+
with gr.Row():
|
85 |
+
with gr.Column():
|
86 |
+
app()
|
87 |
+
|
88 |
+
gradio_app.launch(debug=True)
|
89 |
|
|
|
|
|
|
|
90 |
|