# ── Stage 1: Build React frontend ─────────────────────────────────────────── FROM node:20-slim AS frontend-builder WORKDIR /app COPY package.json ./ RUN npm install --silent COPY public/ ./public/ COPY src/ ./src/ RUN npm run build # ── Stage 2: Python backend ────────────────────────────────────────────────── FROM python:3.11-slim RUN apt-get update && apt-get install -y --no-install-recommends \ git wget curl libglib2.0-0 libsm6 libxrender1 libxext6 \ && rm -rf /var/lib/apt/lists/* WORKDIR /app # Install Python deps first COPY requirements.txt . RUN pip install --no-cache-dir -r requirements.txt # Pre-download all models at BUILD time so runtime starts instantly COPY download_models.py . RUN python download_models.py # Copy app files COPY server.py . COPY --from=frontend-builder /app/build ./build # Fix permissions for HF non-root user 1000 RUN mkdir -p /app/.cache/huggingface /app/models \ && useradd -m -u 1000 hfuser \ && chown -R hfuser:hfuser /app USER 1000 ENV HF_HOME=/app/.cache/huggingface EXPOSE 7860 CMD ["python", "server.py"]