Spaces:
Sleeping
Sleeping
Daniel Feng Claude Opus 4.7 (1M context) commited on
Commit ·
7adbe42
1
Parent(s): e0fcc82
Pull LFS checkpoints unconditionally on boot
Browse filesThe previous setup only ran `git lfs pull` when torch wasn't already
installed. On HF Spaces where torch is baked into the base image, the
checkpoint files remained as 132-byte LFS pointers, causing YOLO to
crash with `UnpicklingError: invalid load key, 'v'` after cropping.
Also guards handle_box_select against None input from cleared annotator.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
app.py
CHANGED
|
@@ -9,7 +9,14 @@ def run(cmd, cwd=None):
|
|
| 9 |
subprocess.check_call(cmd, shell=True, cwd=cwd)
|
| 10 |
|
| 11 |
def setup_deps():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
print(f"mouse_yolo.pt size: {os.path.getsize('checkpoints/mouse_yolo.pt')} bytes")
|
|
|
|
| 13 |
# Use a flag to prevent infinite restarts
|
| 14 |
if os.environ.get("HF_SPACE_BOOTSTRAPPED") == "1":
|
| 15 |
return
|
|
@@ -28,7 +35,6 @@ def setup_deps():
|
|
| 28 |
run("pip install torch==2.6.0 torchvision==0.21.0 torchaudio==2.6.0 --index-url https://download.pytorch.org/whl/cpu")
|
| 29 |
run("pip install -e .", cwd="segment-anything-2")
|
| 30 |
run("pip install gradio opencv-python-headless ultralytics matplotlib")
|
| 31 |
-
run("git lfs install && git lfs pull", cwd=".") # assuming checkpoints/mouse_yolo.pt is tracked
|
| 32 |
|
| 33 |
# Relaunch the script with an env flag to avoid looping
|
| 34 |
print("♻️ Restarting app to apply changes...")
|
|
@@ -152,7 +158,7 @@ def load_frame(video_file, frame_idx):
|
|
| 152 |
|
| 153 |
def handle_box_select(data):
|
| 154 |
global selected_box
|
| 155 |
-
boxes = data.get("boxes", [])
|
| 156 |
if boxes:
|
| 157 |
selected_box = boxes[0]
|
| 158 |
return gr.update(interactive=True)
|
|
|
|
| 9 |
subprocess.check_call(cmd, shell=True, cwd=cwd)
|
| 10 |
|
| 11 |
def setup_deps():
|
| 12 |
+
# Pull LFS content if the weights are still pointer files (a pointer is ~130 B;
|
| 13 |
+
# the real mouse_yolo.pt is ~6 MB). This must run regardless of whether torch
|
| 14 |
+
# is already installed, because HF base images ship with torch and would otherwise
|
| 15 |
+
# skip the pull below.
|
| 16 |
+
if os.path.getsize("checkpoints/mouse_yolo.pt") < 10_000:
|
| 17 |
+
run("git lfs install && git lfs pull", cwd=".")
|
| 18 |
print(f"mouse_yolo.pt size: {os.path.getsize('checkpoints/mouse_yolo.pt')} bytes")
|
| 19 |
+
|
| 20 |
# Use a flag to prevent infinite restarts
|
| 21 |
if os.environ.get("HF_SPACE_BOOTSTRAPPED") == "1":
|
| 22 |
return
|
|
|
|
| 35 |
run("pip install torch==2.6.0 torchvision==0.21.0 torchaudio==2.6.0 --index-url https://download.pytorch.org/whl/cpu")
|
| 36 |
run("pip install -e .", cwd="segment-anything-2")
|
| 37 |
run("pip install gradio opencv-python-headless ultralytics matplotlib")
|
|
|
|
| 38 |
|
| 39 |
# Relaunch the script with an env flag to avoid looping
|
| 40 |
print("♻️ Restarting app to apply changes...")
|
|
|
|
| 158 |
|
| 159 |
def handle_box_select(data):
|
| 160 |
global selected_box
|
| 161 |
+
boxes = (data or {}).get("boxes", [])
|
| 162 |
if boxes:
|
| 163 |
selected_box = boxes[0]
|
| 164 |
return gr.update(interactive=True)
|