"""Resolve Git LFS pointers left by HF Docker builds.""" import os import subprocess import sys SPACE_ID = os.environ.get("SPACE_ID", "FocusGuard/final_v2") LFS_FILES = [ "checkpoints/scaler_mlp.joblib", "checkpoints/hybrid_combiner.joblib", "checkpoints/meta_best.npz", "checkpoints/meta_mlp.npz", ] def _is_lfs_pointer(path): if not os.path.isfile(path): return True with open(path, "rb") as f: return f.read(50).startswith(b"version https://git-lfs") def resolve(): try: from huggingface_hub import hf_hub_download except ImportError: subprocess.check_call([sys.executable, "-m", "pip", "install", "-q", "huggingface_hub"]) from huggingface_hub import hf_hub_download for rel in LFS_FILES: if not _is_lfs_pointer(rel): print(f"[OK] {rel} ({os.path.getsize(rel)} bytes)") continue print(f"[LFS] Downloading {rel} ...") try: local = hf_hub_download( repo_id=SPACE_ID, filename=rel, repo_type="space", local_dir=".", local_dir_use_symlinks=False, ) print(f" -> {os.path.getsize(rel)} bytes") except Exception as e: print(f" WARN: {e}") print("LFS resolution done.") if __name__ == "__main__": resolve()