Spaces:
Sleeping
Sleeping
| # 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"] | |