ma4389 commited on
Commit
02a005d
·
verified ·
1 Parent(s): f042f49

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -6
app.py CHANGED
@@ -1,22 +1,21 @@
1
  import torch
2
  from ultralytics import YOLO
3
  from ultralytics.nn.tasks import DetectionModel
 
4
  import torch.nn as nn
5
  import gradio as gr
6
 
7
- # ✅ Whitelist required classes for PyTorch 2.6 safe loading
8
- torch.serialization.add_safe_globals([DetectionModel, nn.Sequential])
9
 
10
  # Load YOLOv8 model
11
- model = YOLO("best.pt")
12
 
13
  # Detection function
14
  def detect_fracture(image):
15
- # Run detection
16
  results = model.predict(source=image, save=False)
17
- annotated_img = results[0].plot() # Annotated image with bounding boxes
18
 
19
- # Extract labels & confidence scores
20
  detections = []
21
  for box in results[0].boxes:
22
  cls_id = int(box.cls[0])
 
1
  import torch
2
  from ultralytics import YOLO
3
  from ultralytics.nn.tasks import DetectionModel
4
+ from ultralytics.nn.modules.conv import Conv
5
  import torch.nn as nn
6
  import gradio as gr
7
 
8
+ # ✅ Whitelist all necessary classes for PyTorch 2.6 safe loading
9
+ torch.serialization.add_safe_globals([DetectionModel, nn.Sequential, Conv])
10
 
11
  # Load YOLOv8 model
12
+ model = YOLO("best (1).pt") # Change to your model file path
13
 
14
  # Detection function
15
  def detect_fracture(image):
 
16
  results = model.predict(source=image, save=False)
17
+ annotated_img = results[0].plot()
18
 
 
19
  detections = []
20
  for box in results[0].boxes:
21
  cls_id = int(box.cls[0])