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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -6
app.py CHANGED
@@ -1,21 +1,23 @@
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
 
 
1
  import gradio as gr
2
  import torch
3
+ from ultralytics.nn.tasks import DetectionModel
4
+ from torch.nn.modules.container import Sequential # Allow Sequential if needed
5
+
6
+ # Whitelist the globals to bypass the pickle error (only do this if you trust the model source!)
7
+ torch.serialization.add_safe_globals([DetectionModel, Sequential])
8
 
9
  from ultralyticsplus import YOLO
10
  from PIL import Image
11
 
12
+ # Load your custom YOLOv8 leaf detection model
13
  model = YOLO('foduucom/plant-leaf-detection-and-classification')
14
 
15
  def count_leaves(image):
16
+ # Convert image to a PIL Image and ensure it's in RGB
17
  image = Image.open(image).convert("RGB")
18
  # Run inference
19
  results = model.predict(image)
20
+ # Count the number of detected leaves
21
  num_leaves = len(results[0].boxes)
22
  return f"Number of leaves detected: {num_leaves}"
23