--- title: Pipe Count Dev emoji: 🔧 colorFrom: blue colorTo: green sdk: docker app_port: 7860 pinned: false --- # Pipe Counting PWA (Offline-First) Modern offline-first PWA for counting pipes with **in-browser ONNX inference**, diameter clustering, and interactive correction. ## Features - **Offline inference** — YOLOv5 model runs in the browser via ONNX Runtime Web (WebGPU / WASM) - **Multi-diameter sorting** — clusters pipes by bounding-box size (no retraining) - **Interactive correction** — add, delete, re-tag, and area-select pipes - **Expected vs counted QA** — optional per-group expected quantity - **Export** — annotated PNG, JSON, CSV (client-side) - **Bilingual** — Thai / English UI - **Fast deploy** — tiny Docker image (no PyTorch at runtime) ## Architecture ``` Browser PWA → ONNX Runtime Web → YOLOv5 countmodel.onnx ↓ Diameter clustering + user corrections + export ↑ HF Space serves static files only (main.py) ``` ## Local development ### Frontend only ```bash cd frontend npm install npm run dev ``` ### Full stack (built PWA + API) ```bash cd frontend && npm run build # copy dist + models to static/ cd .. pip install -r requirements-server.txt uvicorn main:app --host 0.0.0.0 --port 7860 ``` ### Export ONNX model (one-time / CI) ```bash pip install -r requirements-export.txt pip install torch torchvision --index-url https://download.pytorch.org/whl/cpu git clone --depth 1 https://github.com/ultralytics/yolov5.git python scripts/export_onnx.py ``` ## API Endpoints | Endpoint | Method | Description | |----------|--------|-------------| | `/` | GET | PWA shell | | `/health` | GET | Health check | ## Hugging Face Spaces - SDK: Docker - Port: 7860 - Hardware: Free CPU is sufficient (inference runs on client devices) - Build uses multi-stage Dockerfile: export ONNX → build PWA → serve static ## Configuration | Variable | Default | Description | |----------|---------|-------------| | (none required) | — | Inference is client-side | Legacy server inference endpoints (`/detectImage`, `/detect/json`) were removed in v1.0.0.