Sankie005 commited on
Commit
044c2de
·
verified ·
1 Parent(s): db6cb8c

Created App.py file

Browse files

added initial app file

Files changed (1) hide show
  1. app.py +41 -0
app.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import PIL.Image as Image
3
+ from ultralytics import ASSETS, YOLO
4
+ import cv2
5
+ model = YOLO("best.pt")
6
+
7
+
8
+ def predict_image(img, conf_threshold=0.25, iou_threshold=0.45):
9
+ """Predicts objects in an image using a YOLOv8 model with adjustable confidence and IOU thresholds."""
10
+ results = model.predict(
11
+ source=img,
12
+ conf=conf_threshold,
13
+ iou=iou_threshold,
14
+ show_labels=True,
15
+ show_conf=True,
16
+ )
17
+
18
+ for r in results:
19
+ im_array = r.plot()
20
+ im = Image.fromarray(im_array[..., ::-1])
21
+ return im
22
+
23
+
24
+ iface = gr.Interface(
25
+ fn=predict_image,
26
+ inputs=[
27
+ gr.Image(type="pil", label="Upload Image"),
28
+ gr.Slider(minimum=0, maximum=1, value=0.25, label="Confidence threshold"),
29
+ gr.Slider(minimum=0, maximum=1, value=0.45, label="IoU threshold"),
30
+ ],
31
+ outputs=gr.Image(type="pil", label="Result"),
32
+ title="Roadvis🛣️ Gradio!",
33
+ description="Upload images for inference.",
34
+ examples=[
35
+ ["Assets/pothole1.png", 0.25, 0.45],
36
+ ["Assets/pothole2.webp", 0.25, 0.45],
37
+ ],
38
+ )
39
+
40
+ if __name__ == "__main__":
41
+ iface.launch()