till-onethousand commited on
Commit
eb2f248
·
1 Parent(s): b626944
Files changed (1) hide show
  1. app.py +18 -3
app.py CHANGED
@@ -1,13 +1,28 @@
1
  import gradio as gr
 
2
 
3
- from ultralytics import ASSETS
4
 
5
  model = None
6
 
7
- # ./darknet detect cfg/yolov2.cfg yolov2.weights ~/OneDrive\ -\ One\ Thousand\ GmbH/3.jpg
8
  def predict_image(img, conf_threshold, iou_threshold, model_name):
9
  """Predicts objects in an image using a YOLOv8 model with adjustable confidence and IOU thresholds."""
10
- return img
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
 
12
 
13
  iface = gr.Interface(
 
1
  import gradio as gr
2
+ import PIL.Image as Image
3
 
4
+ from ultralytics import ASSETS, YOLO
5
 
6
  model = None
7
 
8
+
9
  def predict_image(img, conf_threshold, iou_threshold, model_name):
10
  """Predicts objects in an image using a YOLOv8 model with adjustable confidence and IOU thresholds."""
11
+ model = YOLO(model_name)
12
+ results = model.predict(
13
+ source=img,
14
+ conf=conf_threshold,
15
+ iou=iou_threshold,
16
+ show_labels=True,
17
+ show_conf=True,
18
+ imgsz=640,
19
+ )
20
+
21
+ for r in results:
22
+ im_array = r.plot()
23
+ im = Image.fromarray(im_array[..., ::-1])
24
+
25
+ return im
26
 
27
 
28
  iface = gr.Interface(