| FROM python:3.11-slim | |
| # Install system dependencies in a single layer | |
| RUN apt-get update \ | |
| && apt-get install -y build-essential libpq-dev \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # Create a non-root user | |
| RUN useradd -m -u 1000 user | |
| # Set the working directory | |
| WORKDIR /app | |
| # Copy requirements first to leverage caching | |
| COPY ./requirements.txt requirements.txt | |
| RUN pip install --no-cache-dir --upgrade -r requirements.txt | |
| # Copy the rest of the application files (including model) | |
| COPY --chown=user:user . /app | |
| # Switch to non-root user | |
| USER user | |
| # Expose Hugging Face Spaces port | |
| EXPOSE 7860 | |
| # Start the Flask app | |
| CMD ["python", "app.py"] |