# Use a stable, lightweight Python base FROM python:3.11-slim # Set environment variables to ensure output is sent to logs immediately ENV PYTHONUNBUFFERED=1 \ PYTHONDONTWRITEBYTECODE=1 \ PIP_NO_CACHE_DIR=1 # Set the working directory WORKDIR /app # Install only essential system dependencies RUN apt-get update && apt-get install -y \ build-essential \ curl \ git \ && rm -rf /var/lib/apt/lists/* # Create a non-root user (Hugging Face standard UID 1000) RUN useradd -m -u 1000 user USER user ENV HOME=/home/user \ PATH=/home/user/.local/bin:$PATH # Set up the app directory with correct permissions WORKDIR $HOME/app COPY --chown=user requirements.txt $HOME/app/ RUN pip install --user -r requirements.txt # Copy the rest of the application COPY --chown=user . $HOME/app # Hugging Face Spaces specific port EXPOSE 7860 # Command to run Streamlit correctly # --server.address=0.0.0.0 is mandatory for cloud access # --server.enableXsrfProtection=false is required for the HF iFrame CMD ["streamlit", "run", "app.py", "--server.port=7860", "--server.address=0.0.0.0", "--server.enableXsrfProtection=false"]