Spaces:
Runtime error
Runtime error
Commit ·
08104c5
1
Parent(s): 3d8164d
try to preload a differnt model
Browse files- Dockerfile +18 -20
Dockerfile
CHANGED
|
@@ -1,47 +1,45 @@
|
|
| 1 |
FROM nvidia/cuda:12.0.0-cudnn8-devel-ubuntu22.04
|
| 2 |
|
| 3 |
-
|
| 4 |
-
# 1) Variables HF avant tout
|
| 5 |
ENV HF_HOME="/home/user/.cache/huggingface" \
|
| 6 |
HF_HUB_CACHE="/home/user/.cache/huggingface/hub" \
|
| 7 |
TRANSFORMERS_CACHE="/home/user/.cache/huggingface/transformers"
|
| 8 |
|
| 9 |
-
# 2)
|
| 10 |
RUN useradd -m -u 1000 user
|
| 11 |
|
|
|
|
| 12 |
RUN apt-get update && \
|
| 13 |
apt-get install -y --no-install-recommends \
|
| 14 |
-
|
|
|
|
| 15 |
rm -rf /var/lib/apt/lists/*
|
| 16 |
|
| 17 |
-
# 3) Installer dépendances système
|
| 18 |
-
RUN apt-get update && apt-get install -y \
|
| 19 |
-
build-essential git libpoppler-cpp-dev poppler-utils libmagic-dev python3-dev \
|
| 20 |
-
&& rm -rf /var/lib/apt/lists/*
|
| 21 |
-
|
| 22 |
-
# 4) Copier requirements et installer libs Python
|
| 23 |
WORKDIR /home/user/app
|
| 24 |
COPY --chown=user requirements.txt .
|
|
|
|
|
|
|
| 25 |
RUN pip install --no-cache-dir torch torchvision --extra-index-url https://download.pytorch.org/whl/cu118
|
| 26 |
RUN pip install --no-cache-dir huggingface_hub
|
| 27 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 28 |
|
| 29 |
-
# 5)
|
| 30 |
-
RUN mkdir -p /home/user/app/model_cache $HF_HUB_CACHE \
|
| 31 |
-
|
| 32 |
|
| 33 |
-
# 6)
|
| 34 |
USER user
|
| 35 |
RUN python3 - <<EOF
|
| 36 |
-
import os
|
| 37 |
from huggingface_hub import snapshot_download
|
|
|
|
| 38 |
snapshot_download(
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
|
|
|
| 42 |
)
|
| 43 |
EOF
|
| 44 |
|
| 45 |
-
# 7)
|
| 46 |
COPY --chown=user . .
|
| 47 |
-
CMD ["uvicorn","app:app","--host","0.0.0.0","--port","7860"]
|
|
|
|
| 1 |
FROM nvidia/cuda:12.0.0-cudnn8-devel-ubuntu22.04
|
| 2 |
|
| 3 |
+
# 1) Configure HF cache locations up front
|
|
|
|
| 4 |
ENV HF_HOME="/home/user/.cache/huggingface" \
|
| 5 |
HF_HUB_CACHE="/home/user/.cache/huggingface/hub" \
|
| 6 |
TRANSFORMERS_CACHE="/home/user/.cache/huggingface/transformers"
|
| 7 |
|
| 8 |
+
# 2) Create non-root user
|
| 9 |
RUN useradd -m -u 1000 user
|
| 10 |
|
| 11 |
+
# 3) Install Python & system libs
|
| 12 |
RUN apt-get update && \
|
| 13 |
apt-get install -y --no-install-recommends \
|
| 14 |
+
python3 python3-pip python3-dev \
|
| 15 |
+
build-essential git libpoppler-cpp-dev poppler-utils libmagic-dev && \
|
| 16 |
rm -rf /var/lib/apt/lists/*
|
| 17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
WORKDIR /home/user/app
|
| 19 |
COPY --chown=user requirements.txt .
|
| 20 |
+
|
| 21 |
+
# 4) Install Python deps
|
| 22 |
RUN pip install --no-cache-dir torch torchvision --extra-index-url https://download.pytorch.org/whl/cu118
|
| 23 |
RUN pip install --no-cache-dir huggingface_hub
|
| 24 |
RUN pip install --no-cache-dir -r requirements.txt
|
| 25 |
|
| 26 |
+
# 5) Prep model cache dir and HF cache, set ownership
|
| 27 |
+
RUN mkdir -p /home/user/app/model_cache $HF_HUB_CACHE && \
|
| 28 |
+
chown -R user:user /home/user/app /home/user/.cache/huggingface
|
| 29 |
|
| 30 |
+
# 6) **Switch to non-root user** and pre-download your model
|
| 31 |
USER user
|
| 32 |
RUN python3 - <<EOF
|
|
|
|
| 33 |
from huggingface_hub import snapshot_download
|
| 34 |
+
import os
|
| 35 |
snapshot_download(
|
| 36 |
+
repo_id="numind/NuExtract-1.5", # <-- your HF model ID
|
| 37 |
+
local_dir="/home/user/app/model_cache", # <-- where your FastAPI will load from
|
| 38 |
+
cache_dir=os.getenv("HF_HUB_CACHE"), # <-- HF’s own cache
|
| 39 |
+
resume_download=True
|
| 40 |
)
|
| 41 |
EOF
|
| 42 |
|
| 43 |
+
# 7) Copy your code and launch
|
| 44 |
COPY --chown=user . .
|
| 45 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|