Update app.py
Browse files
app.py
CHANGED
|
@@ -3,22 +3,23 @@ from ultralytics import YOLO
|
|
| 3 |
from huggingface_hub import hf_hub_download
|
| 4 |
from PIL import Image
|
| 5 |
import torch
|
| 6 |
-
from torch.serialization import add_safe_globals
|
| 7 |
-
from ultralytics.nn.tasks import DetectionModel # Needed for safe loading
|
| 8 |
|
| 9 |
-
#
|
| 10 |
-
add_safe_globals({'DetectionModel': DetectionModel})
|
| 11 |
-
|
| 12 |
-
# ✅ Download model from Hugging Face Hub
|
| 13 |
model_path = hf_hub_download(repo_id="Safi029/ABD-model", filename="ABD.pt")
|
| 14 |
|
| 15 |
-
#
|
| 16 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
|
|
|
| 18 |
def detect_structure(image):
|
| 19 |
results = model(image)
|
| 20 |
return Image.fromarray(results[0].plot())
|
| 21 |
|
|
|
|
| 22 |
demo = gr.Interface(
|
| 23 |
fn=detect_structure,
|
| 24 |
inputs=gr.Image(type="pil"),
|
|
|
|
| 3 |
from huggingface_hub import hf_hub_download
|
| 4 |
from PIL import Image
|
| 5 |
import torch
|
|
|
|
|
|
|
| 6 |
|
| 7 |
+
# Download the model file from Hugging Face
|
|
|
|
|
|
|
|
|
|
| 8 |
model_path = hf_hub_download(repo_id="Safi029/ABD-model", filename="ABD.pt")
|
| 9 |
|
| 10 |
+
# Explicitly load with weights_only=False
|
| 11 |
+
ckpt = torch.load(model_path, map_location="cpu", weights_only=False)
|
| 12 |
+
|
| 13 |
+
# Now manually initialize YOLO model from checkpoint
|
| 14 |
+
model = YOLO()
|
| 15 |
+
model.model.load_state_dict(ckpt['model'].float().state_dict())
|
| 16 |
|
| 17 |
+
# Function to run detection
|
| 18 |
def detect_structure(image):
|
| 19 |
results = model(image)
|
| 20 |
return Image.fromarray(results[0].plot())
|
| 21 |
|
| 22 |
+
# Gradio interface
|
| 23 |
demo = gr.Interface(
|
| 24 |
fn=detect_structure,
|
| 25 |
inputs=gr.Image(type="pil"),
|