Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -4,7 +4,6 @@ from ultralytics import ASSETS, YOLO
|
|
4 |
|
5 |
model = YOLO("best.pt")
|
6 |
|
7 |
-
|
8 |
def predict_image(img, conf_threshold, iou_threshold):
|
9 |
results = model.predict(
|
10 |
source=img,
|
@@ -15,12 +14,17 @@ def predict_image(img, conf_threshold, iou_threshold):
|
|
15 |
imgsz=640,
|
16 |
)
|
17 |
|
|
|
|
|
|
|
|
|
|
|
18 |
for r in results:
|
19 |
im_array = r.plot()
|
20 |
im = Image.fromarray(im_array[..., ::-1])
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
|
25 |
iface = gr.Interface(
|
26 |
fn=predict_image,
|
@@ -29,11 +33,10 @@ iface = gr.Interface(
|
|
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 |
-
|
36 |
)
|
37 |
|
38 |
if __name__ == '__main__':
|
39 |
-
iface.launch()
|
|
|
4 |
|
5 |
model = YOLO("best.pt")
|
6 |
|
|
|
7 |
def predict_image(img, conf_threshold, iou_threshold):
|
8 |
results = model.predict(
|
9 |
source=img,
|
|
|
14 |
imgsz=640,
|
15 |
)
|
16 |
|
17 |
+
# Assuming 'results' has a property or method to get detected labels count
|
18 |
+
# If not directly available, you might need to parse the results accordingly
|
19 |
+
fruits_count = sum(1 for _ in results if _.label == "fruit") # Example, adjust based on actual results structure
|
20 |
+
|
21 |
+
# Only handling the last result for simplicity, adjust according to your needs
|
22 |
for r in results:
|
23 |
im_array = r.plot()
|
24 |
im = Image.fromarray(im_array[..., ::-1])
|
25 |
+
|
26 |
+
caption = f"Detected fruits: {fruits_count}" # Modify this line according to the actual object you're detecting
|
27 |
+
return im, caption
|
28 |
|
29 |
iface = gr.Interface(
|
30 |
fn=predict_image,
|
|
|
33 |
gr.Slider(minimum=0, maximum=1, value=0.25, label="Confidence threshold"),
|
34 |
gr.Slider(minimum=0, maximum=1, value=0.45, label="IoU threshold")
|
35 |
],
|
36 |
+
outputs=[gr.Image(type="pil", label="Result"), gr.Textbox(label="Caption")],
|
37 |
title="My Yield | 🌱",
|
38 |
description="Estimate the amount of plants per year",
|
|
|
39 |
)
|
40 |
|
41 |
if __name__ == '__main__':
|
42 |
+
iface.launch()
|