FROM python:3.11-slim WORKDIR /app # Install deps first (cached layer — only invalidated when requirements change) COPY requirements-server.txt . RUN pip install --no-cache-dir \ torch torchvision torchaudio --index-url https://download.pytorch.org/whl/cu121 && \ pip install --no-cache-dir -r requirements-server.txt # Copy source (excludes venv/, training/, assets/, .git/ via .dockerignore) COPY . . # Pre-generate facts.json at build time; falls back gracefully if network is down RUN python -m data.loader || echo "facts.json generation skipped — will use fallback facts" EXPOSE 7860 # One worker so the optional trained-model adapter is loaded at most once. CMD ["uvicorn", "environment.server:app", "--host", "0.0.0.0", "--port", "7860", "--workers", "1"]