File size: 2,120 Bytes
0e0cc3e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
---
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.