Spaces:
Sleeping
Sleeping
File size: 1,099 Bytes
71c85a4 | 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 | # 1. Lightweight Python matching the dev version
FROM python:3.13-slim
# 2. Run as a non-root user. Hugging Face Spaces run containers as UID 1000;
# creating a matching user with a writable home avoids permission errors.
# (This is also good security practice for AWS / Docker Hub.)
RUN useradd -m -u 1000 user
USER user
ENV HOME=/home/user \
PATH=/home/user/.local/bin:$PATH
# 3. Working directory inside the user's home
WORKDIR /home/user/app
# 4. Copy the serving dependency file first (better layer caching)
COPY --chown=user requirements-serve.txt .
# 5. Install CPU-only torch, then the serving-only dependencies
RUN pip install --user --upgrade pip \
&& pip install --user torch --index-url https://download.pytorch.org/whl/cpu \
&& pip install --user -r requirements-serve.txt
# 6. Copy the project (including artifacts/, needed to serve)
COPY --chown=user . .
# 7. Unbuffered logs + make `src` importable
ENV PYTHONUNBUFFERED=1 \
PYTHONPATH=/home/user/app
EXPOSE 8000
CMD ["python", "-m", "uvicorn", "src.app.main:app", "--host", "0.0.0.0", "--port", "8000"]
|