3v324v23 commited on
Commit
2fdb608
·
1 Parent(s): 67f4ecf

Add model auto-download and troubleshooting instructions

Browse files
Files changed (2) hide show
  1. README.md +8 -0
  2. detector.py +11 -0
README.md CHANGED
@@ -9,6 +9,14 @@ app_file: app.py
9
  pinned: false
10
  ---
11
 
 
 
 
 
 
 
 
 
12
  # 🎥 MotionScope Pro — Movement Detector
13
 
14
  A professional Streamlit application combining **MediaPipe hand tracking** and **background subtraction motion detection**.
 
9
  pinned: false
10
  ---
11
 
12
+ # ⚠️ IMPORTANT SETUP STEP
13
+ **If you see "Welcome to your static Space"**:
14
+ 1. Go to the **Settings** tab above.
15
+ 2. Scroll to **Select Space SDK**.
16
+ 3. Change it from **Static** to **Docker**.
17
+ 4. Click **Update Space**.
18
+ The app will then build and start!
19
+
20
  # 🎥 MotionScope Pro — Movement Detector
21
 
22
  A professional Streamlit application combining **MediaPipe hand tracking** and **background subtraction motion detection**.
detector.py CHANGED
@@ -4,6 +4,7 @@ Combines MediaPipe HandLandmarker (tasks API) with background subtraction.
4
  """
5
 
6
  import os
 
7
  import cv2
8
  import numpy as np
9
  import mediapipe as mp
@@ -21,6 +22,15 @@ _RunningMode = mp.tasks.vision.RunningMode
21
  _MODEL_PATH = os.path.join(os.path.dirname(__file__), "hand_landmarker.task")
22
 
23
 
 
 
 
 
 
 
 
 
 
24
  class DetectionMode(Enum):
25
  """Available detection modes."""
26
  HAND_TRACKING = "Hand Tracking"
@@ -65,6 +75,7 @@ class MovementDetector:
65
  # ------------------------------------------------------------------
66
 
67
  def _build_hand_landmarker(self):
 
68
  options = _HandLandmarkerOptions(
69
  base_options=_BaseOptions(model_asset_path=_MODEL_PATH),
70
  running_mode=_RunningMode.IMAGE,
 
4
  """
5
 
6
  import os
7
+ import urllib.request
8
  import cv2
9
  import numpy as np
10
  import mediapipe as mp
 
22
  _MODEL_PATH = os.path.join(os.path.dirname(__file__), "hand_landmarker.task")
23
 
24
 
25
+ def _ensure_model_exists():
26
+ """Download the model if it doesn't exist locally."""
27
+ if not os.path.exists(_MODEL_PATH):
28
+ print(f"Downloading model to {_MODEL_PATH}...")
29
+ url = "https://storage.googleapis.com/mediapipe-models/hand_landmarker/hand_landmarker/float16/latest/hand_landmarker.task"
30
+ urllib.request.urlretrieve(url, _MODEL_PATH)
31
+
32
+
33
+
34
  class DetectionMode(Enum):
35
  """Available detection modes."""
36
  HAND_TRACKING = "Hand Tracking"
 
75
  # ------------------------------------------------------------------
76
 
77
  def _build_hand_landmarker(self):
78
+ _ensure_model_exists()
79
  options = _HandLandmarkerOptions(
80
  base_options=_BaseOptions(model_asset_path=_MODEL_PATH),
81
  running_mode=_RunningMode.IMAGE,