Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -3,20 +3,20 @@ from ultralyticsplus import YOLO, render_result
|
|
3 |
import cv2
|
4 |
import torch
|
5 |
|
6 |
-
#
|
7 |
-
print(f"
|
|
|
8 |
|
9 |
-
# Load model with
|
10 |
def load_model():
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
raise RuntimeError("Error loading model. Please check the requirements versions.") from e
|
20 |
|
21 |
model = load_model()
|
22 |
|
@@ -25,8 +25,8 @@ def detect_leaves(image):
|
|
25 |
image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
|
26 |
cv2.imwrite('temp_image.jpg', image)
|
27 |
|
28 |
-
#
|
29 |
-
results = model.predict('temp_image.jpg')
|
30 |
|
31 |
# Process results
|
32 |
num_leaves = len(results[0].boxes)
|
@@ -34,23 +34,17 @@ def detect_leaves(image):
|
|
34 |
|
35 |
return render, num_leaves
|
36 |
|
37 |
-
# Create
|
38 |
-
|
39 |
-
|
40 |
-
gr.
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
submit_btn = gr.Button("Analyze Image", variant="primary")
|
49 |
-
submit_btn.click(
|
50 |
-
fn=detect_leaves,
|
51 |
-
inputs=[input_image],
|
52 |
-
outputs=[output_image, leaf_count]
|
53 |
-
)
|
54 |
|
55 |
if __name__ == "__main__":
|
56 |
-
|
|
|
3 |
import cv2
|
4 |
import torch
|
5 |
|
6 |
+
# Check versions
|
7 |
+
print(f"Torch version: {torch.__version__}")
|
8 |
+
print(f"Ultralytics version: {YOLO.__version__}")
|
9 |
|
10 |
+
# Load model with safe serialization
|
11 |
def load_model():
|
12 |
+
model = YOLO('foduucom/plant-leaf-detection-and-classification')
|
13 |
+
model.overrides.update({
|
14 |
+
'conf': 0.25,
|
15 |
+
'iou': 0.45,
|
16 |
+
'agnostic_nms': False,
|
17 |
+
'max_det': 1000
|
18 |
+
})
|
19 |
+
return model
|
|
|
20 |
|
21 |
model = load_model()
|
22 |
|
|
|
25 |
image = cv2.cvtColor(image, cv2.COLOR_RGB2BGR)
|
26 |
cv2.imwrite('temp_image.jpg', image)
|
27 |
|
28 |
+
# Predict with numpy fix
|
29 |
+
results = model.predict(source='temp_image.jpg', imgsz=640)
|
30 |
|
31 |
# Process results
|
32 |
num_leaves = len(results[0].boxes)
|
|
|
34 |
|
35 |
return render, num_leaves
|
36 |
|
37 |
+
# Create simplified interface
|
38 |
+
interface = gr.Interface(
|
39 |
+
fn=detect_leaves,
|
40 |
+
inputs=gr.Image(label="Upload Plant Image"),
|
41 |
+
outputs=[
|
42 |
+
gr.Image(label="Detection Result"),
|
43 |
+
gr.Number(label="Leaves Count")
|
44 |
+
],
|
45 |
+
title="π Plant Leaf Detector",
|
46 |
+
description="Upload a plant image to detect and count leaves"
|
47 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
48 |
|
49 |
if __name__ == "__main__":
|
50 |
+
interface.launch(server_port=7860)
|