Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,32 +2,35 @@ import gradio as gr
|
|
| 2 |
import torch
|
| 3 |
from ultralytics import YOLO
|
| 4 |
|
| 5 |
-
# β
|
| 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
|
| 15 |
try:
|
| 16 |
model = YOLO("best.pt")
|
| 17 |
except Exception as e:
|
| 18 |
-
raise RuntimeError(f"Failed to load YOLOv8 model
|
| 19 |
|
| 20 |
-
#
|
| 21 |
def detect_objects(image):
|
| 22 |
results = model(image)
|
| 23 |
annotated_image = results[0].plot()
|
| 24 |
return annotated_image
|
| 25 |
|
| 26 |
-
# ποΈ Gradio
|
| 27 |
description = """
|
| 28 |
π **Panel Fault D C Detection App**
|
| 29 |
-
|
| 30 |
-
|
| 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 |
+
|