Update app.py
Browse files
app.py
CHANGED
|
@@ -5,23 +5,25 @@ from PIL import Image
|
|
| 5 |
import torch
|
| 6 |
import torch.serialization
|
| 7 |
|
| 8 |
-
# ✅ Add
|
| 9 |
from ultralytics.nn.tasks import DetectionModel
|
| 10 |
-
from torch.nn import Sequential, Conv2d
|
| 11 |
from ultralytics.nn.modules.conv import Conv
|
|
|
|
| 12 |
|
| 13 |
-
torch.serialization.add_safe_globals([
|
|
|
|
|
|
|
| 14 |
|
| 15 |
-
# 📥 Load model
|
| 16 |
model_path = hf_hub_download(repo_id="Safi029/ABD-model", filename="ABD.pt")
|
| 17 |
model = YOLO(model_path)
|
| 18 |
|
| 19 |
-
# 🧠
|
| 20 |
def detect_structure(image):
|
| 21 |
results = model(image)
|
| 22 |
return Image.fromarray(results[0].plot())
|
| 23 |
|
| 24 |
-
# 🎛️ Gradio
|
| 25 |
demo = gr.Interface(
|
| 26 |
fn=detect_structure,
|
| 27 |
inputs=gr.Image(type="pil"),
|
|
|
|
| 5 |
import torch
|
| 6 |
import torch.serialization
|
| 7 |
|
| 8 |
+
# ✅ Add required classes for safe unpickling
|
| 9 |
from ultralytics.nn.tasks import DetectionModel
|
|
|
|
| 10 |
from ultralytics.nn.modules.conv import Conv
|
| 11 |
+
from torch.nn import Sequential, Conv2d, BatchNorm2d
|
| 12 |
|
| 13 |
+
torch.serialization.add_safe_globals([
|
| 14 |
+
DetectionModel, Sequential, Conv, Conv2d, BatchNorm2d
|
| 15 |
+
])
|
| 16 |
|
| 17 |
+
# 📥 Load model from Hugging Face
|
| 18 |
model_path = hf_hub_download(repo_id="Safi029/ABD-model", filename="ABD.pt")
|
| 19 |
model = YOLO(model_path)
|
| 20 |
|
| 21 |
+
# 🧠 Define detection function
|
| 22 |
def detect_structure(image):
|
| 23 |
results = model(image)
|
| 24 |
return Image.fromarray(results[0].plot())
|
| 25 |
|
| 26 |
+
# 🎛️ Build Gradio interface
|
| 27 |
demo = gr.Interface(
|
| 28 |
fn=detect_structure,
|
| 29 |
inputs=gr.Image(type="pil"),
|