# HuggingFace Spaces — FastAPI # Base image: slim Python 3.11 FROM python:3.11-slim # HuggingFace Spaces runs as a non-root user (uid 1000). # Create the user + working directory up-front so file ownership is correct. RUN useradd -m -u 1000 appuser WORKDIR /app # Install dependencies as root first (faster layer caching) COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt # Copy application source COPY app.py . # Switch to non-root user required by HuggingFace Spaces USER appuser # HuggingFace Spaces expects the service to listen on port 7860 EXPOSE 7860 # Start uvicorn CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]