Nawinkumar15 commited on
Commit
164516a
Β·
verified Β·
1 Parent(s): ad6c417

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -8
app.py CHANGED
@@ -2,32 +2,35 @@ import gradio as gr
2
  import torch
3
  from ultralytics import YOLO
4
 
5
- # βœ… Allowlist required classes for safe loading
6
  import ultralytics.nn.tasks
 
7
  import torch.nn.modules.container
8
 
 
9
  torch.serialization.add_safe_globals([
10
  ultralytics.nn.tasks.DetectionModel,
11
- torch.nn.modules.container.Sequential
 
12
  ])
13
 
14
- # βœ… Load the YOLOv8 model (from trusted source like Roboflow)
15
  try:
16
  model = YOLO("best.pt")
17
  except Exception as e:
18
- raise RuntimeError(f"Failed to load YOLOv8 model: {e}")
19
 
20
- # πŸ” Inference function
21
  def detect_objects(image):
22
  results = model(image)
23
  annotated_image = results[0].plot()
24
  return annotated_image
25
 
26
- # πŸŽ›οΈ Gradio UI
27
  description = """
28
  πŸ“‰ **Panel Fault D C Detection App**
29
- Detect panel faults using a YOLOv8 model trained on Roboflow.
30
- πŸ”— [Dataset Link](https://universe.roboflow.com/naveen-kumar-9emxl/my-project-1-scnhw)
31
  """
32
 
33
  demo = gr.Interface(
@@ -40,3 +43,5 @@ demo = gr.Interface(
40
 
41
  if __name__ == "__main__":
42
  demo.launch()
 
 
 
2
  import torch
3
  from ultralytics import YOLO
4
 
5
+ # βœ… Import modules for unpickling
6
  import ultralytics.nn.tasks
7
+ import ultralytics.nn.modules.conv
8
  import torch.nn.modules.container
9
 
10
+ # 🧠 Add all required classes to the safe globals list
11
  torch.serialization.add_safe_globals([
12
  ultralytics.nn.tasks.DetectionModel,
13
+ torch.nn.modules.container.Sequential,
14
+ ultralytics.nn.modules.conv.Conv,
15
  ])
16
 
17
+ # βœ… Load YOLOv8 model
18
  try:
19
  model = YOLO("best.pt")
20
  except Exception as e:
21
+ raise RuntimeError(f"❌ Failed to load YOLOv8 model:\n{e}")
22
 
23
+ # 🧠 Prediction function
24
  def detect_objects(image):
25
  results = model(image)
26
  annotated_image = results[0].plot()
27
  return annotated_image
28
 
29
+ # πŸŽ›οΈ Gradio interface
30
  description = """
31
  πŸ“‰ **Panel Fault D C Detection App**
32
+ Upload an image to detect panel faults using your YOLOv8 model from Roboflow.
33
+ [Roboflow Dataset](https://universe.roboflow.com/naveen-kumar-9emxl/my-project-1-scnhw)
34
  """
35
 
36
  demo = gr.Interface(
 
43
 
44
  if __name__ == "__main__":
45
  demo.launch()
46
+
47
+