Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,48 +1,20 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import torch
|
| 3 |
from ultralytics import YOLO
|
| 4 |
|
| 5 |
-
# ✅
|
| 6 |
-
|
| 7 |
-
import ultralytics.nn.modules.conv
|
| 8 |
-
import torch.nn.modules.container
|
| 9 |
-
import torch.nn.modules.conv
|
| 10 |
|
| 11 |
-
|
| 12 |
-
torch.serialization.add_safe_globals([
|
| 13 |
-
ultralytics.nn.tasks.DetectionModel,
|
| 14 |
-
ultralytics.nn.modules.conv.Conv,
|
| 15 |
-
torch.nn.modules.container.Sequential,
|
| 16 |
-
torch.nn.modules.conv.Conv2d,
|
| 17 |
-
])
|
| 18 |
-
|
| 19 |
-
# ✅ Load YOLOv8 model
|
| 20 |
-
try:
|
| 21 |
-
print("⚙️ Loading YOLOv8 model...")
|
| 22 |
-
model = YOLO("best.pt")
|
| 23 |
-
except Exception as e:
|
| 24 |
-
raise RuntimeError(f"❌ Failed to load YOLOv8 model:\n{e}")
|
| 25 |
-
|
| 26 |
-
# 🧠 Inference function
|
| 27 |
-
def detect_objects(image):
|
| 28 |
results = model(image)
|
| 29 |
-
|
| 30 |
-
return annotated_image
|
| 31 |
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
📉 **Panel Fault D C Detection**
|
| 35 |
-
Upload an image to detect panel faults using your custom-trained YOLOv8 model.
|
| 36 |
-
🔗 [View Dataset](https://universe.roboflow.com/naveen-kumar-9emxl/my-project-1-scnhw)
|
| 37 |
-
"""
|
| 38 |
-
|
| 39 |
-
demo = gr.Interface(
|
| 40 |
-
fn=detect_objects,
|
| 41 |
inputs=gr.Image(type="pil"),
|
| 42 |
-
outputs=gr.Image(type="pil"),
|
| 43 |
-
title="
|
| 44 |
-
description=
|
| 45 |
)
|
| 46 |
|
| 47 |
-
|
| 48 |
-
|
|
|
|
| 1 |
import gradio as gr
|
|
|
|
| 2 |
from ultralytics import YOLO
|
| 3 |
|
| 4 |
+
# ✅ Load model directly from local file (same folder as app.py)
|
| 5 |
+
model = YOLO("best.pt")
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
+
def predict(image):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
results = model(image)
|
| 9 |
+
return results[0].plot()
|
|
|
|
| 10 |
|
| 11 |
+
iface = gr.Interface(
|
| 12 |
+
fn=predict,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
inputs=gr.Image(type="pil"),
|
| 14 |
+
outputs=gr.Image(type="pil", label="Detected Objects"),
|
| 15 |
+
title="Roboflow YOLOv8 Detector",
|
| 16 |
+
description="Upload an image to detect objects using your YOLOv8 model trained with Roboflow."
|
| 17 |
)
|
| 18 |
|
| 19 |
+
iface.launch()
|
| 20 |
+
|