| FROM python:3.11-slim | |
| # HF Spaces enforces a non-root user (uid 1000) for the runtime. | |
| RUN useradd -m -u 1000 user | |
| WORKDIR /home/user/app | |
| ENV PATH="/home/user/.local/bin:${PATH}" \ | |
| PYTHONPATH=/home/user/app/src \ | |
| PYTHONDONTWRITEBYTECODE=1 \ | |
| PYTHONUNBUFFERED=1 \ | |
| PIP_NO_CACHE_DIR=1 \ | |
| HF_HOME=/home/user/.cache/hf \ | |
| XDG_CACHE_HOME=/home/user/.cache | |
| RUN apt-get update && apt-get install -y --no-install-recommends \ | |
| curl \ | |
| ca-certificates \ | |
| && rm -rf /var/lib/apt/lists/* | |
| USER user | |
| # Install CPU-only torch first so the wheel doesn't pull CUDA bloat. | |
| RUN pip install --user --no-cache-dir \ | |
| "torch>=2.1" --index-url https://download.pytorch.org/whl/cpu | |
| COPY --chown=user requirements.txt ./ | |
| RUN pip install --user --no-cache-dir -r requirements.txt | |
| COPY --chown=user config ./config | |
| COPY --chown=user checkpoints ./checkpoints | |
| COPY --chown=user src ./src | |
| # HF Spaces routes traffic to port 7860. | |
| EXPOSE 7860 | |
| CMD ["uvicorn", "recsys.serving.app:app", "--host", "0.0.0.0", "--port", "7860"] | |