# ---- Docker ---- FROM python:3.10-slim # HF Spaces runs containers as uid 1000 – create a non-root user RUN useradd -m -u 1000 appuser WORKDIR /app # Install dependencies first (layer caching) COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt # Copy application code COPY . . # Pre-create HF / torch cache dirs writable by appuser RUN mkdir -p /home/appuser/.cache && chown -R appuser:appuser /home/appuser /app ENV HF_HOME=/home/appuser/.cache/huggingface USER appuser # HF Spaces expects port 7860; local Docker uses PORT env (default 7860) ENV PORT=7860 EXPOSE 7860 # Run with Uvicorn – 0.0.0.0 so the container is reachable from outside CMD uvicorn main:app --host 0.0.0.0 --port $PORT