Closing Guard is a local-first closing-safety agent for small shops. It turns old Android phones into camera/UI terminals, uses local MiniCPM models to check the gas valve, power panel and door lock, and produces a hash-chained closing ledger that can be verified by scanning a QR code.

This is an engineering demo, not a commercial product. The three critical safety items — gas valve, power panel and door lock — must be confirmed by a human even when the AI says they pass. It records what happened after the fact; it does not replace gas detectors, emergency shut-off valves or fire inspections.
Why Build This
The author was eating at a small street-side restaurant and, on the way out, saw a staff member post a photo to a group chat captioned "closed". The photo showed the stove, with the valve at the edge of the frame — impossible to tell if it was open or shut. That was the moment he realized: closing-time sign-off has always relied on a photo nobody checks.
Malls have property staff inspecting each shop at closing (water, power, gas, doors) against detailed standards. Small street shops have no one checking; it is left to staff, who snap a photo, and nobody knows whether the valve in it is actually closed.
The technical turning point is on-device: 1B-class multimodal models can now understand valves, locks and power panels on cheap hardware and output a JSON verdict with reasons. Shops already have unused old phones, so the cost is close to zero.
The goal is not to let AI sign for staff, but to leave reviewable evidence of "was it shut" for the first time: who checked what and when, what the model said, what the human confirmed, and whether the ledger has been tampered with. That defines the shape: local, evidence-preserving, and humans can always say "no".
Workflow
- An old phone or emulator opens a viewfinder and guides staff to photograph each item;
- Local MiniCPM-V 4.7 1B judges the state of valves, locks and panels, MiniCPM-OCR 1.0 reads the gas meter, MiniCPM-OCR Jev scores the reading's consistency, and OpenCV cross-checks angles and flames;
- Uncertain → retake; abnormal → fix it; critical items must be confirmed by a human even if the AI passes them;
- A closing ledger PDF with a SHA-256 hash chain is generated, with a verification API and QR code.
It does not just record photos — it refuses to let you tap "done" until the checks are complete.

Architecture
Old phone / Android emulator
Camera → WebView UI ──(localhost + adb reverse)──┐
↓
Local hub (Mac mini / in-store machine)
FastAPI → Agent state machine
├─ OpenCV: quality / angle / flame
├─ MiniCPM-V 4.7 1B (llama.cpp :8081)
├─ MiniCPM-OCR 1.0 (llama.cpp :8082)
├─ MiniCPM-OCR Jev (llama.cpp :8083)
├─ SQLite: evidence + hash chain
└─ PDF ledger + QR verification
| Component | Tech | Role |
|---|---|---|
| Device | Android WebView (minSdk 24) | Camera, screen, touch; loads the local web UI |
| Web UI | React + TypeScript + Vite | Check flow, evidence preview, sign-off |
| Hub | Python 3.11 + FastAPI + SQLite | Sessions, state machine, evidence, reports |
| Vision | OpenCV | Quality gate, valve orientation, flame color cross-check |
| Semantics | MiniCPM-V 4.7 1B (GGUF Q4_K_M) | Valve / lock / panel state |
| Readings | MiniCPM-OCR 1.0 (GGUF Q8_0) | Gas meters, thermometers, pressure gauges |
| Reading check | MiniCPM-OCR Jev (GGUF Q4_K_M) | Scores OCR candidates: high → auto-accept, low → human |
| Evidence | SHA-256 chain + WeasyPrint | Hash-chained ledger, verify API and QR code |
"On-device" here means in-store and offline: models run on a local hub in the shop (currently a laptop or mini PC), and photos, verdicts and ledgers stay on that machine. On-phone inference needs extra work and is on the roadmap. The Android app is a thin WebView shell, so phones running Android 7+ work.
Verdict Fusion
Poor image quality -> unsure (retake, no model call)
Flame color cross-check hit -> fail (even if 1B says pass)
Angle off beyond tolerance -> fail (only when CV is confident)
1B clearly says fail -> fail
1B pass with enough confidence -> pass (critical items still need a human)
Otherwise -> unsure (retake or human)
Why not let 1B decide alone? In testing, 1B was not reliable at telling whether panel switches were up or down: an ON power panel came back unsure at 0.5 confidence across runs and never passed stably. So the three critical items always require human confirmation, and the ledger records "AI suggestion + human signature" rather than pretending to be an "AI guarantee".
Quick Start
Requires Python 3.11, Node 20, llama-server on PATH, 8 GB+ RAM and about 5.5 GB of models. Fully verified on Apple Silicon macOS; dependency install and unit tests verified on Ubuntu.
git clone https://github.com/HankGuo/closing-guard.git
cd closing-guard
make demo # check env → install deps → download models → start services → print URL
Then open http://localhost:8010 and try the bundled sample images first.
Small-Sample Evaluation
The author ran real inference on 8 images on an M1 16 GB, deliberately including adversarial cases — open flame, an unlocked padlock, an ON power panel, and a water meter with a rolling last digit:
| Checkpoint | Image | Expected | Actual | Jev |
|---|---|---|---|---|
| Gas valve | closed valve | pass | pass | — |
| Gas valve | stove flame | fail | fail (flame cross-check) | — |
| Power panel | off | pass | pass | — |
| Power panel | on | fail | unsure (1B unreliable, to human) | — |
| Door lock | locked | pass | pass | — |
| Door lock | unlocked | fail | fail | — |
| Gas meter | test card | pass | pass | 0.983 |
| Gas meter | real water meter | unsure | unsure (rolling digit, to human) | 0.004 |
87.5% verdict accuracy with zero false passes. All 8 images come from Wikimedia Commons, none from a real restaurant kitchen, so this only shows the pipeline works and failures are visible — not field accuracy.
Known Limits
- 1B is unreliable at fine-grained switch positions; next step is CV-based breaker handle detection.
- The last digit of meters rolls and OCR cannot read it reliably; it goes to a human, and readings are not for billing.
- Testing used an Android emulator; real old-phone performance (low light, battery) is untested.
- No real store pilot yet.
- Jev thresholds need recalibration in real stores and cannot replace humans.
- The 35B-A3B version is too heavy for this hardware; choosing 1B is deliberate.
Safety Statement
This is an assistive check-and-record tool. It does not replace legally required fire, gas or market inspections and provides no safety guarantee. If you smell gas or see fire or electrical faults, evacuate immediately and call emergency services or your gas company — do not rely on this system.
Links
- GitHub: HankGuo/closing-guard
- Demo video: 58-second demo
