File size: 1,380 Bytes
f6f50c4
 
5af8588
 
f6f50c4
 
5af8588
 
 
f6f50c4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5af8588
 
 
 
 
 
 
f6f50c4
5af8588
f6f50c4
 
 
5af8588
 
 
 
 
 
 
f6f50c4
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
"""Resolve Git LFS pointers left by HF Docker builds."""
import os
import subprocess
import sys


SPACE_ID = os.environ.get("SPACE_ID", "FocusGuard/final")

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()