Update app.py
Browse files
app.py
CHANGED
|
@@ -3,23 +3,24 @@ from ultralytics import YOLO
|
|
| 3 |
from huggingface_hub import hf_hub_download
|
| 4 |
from PIL import Image
|
| 5 |
import torch
|
|
|
|
| 6 |
|
| 7 |
-
#
|
| 8 |
-
|
|
|
|
| 9 |
|
| 10 |
-
#
|
| 11 |
-
|
| 12 |
|
| 13 |
-
#
|
| 14 |
-
model = YOLO()
|
| 15 |
-
model.model.load_state_dict(ckpt['model'].float().state_dict())
|
| 16 |
|
| 17 |
-
#
|
| 18 |
def detect_structure(image):
|
| 19 |
results = model(image)
|
| 20 |
return Image.fromarray(results[0].plot())
|
| 21 |
|
| 22 |
-
# Gradio
|
| 23 |
demo = gr.Interface(
|
| 24 |
fn=detect_structure,
|
| 25 |
inputs=gr.Image(type="pil"),
|
|
|
|
| 3 |
from huggingface_hub import hf_hub_download
|
| 4 |
from PIL import Image
|
| 5 |
import torch
|
| 6 |
+
import torch.serialization
|
| 7 |
|
| 8 |
+
# 🛡️ ALLOW custom classes in checkpoint (required for torch >=2.6)
|
| 9 |
+
from ultralytics.nn.tasks import DetectionModel
|
| 10 |
+
torch.serialization.add_safe_globals([DetectionModel])
|
| 11 |
|
| 12 |
+
# 📥 Download model from Hugging Face repo
|
| 13 |
+
model_path = hf_hub_download(repo_id="Safi029/ABD-model", filename="ABD.pt")
|
| 14 |
|
| 15 |
+
# ✅ Load full model (not weights only)
|
| 16 |
+
model = YOLO(model_path)
|
|
|
|
| 17 |
|
| 18 |
+
# 🔍 Detection function
|
| 19 |
def detect_structure(image):
|
| 20 |
results = model(image)
|
| 21 |
return Image.fromarray(results[0].plot())
|
| 22 |
|
| 23 |
+
# 🎛️ Gradio UI
|
| 24 |
demo = gr.Interface(
|
| 25 |
fn=detect_structure,
|
| 26 |
inputs=gr.Image(type="pil"),
|