lokesh341 commited on
Commit
b093573
·
verified ·
1 Parent(s): 76f83d0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -9
app.py CHANGED
@@ -1,20 +1,14 @@
1
  import gradio as gr
2
- from ultralytics import YOLO
3
  from PIL import Image, ImageDraw
4
  import io
5
  from fpdf import FPDF
6
  import tempfile
7
  import cv2
8
  import os
9
- import torch.serialization
10
  import numpy as np
11
  from urllib.request import urlretrieve
12
- from ultralytics.nn.modules import Conv, Bottleneck, SPPF, C2f, Detect
13
- from ultralytics.nn.tasks import DetectionModel
14
- from torch.nn.modules.container import Sequential
15
-
16
- # Allowlist all necessary YOLOv8 modules to avoid UnpicklingError
17
- torch.serialization.add_safe_globals([DetectionModel, Sequential, Conv, Bottleneck, SPPF, C2f, Detect])
18
 
19
  # Model path
20
  model_path = 'model/yolov8n.pt'
@@ -25,7 +19,7 @@ if not os.path.exists(model_path):
25
  url = 'https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8n.pt'
26
  urlretrieve(url, model_path)
27
 
28
- # Load the YOLOv8 model
29
  model = YOLO(model_path)
30
 
31
  def detect_empty_spots(img_width, img_height, bottle_bboxes, min_gap=50):
 
1
  import gradio as gr
 
2
  from PIL import Image, ImageDraw
3
  import io
4
  from fpdf import FPDF
5
  import tempfile
6
  import cv2
7
  import os
8
+ import torch
9
  import numpy as np
10
  from urllib.request import urlretrieve
11
+ from ultralytics.yolo.engine.model import YOLO
 
 
 
 
 
12
 
13
  # Model path
14
  model_path = 'model/yolov8n.pt'
 
19
  url = 'https://github.com/ultralytics/assets/releases/download/v0.0.0/yolov8n.pt'
20
  urlretrieve(url, model_path)
21
 
22
+ # Load the YOLOv8 model with weights_only=False internally handled by YOLO class
23
  model = YOLO(model_path)
24
 
25
  def detect_empty_spots(img_width, img_height, bottle_bboxes, min_gap=50):