FROM python:3.11-slim # Create a non-root user for Hugging Face compatibility RUN useradd -m -u 1000 user WORKDIR /app # System dependencies RUN apt-get update && apt-get install -y \ gcc \ libpq-dev \ curl \ git \ postgresql-client \ && rm -rf /var/lib/apt/lists/* # Copy requirements and install as root to cache globally, # but ensure the user can access them COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt # Copy project files COPY --chown=user . . # Adjust permissions for the entrypoint and the app directory RUN chmod +x entrypoint.sh && chown -R user:user /app # Switch to the non-root user USER user ENV PATH="/home/user/.local/bin:$PATH" # Hugging Face Spaces MUST use port 7860 EXPOSE 7860 CMD ["./entrypoint.sh"]