Spaces:
Runtime error
Runtime error
| 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"] |