| # Use the official lightweight Python image | |
| FROM python:3.10-slim | |
| # Create a non-root user (Mandatory for Hugging Face Spaces security) | |
| RUN useradd -m -u 1000 user | |
| USER user | |
| # Set environment variables for the user and force model caching to a writable directory | |
| ENV HOME=/home/user \ | |
| PATH=/home/user/.local/bin:$PATH \ | |
| HF_HOME=/tmp/huggingface_cache | |
| WORKDIR $HOME/app | |
| # Copy requirements and install | |
| COPY --chown=user requirements.txt . | |
| RUN pip install --no-cache-dir -r requirements.txt | |
| # Copy the FastAPI application code | |
| COPY --chown=user . . | |
| # Expose the mandatory Hugging Face port | |
| EXPOSE 7860 | |
| # Launch the application | |
| CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"] |