FROM python:3.11-slim # System libs for Pillow + ONNX Runtime RUN apt-get update && apt-get install -y --no-install-recommends \ libgl1 libglib2.0-0 libgomp1 \ && rm -rf /var/lib/apt/lists/* # HF Spaces convention: non-root user named "user" with UID 1000 RUN useradd -m -u 1000 user USER user ENV HOME=/home/user \ PATH=/home/user/.local/bin:$PATH \ HOST=0.0.0.0 \ PORT=7860 WORKDIR /home/user/app COPY --chown=user requirements.txt . RUN pip install --no-cache-dir --user -r requirements.txt # Pre-download U-2-Net so the first /trace request is instant. RUN python -c "from rembg import new_session; new_session('u2net')" COPY --chown=user . . EXPOSE 7860 CMD ["python", "app.py"]