Ramendra commited on
Commit
7d42c9f
·
verified ·
1 Parent(s): e0a255e

replaced with new model -bestn.pt

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