FROM python:3.9-slim # Create a non-root user for security (Hugging Face Spaces best practice) RUN useradd -m -u 1000 user USER user ENV PATH="/home/user/.local/bin:$PATH" WORKDIR /app # Copy requirements first for better Docker layer caching COPY --chown=user requirements.txt /app/requirements.txt # Install dependencies RUN pip install --no-cache-dir --upgrade pip && \ pip install --no-cache-dir --user -r requirements.txt # Copy application code COPY --chown=user . /app # Expose port 7860 (Hugging Face Spaces standard) EXPOSE 7860 # Run FastAPI with uvicorn CMD ["uvicorn", "app_fastapi:app", "--host", "0.0.0.0", "--port", "7860"]