Spaces:
Sleeping
Sleeping
k22056537 commited on
Commit ·
44572a8
1
Parent(s): 6dcb046
fix: use huggingface_hub to resolve LFS pointers at runtime
Browse filesurllib can't follow HF's Xet CDN redirects for LFS files.
Switched to hf_hub_download which handles auth and storage
backends properly.
- requirements.txt +1 -0
- resolve_lfs.py +20 -10
requirements.txt
CHANGED
|
@@ -22,3 +22,4 @@ pytest>=9.0.0
|
|
| 22 |
pytest-cov>=5.0.0
|
| 23 |
face_detection @ git+https://github.com/elliottzheng/face-detection
|
| 24 |
gdown>=5.0.0
|
|
|
|
|
|
| 22 |
pytest-cov>=5.0.0
|
| 23 |
face_detection @ git+https://github.com/elliottzheng/face-detection
|
| 24 |
gdown>=5.0.0
|
| 25 |
+
huggingface_hub
|
resolve_lfs.py
CHANGED
|
@@ -1,11 +1,12 @@
|
|
| 1 |
"""Resolve Git LFS pointers left by HF Docker builds."""
|
| 2 |
import os
|
| 3 |
-
import
|
|
|
|
| 4 |
|
| 5 |
-
SPACE = os.environ.get("SPACE_ID", "FocusGuard/final")
|
| 6 |
-
BASE = f"https://huggingface.co/spaces/{SPACE}/resolve/main"
|
| 7 |
|
| 8 |
-
|
|
|
|
|
|
|
| 9 |
"checkpoints/scaler_mlp.joblib",
|
| 10 |
"checkpoints/hybrid_combiner.joblib",
|
| 11 |
"checkpoints/meta_best.npz",
|
|
@@ -21,16 +22,25 @@ def _is_lfs_pointer(path):
|
|
| 21 |
|
| 22 |
|
| 23 |
def resolve():
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
if not _is_lfs_pointer(rel):
|
| 26 |
-
|
| 27 |
-
print(f"[OK] {rel} ({sz} bytes)")
|
| 28 |
continue
|
| 29 |
-
url = f"{BASE}/{rel}"
|
| 30 |
print(f"[LFS] Downloading {rel} ...")
|
| 31 |
try:
|
| 32 |
-
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
print(f" -> {os.path.getsize(rel)} bytes")
|
| 35 |
except Exception as e:
|
| 36 |
print(f" WARN: {e}")
|
|
|
|
| 1 |
"""Resolve Git LFS pointers left by HF Docker builds."""
|
| 2 |
import os
|
| 3 |
+
import subprocess
|
| 4 |
+
import sys
|
| 5 |
|
|
|
|
|
|
|
| 6 |
|
| 7 |
+
SPACE_ID = os.environ.get("SPACE_ID", "FocusGuard/final")
|
| 8 |
+
|
| 9 |
+
LFS_FILES = [
|
| 10 |
"checkpoints/scaler_mlp.joblib",
|
| 11 |
"checkpoints/hybrid_combiner.joblib",
|
| 12 |
"checkpoints/meta_best.npz",
|
|
|
|
| 22 |
|
| 23 |
|
| 24 |
def resolve():
|
| 25 |
+
try:
|
| 26 |
+
from huggingface_hub import hf_hub_download
|
| 27 |
+
except ImportError:
|
| 28 |
+
subprocess.check_call([sys.executable, "-m", "pip", "install", "-q", "huggingface_hub"])
|
| 29 |
+
from huggingface_hub import hf_hub_download
|
| 30 |
+
|
| 31 |
+
for rel in LFS_FILES:
|
| 32 |
if not _is_lfs_pointer(rel):
|
| 33 |
+
print(f"[OK] {rel} ({os.path.getsize(rel)} bytes)")
|
|
|
|
| 34 |
continue
|
|
|
|
| 35 |
print(f"[LFS] Downloading {rel} ...")
|
| 36 |
try:
|
| 37 |
+
local = hf_hub_download(
|
| 38 |
+
repo_id=SPACE_ID,
|
| 39 |
+
filename=rel,
|
| 40 |
+
repo_type="space",
|
| 41 |
+
local_dir=".",
|
| 42 |
+
local_dir_use_symlinks=False,
|
| 43 |
+
)
|
| 44 |
print(f" -> {os.path.getsize(rel)} bytes")
|
| 45 |
except Exception as e:
|
| 46 |
print(f" WARN: {e}")
|