luxmorocco commited on
Commit
ee0e2d0
·
verified ·
1 Parent(s): 048ed47

Upload growth.py

Browse files
Files changed (1) hide show
  1. growth.py +43 -0
growth.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import PIL.Image as Image
2
+ import gradio as gr
3
+ from ultralytics import ASSETS, YOLO
4
+
5
+ model = YOLO("/home/jad-tounsi/Desktop/YAZ+/Yield/model_eval/weights/best.pt")
6
+
7
+
8
+ def predict_image(img, conf_threshold, iou_threshold):
9
+ results = model.predict(
10
+ source=img,
11
+ conf=conf_threshold,
12
+ iou=iou_threshold,
13
+ show_labels=True,
14
+ show_conf=True,
15
+ imgsz=640,
16
+ )
17
+
18
+ for r in results:
19
+ im_array = r.plot()
20
+ im = Image.fromarray(im_array[..., ::-1])
21
+
22
+ return im
23
+
24
+
25
+ iface = gr.Interface(
26
+ fn=predict_image,
27
+ inputs=[
28
+ gr.Image(type="pil", label="Upload Image"),
29
+ gr.Slider(minimum=0, maximum=1, value=0.25, label="Confidence threshold"),
30
+ gr.Slider(minimum=0, maximum=1, value=0.45, label="IoU threshold")
31
+ ],
32
+ outputs=gr.Image(type="pil", label="Result"),
33
+ title="My Yield | 🌱",
34
+ description="Estimate the amount of plants per year",
35
+ examples=[
36
+ [ASSETS / "/home/jad-tounsi/Desktop/YAZ+/YAZ+ GPT/pages/asssets/test.jpg", 0.25, 0.45],
37
+ [ASSETS / "/home/jad-tounsi/Desktop/YAZ+/YAZ+ GPT/pages/asssets/test2.jpg", 0.25, 0.45],
38
+ [ASSETS / "/home/jad-tounsi/Desktop/YAZ+/YAZ+ GPT/pages/asssets/test3.jpg", 0.25, 0.45]
39
+ ]
40
+ )
41
+
42
+ if __name__ == '__main__':
43
+ iface.launch()