lucid-hf commited on
Commit
7c35a94
·
verified ·
1 Parent(s): 9460c54

CI: deploy Docker/PDM Space

Browse files
services/app_service/deim_model.py CHANGED
@@ -24,7 +24,7 @@ def _parse_version(version_str: str) -> Tuple[int, ...]:
24
 
25
 
26
  class DeimHgnetV2MDrone(BaseModel):
27
- def __init__(self, device: str = "cuda", version: str = "v2"):
28
  self.device = device
29
  repo_root = Path(__file__).resolve().parents[1]
30
  default_rel = (
 
24
 
25
 
26
  class DeimHgnetV2MDrone(BaseModel):
27
+ def __init__(self, device: str, version: str = "v2"):
28
  self.device = device
29
  repo_root = Path(__file__).resolve().parents[1]
30
  default_rel = (
services/app_service/pages/bushland_beacon.py CHANGED
@@ -4,6 +4,7 @@ import time
4
  from pathlib import Path
5
 
6
  import streamlit as st
 
7
  from deim_model import DeimHgnetV2MDrone
8
  from PIL import Image
9
 
@@ -57,12 +58,12 @@ with st.sidebar:
57
  conf_thr = st.slider("Minimum confidence threshold", 0.05, 0.95, 0.50, 0.01)
58
 
59
 
60
- DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
61
 
62
- @st.cache_resource
63
- def load_model(device: str = DEVICE):
64
- return DeimHgnetV2MDrone(device=device)
65
 
 
 
 
66
 
67
 
68
  # =============== Detection helpers ===============
 
4
  from pathlib import Path
5
 
6
  import streamlit as st
7
+ import torch
8
  from deim_model import DeimHgnetV2MDrone
9
  from PIL import Image
10
 
 
58
  conf_thr = st.slider("Minimum confidence threshold", 0.05, 0.95, 0.50, 0.01)
59
 
60
 
61
+ DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
62
 
 
 
 
63
 
64
+ @st.cache_resource
65
+ def load_model(device: str = DEVICE):
66
+ return DeimHgnetV2MDrone(device=device)
67
 
68
 
69
  # =============== Detection helpers ===============
services/app_service/pages/lost_at_sea.py CHANGED
@@ -4,6 +4,7 @@ import time
4
  from pathlib import Path
5
 
6
  import streamlit as st
 
7
  from deim_model import DeimHgnetV2MDrone
8
  from PIL import Image
9
 
@@ -58,12 +59,12 @@ with st.sidebar:
58
  conf_thr = st.slider("Minimum confidence threshold", 0.05, 0.95, 0.50, 0.01)
59
 
60
 
61
- DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
62
 
63
- @st.cache_resource
64
- def load_model(device: str = DEVICE):
65
- return DeimHgnetV2MDrone(device=device)
66
 
 
 
 
67
 
68
 
69
  # =============== Detection helpers ===============
@@ -77,7 +78,7 @@ def run_image_detection(uploaded_file, conf_thr: float = 0.5):
77
  return
78
 
79
  try:
80
- model = load_model(device="cuda")
81
  with st.spinner("Running detection..."):
82
  annotated = model.predict_image(img, min_confidence=conf_thr)
83
 
 
4
  from pathlib import Path
5
 
6
  import streamlit as st
7
+ import torch
8
  from deim_model import DeimHgnetV2MDrone
9
  from PIL import Image
10
 
 
59
  conf_thr = st.slider("Minimum confidence threshold", 0.05, 0.95, 0.50, 0.01)
60
 
61
 
62
+ DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
63
 
 
 
 
64
 
65
+ @st.cache_resource
66
+ def load_model(device: str = DEVICE):
67
+ return DeimHgnetV2MDrone(device=device)
68
 
69
 
70
  # =============== Detection helpers ===============
 
78
  return
79
 
80
  try:
81
+ model = load_model()
82
  with st.spinner("Running detection..."):
83
  annotated = model.predict_image(img, min_confidence=conf_thr)
84
 
services/app_service/pages/signal_watch.py CHANGED
@@ -5,6 +5,7 @@ from pathlib import Path
5
  import cv2
6
  import numpy as np
7
  import streamlit as st
 
8
  from deim_model import DeimHgnetV2MDrone
9
  from PIL import Image
10
 
@@ -54,9 +55,11 @@ def _discover_model_entries() -> list[tuple[str, str]]:
54
 
55
  MODEL_ENTRIES = _discover_model_entries()
56
 
 
 
57
 
58
  @st.cache_resource
59
- def load_model(model_key: str, device: "cuda"):
60
  if model_key == "deim":
61
  return DeimHgnetV2MDrone(device=device)
62
  if not model_key.startswith("yolo:"):
@@ -196,7 +199,7 @@ def run_video_feed_detection(
196
  preview_max_width: int,
197
  ):
198
  try:
199
- model = load_model(model_key, device="cpu") # Use CPU for Hugging Face Spaces
200
  except Exception as exc:
201
  st.error(str(exc))
202
  return
 
5
  import cv2
6
  import numpy as np
7
  import streamlit as st
8
+ import torch
9
  from deim_model import DeimHgnetV2MDrone
10
  from PIL import Image
11
 
 
55
 
56
  MODEL_ENTRIES = _discover_model_entries()
57
 
58
+ DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
59
+
60
 
61
  @st.cache_resource
62
+ def load_model(model_key: str, device: str = DEVICE):
63
  if model_key == "deim":
64
  return DeimHgnetV2MDrone(device=device)
65
  if not model_key.startswith("yolo:"):
 
199
  preview_max_width: int,
200
  ):
201
  try:
202
+ model = load_model(model_key, device=DEVICE)
203
  except Exception as exc:
204
  st.error(str(exc))
205
  return