muskangoyal06 commited on
Commit
e1976f4
·
verified ·
1 Parent(s): a835c9c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -1,21 +1,21 @@
1
  import gradio as gr
2
  import torch
3
- from ultralytics.nn.tasks import DetectionModel
4
- # Allow safe globals for custom model loading (do this only if you trust the source)
5
- torch.serialization.add_safe_globals([DetectionModel])
 
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
- # Convert to a PIL Image (if not already)
15
  image = Image.open(image).convert("RGB")
16
  # Run inference
17
  results = model.predict(image)
18
- # Count the number of detected leaves
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