FROM python:3.11-slim Create the specific user required by Hugging Face Spaces RUN useradd -m -u 1000 user USER user ENV PATH="/home/user/.local/bin:$PATH" WORKDIR /app Copy and install dependencies first for faster caching COPY --chown=user requirements.txt . RUN pip install --no-cache-dir -r requirements.txt Copy the rest of the application COPY --chown=user . . Boot the FastAPI server exactly as you did locally CMD ["python", "app.py"]