naazimsnh02 commited on
Commit
e0446f7
Β·
1 Parent(s): d47fb57

Final Submission

Browse files
Files changed (5) hide show
  1. .gitignore +6 -0
  2. README.md +7 -15
  3. SUBMISSION.md +171 -0
  4. MODEL_CARD.md β†’ docs/MODEL_CARD.md +0 -0
  5. tracer.py +2 -16
.gitignore CHANGED
@@ -42,6 +42,12 @@ tmp/
42
  .venv/
43
  venv/
44
 
 
 
 
 
45
  # Local diagnostic logs
46
  samples/diag_*_out*.txt
47
  *.png
 
 
 
42
  .venv/
43
  venv/
44
 
45
+ # Remotion video project
46
+ video/node_modules/
47
+ video/out/
48
+
49
  # Local diagnostic logs
50
  samples/diag_*_out*.txt
51
  *.png
52
+ *.mp4
53
+ video/
README.md CHANGED
@@ -34,7 +34,10 @@ tags:
34
 
35
  *Find where money is being lost β€” in under 60 seconds*
36
 
37
- [![HF Space](https://img.shields.io/badge/πŸ€—%20Space-Kirana%20Detective-blue)](https://huggingface.co/spaces/build-small-hackathon/kirana-detective)
 
 
 
38
  [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)
39
  [![Python 3.11](https://img.shields.io/badge/Python-3.11-blue.svg)](https://python.org)
40
  [![Training: Modal](https://img.shields.io/badge/Training-Modal%20A10G-orange)](https://modal.com)
@@ -113,7 +116,7 @@ Agent 6 β€” MiniCPM5-1B generates rupee savings report + action items
113
  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
114
  ```
115
 
116
- Every agent run is traced and logged for the **Sharing is Caring** badge.
117
 
118
  ---
119
 
@@ -225,27 +228,18 @@ Comfortably within the **Tiny Titan** ≀4B threshold. Zero cloud API calls β€”
225
  | πŸ”Œ Off the Grid | 100% local inference β€” MiniCPM-V (transformers) + MiniCPM5-1B (GGUF) + YOLO26n (ONNX) |
226
  | πŸ¦™ Llama Champion | MiniCPM5-1B served via llama-cpp-python (GGUF Q4_K_M) |
227
  | 🎨 Off-Brand | Custom Gradio UI β€” rupee savings cards, colour-coded anomaly flags |
228
- | πŸ“‘ Sharing is Caring | Two public trace datasets: runtime audit traces per run + full Claude Code build sessions |
229
  | πŸ““ Field Notes | *"How I built an AI auditor for India's 12 million kirana stores"* |
230
  | πŸ‹οΈ Tiny Titan | ~2.38B total parameters β€” OCR + normalization + counting + report |
231
 
232
  ---
233
 
234
- ## Sharing is Caring β€” Trace Datasets
235
-
236
- Two public datasets document everything that happened in this project:
237
-
238
- ### 1. Runtime Audit Traces β€” `build-small-hackathon/kirana-detective-traces`
239
-
240
- Published automatically after every invoice audit run by [`tracer.py`](tracer.py). Each file records one complete pipeline execution β€” all six agents, inputs, outputs, and timings.
241
-
242
- ### 2. Claude Code Build Sessions β€” `build-small-hackathon/kirana-detective-build-traces`
243
 
244
  The 11 raw Claude Code (Sonnet 4.6) JSONL sessions used to design, code, debug, and document this entire project β€” from blank repo to hackathon submission. Viewable in HF Data Studio's native agent trace viewer.
245
 
246
  | Dataset | Contents | Format |
247
  |---|---|---|
248
- | [`build-small-hackathon/kirana-detective-traces`](https://huggingface.co/datasets/build-small-hackathon/kirana-detective-traces) | Per-audit runtime traces (6 agents per run) | JSONL, auto-published by app |
249
  | [`build-small-hackathon/kirana-detective-build-traces`](https://huggingface.co/datasets/build-small-hackathon/kirana-detective-build-traces) | 11 Claude Code build sessions Β· ~8.9 MB | Native JSONL trace viewer |
250
 
251
  To upload build traces:
@@ -297,9 +291,7 @@ kirana-detective/
297
  - **Product normalizer**: [build-small-hackathon/minicpm5-1b-indian-fmcg-normalizer](https://huggingface.co/build-small-hackathon/minicpm5-1b-indian-fmcg-normalizer)
298
  - **Product detector**: [build-small-hackathon/yolo26n-indian-fmcg-detection](https://huggingface.co/build-small-hackathon/yolo26n-indian-fmcg-detection)
299
  - **Full model card**: [MODEL_CARD.md](MODEL_CARD.md)
300
- - **Runtime audit traces**: [build-small-hackathon/kirana-detective-traces](https://huggingface.co/datasets/build-small-hackathon/kirana-detective-traces)
301
  - **Build sessions (Claude Code)**: [build-small-hackathon/kirana-detective-build-traces](https://huggingface.co/datasets/build-small-hackathon/kirana-detective-build-traces)
302
- - **PRD**: [docs/kirana-detective-prd.md](docs/kirana-detective-prd.md)
303
 
304
  ---
305
 
 
34
 
35
  *Find where money is being lost β€” in under 60 seconds*
36
 
37
+ [![Try It Live](https://img.shields.io/badge/πŸ€—%20Try%20It-Live%20Demo-blue)](https://huggingface.co/spaces/build-small-hackathon/kirana-detective)
38
+ [![Watch Demo](https://img.shields.io/badge/β–Ά%20Watch-Demo-red)](https://youtu.be/8TVZP4sfesI)
39
+ [![Blog Post](https://img.shields.io/badge/πŸ“%20Blog-How%20I%20Built%20It-orange)](https://huggingface.co/blog/build-small-hackathon/kirana-detective)
40
+ [![X Post](https://img.shields.io/badge/𝕏-View%20Post-black)](https://x.com/naazimhussain02/status/2065966381657633161)
41
  [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE)
42
  [![Python 3.11](https://img.shields.io/badge/Python-3.11-blue.svg)](https://python.org)
43
  [![Training: Modal](https://img.shields.io/badge/Training-Modal%20A10G-orange)](https://modal.com)
 
116
  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
117
  ```
118
 
119
+ Every agent run is stored locally in SQLite for audit history.
120
 
121
  ---
122
 
 
228
  | πŸ”Œ Off the Grid | 100% local inference β€” MiniCPM-V (transformers) + MiniCPM5-1B (GGUF) + YOLO26n (ONNX) |
229
  | πŸ¦™ Llama Champion | MiniCPM5-1B served via llama-cpp-python (GGUF Q4_K_M) |
230
  | 🎨 Off-Brand | Custom Gradio UI β€” rupee savings cards, colour-coded anomaly flags |
231
+ | πŸ“‘ Sharing is Caring | Claude Code build sessions (11 JSONL sessions) published as a public trace dataset |
232
  | πŸ““ Field Notes | *"How I built an AI auditor for India's 12 million kirana stores"* |
233
  | πŸ‹οΈ Tiny Titan | ~2.38B total parameters β€” OCR + normalization + counting + report |
234
 
235
  ---
236
 
237
+ ## Sharing is Caring β€” Build Trace Dataset
 
 
 
 
 
 
 
 
238
 
239
  The 11 raw Claude Code (Sonnet 4.6) JSONL sessions used to design, code, debug, and document this entire project β€” from blank repo to hackathon submission. Viewable in HF Data Studio's native agent trace viewer.
240
 
241
  | Dataset | Contents | Format |
242
  |---|---|---|
 
243
  | [`build-small-hackathon/kirana-detective-build-traces`](https://huggingface.co/datasets/build-small-hackathon/kirana-detective-build-traces) | 11 Claude Code build sessions Β· ~8.9 MB | Native JSONL trace viewer |
244
 
245
  To upload build traces:
 
291
  - **Product normalizer**: [build-small-hackathon/minicpm5-1b-indian-fmcg-normalizer](https://huggingface.co/build-small-hackathon/minicpm5-1b-indian-fmcg-normalizer)
292
  - **Product detector**: [build-small-hackathon/yolo26n-indian-fmcg-detection](https://huggingface.co/build-small-hackathon/yolo26n-indian-fmcg-detection)
293
  - **Full model card**: [MODEL_CARD.md](MODEL_CARD.md)
 
294
  - **Build sessions (Claude Code)**: [build-small-hackathon/kirana-detective-build-traces](https://huggingface.co/datasets/build-small-hackathon/kirana-detective-build-traces)
 
295
 
296
  ---
297
 
SUBMISSION.md ADDED
@@ -0,0 +1,171 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Kirana Detective β€” Hackathon Submission
2
+
3
+ **HuggingFace Build Small Hackathon 2026**
4
+
5
+ | | |
6
+ |---|---|
7
+ | **Space** | [build-small-hackathon/kirana-detective](https://huggingface.co/spaces/build-small-hackathon/kirana-detective) |
8
+ | **Demo Video** | [YouTube](https://youtu.be/8TVZP4sfesI) |
9
+ | **Blog Post** | [How I Built an AI Auditor for India's 12 Million Kirana Stores](https://huggingface.co/blog/build-small-hackathon/kirana-detective) |
10
+ | **Social Post** | [X / Twitter](https://x.com/naazimhussain02/status/2065966381657633161) |
11
+ | **Track** | Track 1: Backyard AI |
12
+ | **Total Parameters** | ~2.38B (Tiny Titan βœ…) |
13
+
14
+ ---
15
+
16
+ ## Track: Backyard AI
17
+
18
+ **Problem**: India's 12 million kirana store owners receive 3–5 distributor invoices per week via WhatsApp, printed bills, or Tally exports. Manual verification is impossible. Distributors overcharge, deliver short quantities, and apply wrong GST rates. A single store loses β‚Ή3,000–₹8,000 per month silently.
19
+
20
+ **Solution**: Upload an invoice + delivery photos β†’ receive a β‚Ή leakage report in under 60 seconds. Every finding (overcharge, shortage, GST error, duplicate) maps to a rupee amount and an action step.
21
+
22
+ **Real user**: Tested against real invoice formats from kirana distributors in India (HUL, ITC, NestlΓ©, Britannia).
23
+
24
+ **Model constraint fit**: Entire pipeline runs on CPU β€” no GPU required at inference. Designed for Tier 2/3 city deployment where GPU hardware is absent and internet is patchy.
25
+
26
+ ---
27
+
28
+ ## Merit Badges
29
+
30
+ ### βœ… Off the Grid
31
+ Zero cloud API calls. All inference runs locally:
32
+ - MiniCPM-V 4.6 via `transformers` (merged bfloat16 weights)
33
+ - MiniCPM5-1B via `llama-cpp-python` (GGUF Q4_K_M)
34
+ - YOLO26n via ONNX Runtime
35
+
36
+ Invoice data never leaves the device. Suitable for privacy-sensitive business data.
37
+
38
+ ### βœ… Well-Tuned
39
+ Three custom models fine-tuned from scratch and published on HF Hub:
40
+
41
+ | Model | Repo | Task |
42
+ |---|---|---|
43
+ | MiniCPM-V 4.6 | [`build-small-hackathon/minicpm-v-4-6-indian-invoice-extraction-merged`](https://huggingface.co/build-small-hackathon/minicpm-v-4-6-indian-invoice-extraction-merged) | Invoice OCR β†’ structured JSON |
44
+ | MiniCPM5-1B | [`build-small-hackathon/minicpm5-1b-indian-fmcg-normalizer`](https://huggingface.co/build-small-hackathon/minicpm5-1b-indian-fmcg-normalizer) | Product name normalisation + savings report |
45
+ | YOLO26n | [`build-small-hackathon/yolo26n-indian-fmcg-detection`](https://huggingface.co/build-small-hackathon/yolo26n-indian-fmcg-detection) | Product counting from delivery photos |
46
+
47
+ Training dataset: [`build-small-hackathon/kirana-invoice-train-data`](https://huggingface.co/datasets/build-small-hackathon/kirana-invoice-train-data) β€” 500 synthetic Indian invoices (printed GST, Tally PDF, handwritten, WhatsApp).
48
+
49
+ ### βœ… Off-Brand
50
+ Custom Gradio UI β€” not default Gradio. Features:
51
+ - Rupee savings cards with colour-coded anomaly type (overcharge = red, shortage = amber, duplicate = purple, GST = orange)
52
+ - Agent progress stream with per-agent timing
53
+ - Collapsible raw JSON view per agent
54
+ - Dark/warm colour scheme themed around the kirana store context
55
+
56
+ ### βœ… Llama Champion
57
+ MiniCPM5-1B is served entirely via `llama-cpp-python` using a GGUF Q4_K_M quantised model. Used for both Agent 2 (product normalisation) and Agent 6 (savings report generation). No transformers at runtime for these two agents β€” pure llama.cpp.
58
+
59
+ ### βœ… Sharing is Caring
60
+ 11 raw Claude Code (Sonnet 4.6) JSONL build sessions published as a public trace dataset, viewable in HF Data Studio's native agent trace viewer:
61
+
62
+ [`build-small-hackathon/kirana-detective-build-traces`](https://huggingface.co/datasets/build-small-hackathon/kirana-detective-build-traces) β€” complete design, coding, debugging, and documentation sessions from blank repo to submission.
63
+
64
+ ### βœ… Field Notes
65
+ Full blog post: [How I Built an AI Auditor for India's 12 Million Kirana Stores](https://huggingface.co/blog/build-small-hackathon/kirana-detective)
66
+
67
+ Covers: the problem, the 6-agent pipeline design, all three fine-tuned models with training details, the local-inference rationale, the hardest bug, and the full stack.
68
+
69
+ ---
70
+
71
+ ## Prize Categories Targeted
72
+
73
+ ### Special Awards
74
+
75
+ **πŸ‹οΈ Tiny Titan** β€” ~2.38B total parameters across all three models combined.
76
+
77
+ | Component | Parameters |
78
+ |---|---|
79
+ | MiniCPM-V 4.6 (merged bfloat16) | ~1.3B |
80
+ | MiniCPM5-1B (GGUF Q4_K_M) | ~1.08B |
81
+ | YOLO26n (ONNX) | ~2.4M |
82
+ | **Total** | **~2.38B** |
83
+
84
+ Well within the ≀4B Tiny Titan threshold.
85
+
86
+ **πŸ€– Best Agent** β€” Fully modular 6-agent pipeline. Each agent has a single responsibility, a defined input/output contract, and produces an `AgentTraceEntry` with timing. Generator-based streaming shows live agent progress in the UI.
87
+
88
+ **🎨 Off-Brand** β€” Custom Gradio UI with rupee savings cards, colour-coded anomaly flags, and agent-by-agent progress stream. Distinctly different from the default Gradio look.
89
+
90
+ **πŸ“Š Best Demo** β€” End-to-end demo covering: invoice upload β†’ extraction β†’ normalisation β†’ price check β†’ delivery photo counting β†’ shortage reconciliation β†’ β‚Ή savings report with action items.
91
+
92
+ **πŸŽ–οΈ Bonus Quest Champion** β€” All 6 merit badges claimed on a single submission:
93
+
94
+ | # | Badge | Evidence |
95
+ |---|---|---|
96
+ | 1 | Off the Grid | Zero cloud API calls β€” MiniCPM-V (transformers) + MiniCPM5-1B (llama.cpp) + YOLO26n (ONNX), all CPU |
97
+ | 2 | Well-Tuned | 3 custom fine-tuned models published on HF Hub (MiniCPM-V 4.6, MiniCPM5-1B, YOLO26n) |
98
+ | 3 | Off-Brand | Custom Gradio UI β€” rupee savings cards, colour-coded anomaly flags, per-agent streaming progress |
99
+ | 4 | Llama Champion | MiniCPM5-1B served via llama-cpp-python (GGUF Q4_K_M) for both Agent 2 and Agent 6 |
100
+ | 5 | Sharing is Caring | 11 Claude Code build sessions published at [`build-small-hackathon/kirana-detective-build-traces`](https://huggingface.co/datasets/build-small-hackathon/kirana-detective-build-traces) |
101
+ | 6 | Field Notes | Blog post at [huggingface.co/blog/build-small-hackathon/kirana-detective](https://huggingface.co/blog/build-small-hackathon/kirana-detective) |
102
+
103
+ Full sash. All badges earned independently, each with verifiable evidence.
104
+
105
+ **πŸ—³οΈ Community Choice** β€” Kirana Detective is built around a problem that 12 million Indian shopkeepers face every week. It is demonstrable to anyone who has ever received a bill they couldn't verify β€” which is most of the world. The live Space requires no setup, no account, and produces a tangible rupee number in under a minute. The blog post and X post are live for community sharing. Encouraging votes from the community.
106
+
107
+ ### Sponsor Awards
108
+
109
+ **OpenBMB ($10,000 pool)**
110
+
111
+ Both language models are from OpenBMB's MiniCPM family:
112
+ - MiniCPM-V 4.6 (`openbmb/MiniCPM-V-4.6`) β€” fine-tuned for Indian invoice extraction
113
+ - MiniCPM5-1B (`openbmb/MiniCPM5-1B`) β€” fine-tuned for FMCG product normalisation and report generation
114
+
115
+ Both are fine-tuned, pushed to HF Hub, and used in production in the Space. MiniCPM5-1B runs as GGUF via llama.cpp (cross-qualifying for Llama Champion badge).
116
+
117
+ **Modal ($20,000 in credits)**
118
+
119
+ All three models were trained on Modal A10G GPUs using Modal's `@app.function` decorator with GPU provisioning. Total compute: ~4.5 hours of A10G time, ~$5.80 total cost.
120
+
121
+ Training scripts in `finetune/`:
122
+ - `finetune/train_minicpm_v.py` β€” MiniCPM-V 4.6 fine-tuning (51 min, A10G)
123
+ - `finetune/train_minicpm5_1b.py` β€” MiniCPM5-1B fine-tuning (~1 hr, A10G)
124
+ - `finetune/train_yolo26n.py` β€” YOLO26n fine-tuning (~2 hrs, A10G)
125
+ - `finetune/generate_invoices.py` β€” synthetic invoice generation (Modal function)
126
+ - `finetune/export_minicpm_v_gguf.py` β€” LoRA merge + GGUF export (Modal function)
127
+
128
+ **NVIDIA**
129
+
130
+ YOLO26n is exported to ONNX and can leverage NVIDIA GPU acceleration via ONNX Runtime when available (falls back to CPU). The A10G GPU used for all training is NVIDIA hardware. ONNX Runtime GPU execution provider supports CUDA/TensorRT for deployment on NVIDIA hardware.
131
+
132
+ ---
133
+
134
+ ## Six-Agent Pipeline Summary
135
+
136
+ ```
137
+ Agent 1 β€” Invoice Extractor MiniCPM-V 4.6 (OpenBMB, fine-tuned) β†’ Structured JSON
138
+ Agent 2 β€” Product Matcher MiniCPM5-1B (OpenBMB, GGUF, llama.cpp) β†’ Canonical SKU names
139
+ Agent 3 β€” Pricing Agent Rule-based (SQLite history) β†’ Price / GST flags
140
+ Agent 4 β€” Visual Counter YOLO26n (ONNX Runtime) β†’ Product counts
141
+ Agent 5 β€” Reconciliation Agent Rule-based β†’ Shortage flags + β‚Ή loss
142
+ Agent 6 β€” Savings Agent MiniCPM5-1B (OpenBMB, GGUF, llama.cpp) β†’ β‚Ή report + actions
143
+ ```
144
+
145
+ ---
146
+
147
+ ## Constraints Met
148
+
149
+ | Constraint | Status |
150
+ |---|---|
151
+ | Models ≀ 32B parameters | βœ… ~2.38B total |
152
+ | Gradio UI | βœ… Custom Gradio 6.16 |
153
+ | Hosted as HF Space | βœ… [build-small-hackathon/kirana-detective](https://huggingface.co/spaces/build-small-hackathon/kirana-detective) |
154
+ | Demo video | βœ… [YouTube](https://youtu.be/8TVZP4sfesI) |
155
+ | Social media post | βœ… [X post](https://x.com/naazimhussain02/status/2065966381657633161) |
156
+
157
+ ---
158
+
159
+ ## Links
160
+
161
+ | Resource | URL |
162
+ |---|---|
163
+ | Space | https://huggingface.co/spaces/build-small-hackathon/kirana-detective |
164
+ | Blog | https://huggingface.co/blog/build-small-hackathon/kirana-detective |
165
+ | X Post | https://x.com/naazimhussain02/status/2065966381657633161 |
166
+ | Invoice Extractor | https://huggingface.co/build-small-hackathon/minicpm-v-4-6-indian-invoice-extraction-merged |
167
+ | Product Normalizer | https://huggingface.co/build-small-hackathon/minicpm5-1b-indian-fmcg-normalizer |
168
+ | Product Detector | https://huggingface.co/build-small-hackathon/yolo26n-indian-fmcg-detection |
169
+ | Training Dataset | https://huggingface.co/datasets/build-small-hackathon/kirana-invoice-train-data |
170
+ | Build Traces | https://huggingface.co/datasets/build-small-hackathon/kirana-detective-build-traces |
171
+ | GitHub | https://github.com/naazimsnh02/kirana-detective |
MODEL_CARD.md β†’ docs/MODEL_CARD.md RENAMED
File without changes
tracer.py CHANGED
@@ -114,22 +114,8 @@ class AgentTracer:
114
  # Persist to local SQLite first (fast, synchronous)
115
  storage.save_audit_run(audit_run_id, trace_json)
116
 
117
- # Then push to HF Hub with retries
118
- for attempt in range(MAX_RETRIES):
119
- try:
120
- self._publish_to_hf_hub(audit_run_id, entries)
121
- storage.mark_trace_published(audit_run_id)
122
- logger.info("Trace %s published to HF Hub", audit_run_id)
123
- return
124
- except Exception as e:
125
- wait = BACKOFF_BASE_SECONDS ** (attempt + 1)
126
- logger.warning(
127
- "Trace publish attempt %d/%d failed: %s β€” retrying in %ds",
128
- attempt + 1, MAX_RETRIES, e, wait,
129
- )
130
- time.sleep(wait)
131
-
132
- logger.error("Trace %s: all %d publish attempts failed; stored locally only", audit_run_id, MAX_RETRIES)
133
 
134
  def _publish_to_hf_hub(self, audit_run_id: str, entries: List[AgentTraceEntry]) -> None:
135
  from huggingface_hub import HfApi, CommitOperationAdd
 
114
  # Persist to local SQLite first (fast, synchronous)
115
  storage.save_audit_run(audit_run_id, trace_json)
116
 
117
+ # HF Hub publishing disabled β€” runtime trace dataset was not completed
118
+ logger.info("Trace %s stored locally (HF Hub publishing disabled)", audit_run_id)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
119
 
120
  def _publish_to_hf_hub(self, audit_run_id: str, entries: List[AgentTraceEntry]) -> None:
121
  from huggingface_hub import HfApi, CommitOperationAdd