Spaces:
Sleeping
Sleeping
Daniel Feng Claude Opus 4.7 (1M context) commited on
Commit ·
d64269e
1
Parent(s): 7adbe42
Fetch LFS weights via HTTPS resolve URL instead of git-lfs
Browse files`git lfs pull` is unreliable on the HF Gradio SDK runtime (no .git dir
or no git-lfs binary), so checkpoint files stay as ~130 B pointers and
torch.load crashes with `invalid load key, 'v'`. Download the real
blobs directly from huggingface.co/.../resolve/main/... instead; the
redirect to the LFS CDN is followed automatically by urllib.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
app.py
CHANGED
|
@@ -8,13 +8,30 @@ def run(cmd, cwd=None):
|
|
| 8 |
print(f"▶ {cmd}")
|
| 9 |
subprocess.check_call(cmd, shell=True, cwd=cwd)
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
def setup_deps():
|
| 12 |
-
|
| 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
|
|
|
|
| 8 |
print(f"▶ {cmd}")
|
| 9 |
subprocess.check_call(cmd, shell=True, cwd=cwd)
|
| 10 |
|
| 11 |
+
LFS_BLOBS = {
|
| 12 |
+
"checkpoints/mouse_yolo.pt": "https://huggingface.co/spaces/Daniel-F/mouse-behavioral-study/resolve/main/checkpoints/mouse_yolo.pt",
|
| 13 |
+
"checkpoints/nose_detector.pth": "https://huggingface.co/spaces/Daniel-F/mouse-behavioral-study/resolve/main/checkpoints/nose_detector.pth",
|
| 14 |
+
"checkpoints/sam2_hiera_small.pt": "https://huggingface.co/spaces/Daniel-F/mouse-behavioral-study/resolve/main/checkpoints/sam2_hiera_small.pt",
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
def _fetch_lfs_blobs():
|
| 18 |
+
# The repo's .pt/.pth files are stored via Git LFS. On the HF Spaces runtime
|
| 19 |
+
# `git lfs pull` is unreliable (no .git dir and/or no git-lfs binary), so we
|
| 20 |
+
# download the resolved LFS blobs over HTTPS. A pointer file is ~130 B; real
|
| 21 |
+
# weights are multi-MB, so size < 10 KB means we still have the pointer.
|
| 22 |
+
import urllib.request
|
| 23 |
+
for path, url in LFS_BLOBS.items():
|
| 24 |
+
size = os.path.getsize(path) if os.path.exists(path) else 0
|
| 25 |
+
if size >= 10_000:
|
| 26 |
+
continue
|
| 27 |
+
print(f"⬇ fetching {path} from {url}")
|
| 28 |
+
tmp = path + ".part"
|
| 29 |
+
urllib.request.urlretrieve(url, tmp)
|
| 30 |
+
os.replace(tmp, path)
|
| 31 |
+
print(f" → {os.path.getsize(path)} bytes")
|
| 32 |
+
|
| 33 |
def setup_deps():
|
| 34 |
+
_fetch_lfs_blobs()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
print(f"mouse_yolo.pt size: {os.path.getsize('checkpoints/mouse_yolo.pt')} bytes")
|
| 36 |
|
| 37 |
# Use a flag to prevent infinite restarts
|