FROM python:3.11-slim # System libraries needed by scipy/scikit-learn/matplotlib wheels and shap's build step RUN apt-get update && apt-get install -y --no-install-recommends \ build-essential \ libgomp1 \ && rm -rf /var/lib/apt/lists/* # Hugging Face Spaces runs containers as a non-root user by convention RUN useradd -m -u 1000 appuser USER appuser ENV HOME=/home/appuser \ PATH=/home/appuser/.local/bin:$PATH WORKDIR /home/appuser/app COPY --chown=appuser:appuser requirements.txt . RUN pip install --no-cache-dir --user -r requirements.txt COPY --chown=appuser:appuser app.py . # Hugging Face Docker Spaces expect the app to listen on port 7860 ENV PORT=7860 \ WORK_ROOT=/home/appuser/app/runs \ MPLCONFIGDIR=/home/appuser/app/.mplcache RUN mkdir -p /home/appuser/app/runs /home/appuser/app/.mplcache EXPOSE 7860 CMD ["python", "app.py"]