Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,41 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from ultralyticsplus import YOLO, render_result
|
4 |
+
|
5 |
+
def yoloFunc(image: gr.inputs.Image = None,
|
6 |
+
image_size: int = 640,
|
7 |
+
conf_threshold: float = 0.4,
|
8 |
+
iou_threshold: float = 0.5):
|
9 |
+
model_path = 'best.pt'
|
10 |
+
model = YOLO(model_path)
|
11 |
+
|
12 |
+
results = model.predict(image,
|
13 |
+
image_size=image_size,
|
14 |
+
conf_threshold=conf_threshold,
|
15 |
+
iou_threshold=iou_threshold
|
16 |
+
)
|
17 |
+
|
18 |
+
box = results[0].boxes
|
19 |
+
|
20 |
+
render = render_result(model=model, image=image, results=results[0])
|
21 |
+
return render
|
22 |
+
|
23 |
+
inputs = [
|
24 |
+
gr.inputs.Image(type='filepath', label="Input Image"),
|
25 |
+
gr.inputs.Slider(minimum=320, maximum=1024, default=640, step=32, label="Image Size"),
|
26 |
+
gr.inputs.Slider(minimum=0.1, maximum=1.0, default=0.4, steps=0.05, label="Confidence Threshold"),
|
27 |
+
gr.inputs.Slider(minimum=0.1, maximum=1.0, default=0.5, steps=0.05, label="IOU Threshold")
|
28 |
+
]
|
29 |
+
|
30 |
+
outputs = gr.outputs.Image(type='filepath', label="Output Image")
|
31 |
+
|
32 |
+
title = "Pothole Detection"
|
33 |
+
|
34 |
+
yolo_app = gr.Interface(
|
35 |
+
fn=yoloFunc,
|
36 |
+
inputs=inputs,
|
37 |
+
outputs=outputs,
|
38 |
+
title=title,
|
39 |
+
)
|
40 |
+
|
41 |
+
yolo_app.launch(debug=True, enable_queue=True)
|