Spaces:
Runtime error
Runtime error
File size: 1,584 Bytes
b7bae39 77c8eed 08104c5 31c16de 727bef6 08104c5 b8658f4 08104c5 1680b8f 08104c5 1680b8f 31c16de 08104c5 1680b8f 31c16de 727bef6 08104c5 727bef6 08104c5 a3a70b9 369dab9 ae042ea 08104c5 84a9640 08104c5 6ac2280 cd76ddf dd14bf0 08104c5 31c16de 08104c5 | 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 | FROM nvidia/cuda:12.0.0-cudnn8-devel-ubuntu22.04
# 1) Configure HF cache locations up front
ENV HF_HOME="/home/user/.cache/huggingface" \
HF_HUB_CACHE="/home/user/.cache/huggingface/hub" \
TRANSFORMERS_CACHE="/home/user/.cache/huggingface/transformers"
# 2) Create non-root user
RUN useradd -m -u 1000 user
# 3) Install Python & system libs
RUN apt-get update && \
apt-get install -y --no-install-recommends \
python3 python3-pip python3-dev \
build-essential git libpoppler-cpp-dev poppler-utils libmagic-dev && \
rm -rf /var/lib/apt/lists/*
WORKDIR /home/user/app
COPY --chown=user requirements.txt .
# 4) Install Python deps
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) Prep model cache dir and HF cache, set ownership
RUN mkdir -p /home/user/app/model_cache $HF_HUB_CACHE && \
chown -R user:user /home/user/app /home/user/.cache/huggingface
# 6) **Switch to non-root user** and pre-download your model
USER user
RUN python3 - <<EOF
from huggingface_hub import snapshot_download
import os
snapshot_download(
repo_id="numind/NuExtract-1.5", # <-- your HF model ID
local_dir="/home/user/app/model_cache", # <-- where your FastAPI will load from
cache_dir=os.getenv("HF_HUB_CACHE"), # <-- HF’s own cache
resume_download=True
)
EOF
# 7) Copy your code and launch
COPY --chown=user . .
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"] |