Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,21 +1,21 @@
|
|
1 |
import gradio as gr
|
2 |
import torch
|
3 |
-
from
|
4 |
-
# Allow safe globals for
|
5 |
-
torch.serialization.add_safe_globals([
|
|
|
6 |
from ultralyticsplus import YOLO
|
7 |
from PIL import Image
|
8 |
|
9 |
# Load your custom YOLOv8 leaf detection model.
|
10 |
-
# If this still causes issues, try using a supported model like 'yolov8n.pt'
|
11 |
model = YOLO('foduucom/plant-leaf-detection-and-classification')
|
12 |
|
13 |
def count_leaves(image):
|
14 |
-
#
|
15 |
image = Image.open(image).convert("RGB")
|
16 |
# Run inference
|
17 |
results = model.predict(image)
|
18 |
-
# Count
|
19 |
num_leaves = len(results[0].boxes)
|
20 |
return f"Number of leaves detected: {num_leaves}"
|
21 |
|
|
|
1 |
import gradio as gr
|
2 |
import torch
|
3 |
+
from torch.nn.modules.container import Sequential # import Sequential
|
4 |
+
# Allow safe globals for the Sequential class
|
5 |
+
torch.serialization.add_safe_globals([Sequential])
|
6 |
+
|
7 |
from ultralyticsplus import YOLO
|
8 |
from PIL import Image
|
9 |
|
10 |
# Load your custom YOLOv8 leaf detection model.
|
|
|
11 |
model = YOLO('foduucom/plant-leaf-detection-and-classification')
|
12 |
|
13 |
def count_leaves(image):
|
14 |
+
# Ensure the image is a PIL Image and convert to RGB
|
15 |
image = Image.open(image).convert("RGB")
|
16 |
# Run inference
|
17 |
results = model.predict(image)
|
18 |
+
# Count detected leaves
|
19 |
num_leaves = len(results[0].boxes)
|
20 |
return f"Number of leaves detected: {num_leaves}"
|
21 |
|