Spaces:
Sleeping
Sleeping
k22056537 commited on
Commit ·
d5c34f9
1
Parent(s): 765fbe6
fix: download LFS files from HF API during Docker build
Browse filesHF Docker builds copy LFS pointers, not real files. Added a build
step that detects pointer files and downloads the actual binaries
from the HF Hub resolve API.
- Dockerfile +35 -25
Dockerfile
CHANGED
|
@@ -11,11 +11,9 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
|
|
| 11 |
libglib2.0-0 libsm6 libxrender1 libxext6 libxcb1 libgl1 libgomp1 \
|
| 12 |
ffmpeg libavcodec-dev libavformat-dev libavutil-dev libswscale-dev \
|
| 13 |
libavdevice-dev libopus-dev libvpx-dev libsrtp2-dev \
|
| 14 |
-
build-essential nodejs npm
|
| 15 |
&& rm -rf /var/lib/apt/lists/*
|
| 16 |
|
| 17 |
-
RUN git lfs install
|
| 18 |
-
|
| 19 |
RUN pip install --no-cache-dir torch torchvision --index-url https://download.pytorch.org/whl/cpu
|
| 20 |
|
| 21 |
COPY requirements.txt ./
|
|
@@ -23,31 +21,43 @@ RUN pip install --no-cache-dir -r requirements.txt
|
|
| 23 |
|
| 24 |
COPY . .
|
| 25 |
|
| 26 |
-
#
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
git lfs pull 2>/dev/null || echo "git lfs pull skipped (no .git dir)"; \
|
| 30 |
-
fi
|
| 31 |
-
|
| 32 |
RUN python -c "\
|
| 33 |
-
import os, sys;\
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
];\
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
else:\
|
| 47 |
-
print(f'[OK] {
|
| 48 |
-
|
| 49 |
-
print('Checkpoint verification failed — models will not load'); sys.exit(1);\
|
| 50 |
-
print('All checkpoints verified')\
|
| 51 |
"
|
| 52 |
|
| 53 |
RUN npm install && npm run build && mkdir -p /app/static && cp -R dist/* /app/static/
|
|
|
|
| 11 |
libglib2.0-0 libsm6 libxrender1 libxext6 libxcb1 libgl1 libgomp1 \
|
| 12 |
ffmpeg libavcodec-dev libavformat-dev libavutil-dev libswscale-dev \
|
| 13 |
libavdevice-dev libopus-dev libvpx-dev libsrtp2-dev \
|
| 14 |
+
build-essential nodejs npm curl \
|
| 15 |
&& rm -rf /var/lib/apt/lists/*
|
| 16 |
|
|
|
|
|
|
|
| 17 |
RUN pip install --no-cache-dir torch torchvision --index-url https://download.pytorch.org/whl/cpu
|
| 18 |
|
| 19 |
COPY requirements.txt ./
|
|
|
|
| 21 |
|
| 22 |
COPY . .
|
| 23 |
|
| 24 |
+
# HF Docker builds copy LFS pointers, not real files.
|
| 25 |
+
# Resolve them by downloading from the HF API.
|
| 26 |
+
ARG HF_SPACE=FocusGuard/final
|
|
|
|
|
|
|
|
|
|
| 27 |
RUN python -c "\
|
| 28 |
+
import os, urllib.request, sys;\
|
| 29 |
+
SPACE='${HF_SPACE}';\
|
| 30 |
+
BASE=f'https://huggingface.co/spaces/{SPACE}/resolve/main';\
|
| 31 |
+
files=[\
|
| 32 |
+
'checkpoints/mlp_best.pt',\
|
| 33 |
+
'checkpoints/scaler_mlp.joblib',\
|
| 34 |
+
'checkpoints/hybrid_combiner.joblib',\
|
| 35 |
+
'checkpoints/hybrid_focus_config.json',\
|
| 36 |
+
'checkpoints/xgboost_face_orientation_best.json',\
|
| 37 |
+
'checkpoints/meta_best.npz',\
|
| 38 |
+
'checkpoints/meta_mlp.npz',\
|
| 39 |
+
'checkpoints/L2CSNet_gaze360.pkl',\
|
| 40 |
+
'models/L2CS-Net/models/L2CSNet_gaze360.pkl',\
|
| 41 |
];\
|
| 42 |
+
for f in files:\
|
| 43 |
+
path=f;\
|
| 44 |
+
is_ptr=False;\
|
| 45 |
+
if os.path.isfile(path):\
|
| 46 |
+
with open(path,'rb') as fh:\
|
| 47 |
+
is_ptr=fh.read(50).startswith(b'version https://git-lfs');\
|
| 48 |
+
if not os.path.isfile(path) or is_ptr:\
|
| 49 |
+
url=f'{BASE}/{f}';\
|
| 50 |
+
print(f'Downloading {f} ...');\
|
| 51 |
+
try:\
|
| 52 |
+
os.makedirs(os.path.dirname(path),exist_ok=True);\
|
| 53 |
+
urllib.request.urlretrieve(url,path);\
|
| 54 |
+
sz=os.path.getsize(path);\
|
| 55 |
+
print(f' OK ({sz} bytes)');\
|
| 56 |
+
except Exception as e:\
|
| 57 |
+
print(f' WARN: {e}');\
|
| 58 |
else:\
|
| 59 |
+
print(f'[OK] {f} ({os.path.getsize(path)} bytes)');\
|
| 60 |
+
print('Checkpoint resolution done')\
|
|
|
|
|
|
|
| 61 |
"
|
| 62 |
|
| 63 |
RUN npm install && npm run build && mkdir -p /app/static && cp -R dist/* /app/static/
|