mrrahul011 commited on
Commit
ec3a1be
·
verified ·
1 Parent(s): f236788

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +84 -0
app.py ADDED
@@ -0,0 +1,84 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import PIL.Image as Image
3
+
4
+ from ultralytics import ASSETS, YOLO
5
+
6
+ model_egg = YOLO("/content/drive/MyDrive/EPR_Detection/weights/egg_best.pt")
7
+ model_nest = YOLO("/content/drive/MyDrive/EPR_Detection/weights/nest_best.pt")
8
+
9
+ def predict_egg_image(img, conf_threshold, iou_threshold):
10
+ """Predicts objects in an image using a YOLO model with adjustable confidence and IOU thresholds."""
11
+ results = model_egg.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
+ def predict_nest_image(img, conf_threshold, iou_threshold):
28
+ """Predicts objects in an image using a YOLO model with adjustable confidence and IOU thresholds."""
29
+ results = model_nest.predict(
30
+ source=img,
31
+ conf=conf_threshold,
32
+ iou=iou_threshold,
33
+ show_labels=True,
34
+ show_conf=True,
35
+ imgsz=640,
36
+ )
37
+
38
+ for r in results:
39
+ im_array = r.plot()
40
+ im = Image.fromarray(im_array[..., ::-1])
41
+
42
+ return i
43
+
44
+ iface_egg = gr.Interface(
45
+ fn=predict_egg_image,
46
+ inputs=[
47
+ gr.Image(type="pil", label="Upload Image"),
48
+ gr.Slider(minimum=0, maximum=1, value=0.25, label="Confidence threshold"),
49
+ gr.Slider(minimum=0, maximum=1, value=0.45, label="IoU threshold"),
50
+ ],
51
+ outputs=gr.Image(type="pil", label="Result"),
52
+ title="EPR Egg Detection",
53
+ description="Upload images for egg detection inference.",
54
+ examples=[
55
+ ["/content/drive/MyDrive/EPR_Detection/Examples/Egg/egg1.jpg", 0.25, 0.45],
56
+ ["/content/drive/MyDrive/EPR_Detection/Examples/Egg/egg2.jpg", 0.25, 0.45],
57
+ ["/content/drive/MyDrive/EPR_Detection/Examples/Egg/egg3.jpg", 0.25, 0.45]
58
+ ],
59
+ )
60
+
61
+ iface_nest = gr.Interface(
62
+ fn=predict_nest_image,
63
+ inputs=[
64
+ gr.Image(type="pil", label="Upload Image"),
65
+ gr.Slider(minimum=0, maximum=1, value=0.25, label="Confidence threshold"),
66
+ gr.Slider(minimum=0, maximum=1, value=0.45, label="IoU threshold"),
67
+ ],
68
+ outputs=gr.Image(type="pil", label="Result"),
69
+ title="EPR Nest Detection",
70
+ description="Upload images for nest detection inference.",
71
+ examples=[
72
+ ["/content/drive/MyDrive/EPR_Detection/Examples/Nest/nest1.jpg", 0.25, 0.45],
73
+ ["/content/drive/MyDrive/EPR_Detection/Examples/Nest/nest2.jpg", 0.25, 0.45],
74
+ ["/content/drive/MyDrive/EPR_Detection/Examples/Nest/nest3.jpg", 0.25, 0.45]
75
+ ],
76
+ )
77
+
78
+ iface = gr.TabbedInterface(
79
+ [iface_egg, iface_nest],
80
+ ["EPR Egg", "EPR Nest"]
81
+ )
82
+
83
+ if __name__ == "__main__":
84
+ iface.launch()