Spaces:
Runtime error
Runtime error
File size: 1,591 Bytes
b7bae39 77c8eed 1680b8f 31c16de 727bef6 31c16de b8658f4 1680b8f 31c16de b8658f4 31c16de 1680b8f 31c16de 727bef6 31c16de 727bef6 31c16de a3a70b9 369dab9 7329fdd ae042ea 84a9640 31c16de 6ac2280 cd76ddf dd14bf0 31c16de | 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 | FROM nvidia/cuda:12.0.0-cudnn8-devel-ubuntu22.04
# 1) Variables HF avant tout
ENV HF_HOME="/home/user/.cache/huggingface" \
HF_HUB_CACHE="/home/user/.cache/huggingface/hub" \
TRANSFORMERS_CACHE="/home/user/.cache/huggingface/transformers"
# 2) Créer l’utilisateur non-root
RUN useradd -m -u 1000 user
RUN apt-get update && \
apt-get install -y --no-install-recommends \
python3 python3-pip python3-dev && \
rm -rf /var/lib/apt/lists/*
# 3) Installer dépendances système
RUN apt-get update && apt-get install -y \
build-essential git libpoppler-cpp-dev poppler-utils libmagic-dev python3-dev \
&& rm -rf /var/lib/apt/lists/*
# 4) Copier requirements et installer libs Python
WORKDIR /home/user/app
COPY --chown=user requirements.txt .
RUN pip install --no-cache-dir torch torchvision --extra-index-url https://download.pytorch.org/whl/cu118
RUN pip install --no-cache-dir huggingface_hub
RUN pip install --no-cache-dir -r requirements.txt
# 5) Pré-créer model_cache et HF_HOME, puis chown
RUN mkdir -p /home/user/app/model_cache $HF_HUB_CACHE \
&& chown -R user:user /home/user/app /home/user/.cache/huggingface
# 6) Télécharger le modèle au build-time sous l’utilisateur non-root
USER user
RUN python3 - <<EOF
import os
from huggingface_hub import snapshot_download
snapshot_download(
repo_id="numind/NuExtract-1.5-tiny",
local_dir="/home/user/app/model_cache",
cache_dir=os.getenv("HF_HUB_CACHE")
)
EOF
# 7) Copier le reste du code et démarrer
COPY --chown=user . .
CMD ["uvicorn","app:app","--host","0.0.0.0","--port","7860"] |