Dricz commited on
Commit
939d079
1 Parent(s): b59b1c1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -20
app.py CHANGED
@@ -8,34 +8,36 @@ import numpy as np
8
  model = YOLO('best (1).pt')
9
 
10
 
11
- def response(image):
12
- print(image)
13
- results = model(image)
14
- for i, r in enumerate(results):
15
 
16
- # Plot results image
17
- im_bgr = r.plot()
18
- im_rgb = im_bgr[..., ::-1] # Convert BGR to RGB
19
 
20
- # im_rgb = Image.fromarray(im_rgb)
21
 
22
- return im_rgb
23
 
24
- def yoloV8_func(image: gr.Image = None,
25
- image_size: gr.Slider = 640,
26
- conf_threshold: gr.Slider = 0.4,
27
- iou_threshold: gr.Slider = 0.50):
28
  model = YOLO('best (1).pt')
29
 
30
- results = model.predict(image,
31
- conf=conf_threshold,
32
- iou=iou_threshold,
33
- imgsz=image_size)
34
 
35
  box = results[0].boxes
36
 
37
- render = render_result(model=model, image=image, result=results[0], rect_th = 1, text_th = 1)
38
- return render
 
 
 
 
 
 
 
39
 
40
 
41
  inputs = [
@@ -71,5 +73,5 @@ title = "YOLOv8 Custom Object Detection by Uyen Nguyen"
71
  # Launch the Gradio interface in debug mode with queue enabled
72
  # yolo_app.launch()
73
 
74
- iface = gr.Interface(fn=yoloV8_func, inputs=inputs, outputs=outputs)
75
  iface.launch()
 
8
  model = YOLO('best (1).pt')
9
 
10
 
11
+ # def response(image):
12
+ # print(image)
13
+ # results = model(image)
14
+ # for i, r in enumerate(results):
15
 
16
+ # # Plot results image
17
+ # im_bgr = r.plot()
18
+ # im_rgb = im_bgr[..., ::-1] # Convert BGR to RGB
19
 
20
+ # # im_rgb = Image.fromarray(im_rgb)
21
 
22
+ # return im_rgb
23
 
24
+ def response2(image: gr.Image = None,image_size: gr.Slider = 640, conf_threshold: gr.Slider = 0.5, iou_threshold: gr.Slider = 0.6):
25
+
 
 
26
  model = YOLO('best (1).pt')
27
 
28
+ results = model.predict(image, conf=conf_threshold, iou=iou_threshold, imgsz=image_size)
 
 
 
29
 
30
  box = results[0].boxes
31
 
32
+ # render = render_result(model=model, image=image, result=results[0], rect_th = 1, text_th = 1
33
+ for i, r in enumerate(results):
34
+
35
+ # Plot results image
36
+ im_bgr = r.plot()
37
+ im_rgb = im_bgr[..., ::-1] # Convert BGR to RGB
38
+
39
+ # im_rgb = Image.fromarray(im_rgb)
40
+ return im_rgb
41
 
42
 
43
  inputs = [
 
73
  # Launch the Gradio interface in debug mode with queue enabled
74
  # yolo_app.launch()
75
 
76
+ iface = gr.Interface(fn=response2, inputs=inputs, outputs=outputs)
77
  iface.launch()