# HuggingFace Spaces — single-container deployment # # Builds the React dashboard, then serves it as static files from FastAPI. # Everything runs on port 7860 (required by HF Spaces). # No GPU — CPU-only ONNX inference. Demo mode works at full speed. # For real video, keep clips under 20 seconds. # ── Stage 1: build React dashboard ─────────────────────────────────────────── FROM node:20-alpine AS frontend-build WORKDIR /frontend COPY dashboard/package.json dashboard/package-lock.json* ./ RUN npm install COPY dashboard/ . # API calls go to the same origin (/api/*) — no separate WS URL needed RUN npm run build # ── Stage 2: Python backend + static frontend ──────────────────────────────── FROM python:3.11-slim WORKDIR /app # System deps for OpenCV headless RUN apt-get update && apt-get install -y --no-install-recommends \ libglib2.0-0 libgomp1 libgl1 libglib2.0-0 \ libxcb1 libxext6 libx11-6 libsm6 libxrender1 \ && rm -rf /var/lib/apt/lists/* # Python deps — CPU-only onnxruntime (no CUDA on HF free tier) RUN pip install --no-cache-dir \ fastapi \ "uvicorn[standard]" \ websockets \ "pydantic>=2.0" \ aiosqlite \ python-multipart \ python-dotenv \ opencv-python-headless \ supervision \ numpy \ onnxruntime \ scipy \ Pillow # Copy backend source COPY core/ ./core/ COPY api/ ./api/ # Copy built frontend into a location FastAPI will serve as static files COPY --from=frontend-build /frontend/dist ./dashboard/dist # Data directory for SQLite RUN mkdir -p /app/data # HF Spaces runs containers as uid 1000 — ensure writable data dir RUN chown -R 1000:1000 /app/data # HF Spaces requires port 7860 EXPOSE 7860 ENV API_HOST=0.0.0.0 ENV API_PORT=7860 ENV SERVE_FRONTEND=1 CMD ["uvicorn", "api.main:app", "--host", "0.0.0.0", "--port", "7860"]