| # Use a lightweight Python base image | |
| FROM python:3.10-slim | |
| # Set environment variables for HF Spaces | |
| ENV PYTHONUNBUFFERED=1 \ | |
| PYTHONDONTWRITEBYTECODE=1 \ | |
| PORT=7860 | |
| # Add a user with UID 1000 as required by HF Spaces | |
| RUN useradd -m -u 1000 user | |
| USER user | |
| ENV HOME=/home/user \ | |
| PATH=/home/user/.local/bin:$PATH | |
| WORKDIR $HOME/app | |
| # Copy and install requirements | |
| COPY --chown=user requirements.txt . | |
| RUN pip install --no-cache-dir -r requirements.txt | |
| # Copy the rest of the application | |
| COPY --chown=user . . | |
| # Expose the mandatory HF port | |
| EXPOSE 7860 | |
| # Command to run the Fast API server | |
| CMD ["python", "main.py"] | |