yesyanyan commited on
Commit
eacd656
·
verified ·
1 Parent(s): 4c38fbe

Update showcase

Browse files
README.md CHANGED
@@ -1,10 +1,21 @@
1
  ---
2
- title: Doc2sheet
3
- emoji: 📈
4
- colorFrom: purple
5
- colorTo: yellow
6
  sdk: static
 
7
  pinned: false
 
 
 
 
 
 
 
8
  ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
1
  ---
2
+ title: Doc2Sheet
3
+ emoji: 🧾
4
+ colorFrom: green
5
+ colorTo: blue
6
  sdk: static
7
+ app_file: index.html
8
  pinned: false
9
+ license: mit
10
+ short_description: Invoices & receipts → validated spreadsheet (vision LLM)
11
+ tags:
12
+ - document-ai
13
+ - invoice
14
+ - ocr
15
+ - automation
16
  ---
17
 
18
+ # Doc2Sheet
19
+
20
+ Recorded results of Doc2Sheet on four sample documents. Source code, CLI and the Gradio app:
21
+ https://github.com/yesyesyanyan/doc2sheet
assets/invoice_harbor_vine_scanned.jpg ADDED
assets/invoice_harbor_vine_scanned_thumb.jpg ADDED
assets/invoice_kestrel_total_error.jpg ADDED
assets/invoice_kestrel_total_error_thumb.jpg ADDED
assets/invoice_pixel_pine_eur.jpg ADDED
assets/invoice_pixel_pine_eur_thumb.jpg ADDED
assets/receipt_blue_heron_photo.jpg ADDED
assets/receipt_blue_heron_photo_thumb.jpg ADDED
index.html CHANGED
@@ -1,19 +1,342 @@
1
  <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  </html>
 
1
  <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1">
6
+ <title>Doc2Sheet — invoice & receipt extraction</title>
7
+ <meta name="description" content="Invoices and receipts to validated spreadsheet rows with a vision LLM and deterministic checks. Real results on four sample documents.">
8
+ <style>
9
+ :root {
10
+ --bg: #f7f8f7;
11
+ --surface: #ffffff;
12
+ --surface-2: #f1f3f2;
13
+ --text: #16201c;
14
+ --muted: #5b6863;
15
+ --line: #dfe5e2;
16
+ --accent: #0f7a5a;
17
+ --accent-soft: #e2f3ec;
18
+ --ok: #157347;
19
+ --ok-soft: #e3f4ea;
20
+ --warn: #9a5b00;
21
+ --warn-soft: #fff1d6;
22
+ --bad: #b3261e;
23
+ --bad-soft: #fde3e1;
24
+ --code-bg: #0f1a16;
25
+ --code-text: #d7efe5;
26
+ --shadow: 0 1px 2px rgba(16, 32, 28, .06), 0 8px 24px rgba(16, 32, 28, .06);
27
+ }
28
+ @media (prefers-color-scheme: dark) {
29
+ :root {
30
+ --bg: #0e1412;
31
+ --surface: #151d1a;
32
+ --surface-2: #1b2521;
33
+ --text: #e6eeea;
34
+ --muted: #9aaaa3;
35
+ --line: #26332e;
36
+ --accent: #3fc796;
37
+ --accent-soft: #163128;
38
+ --ok: #54d18f;
39
+ --ok-soft: #14301f;
40
+ --warn: #f2b84b;
41
+ --warn-soft: #3a2c10;
42
+ --bad: #ff8a80;
43
+ --bad-soft: #3b1a18;
44
+ --code-bg: #0a0f0d;
45
+ --code-text: #cfe9de;
46
+ --shadow: none;
47
+ }
48
+ }
49
+ * { box-sizing: border-box; }
50
+ html { -webkit-text-size-adjust: 100%; }
51
+ body {
52
+ margin: 0;
53
+ background: var(--bg);
54
+ color: var(--text);
55
+ font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
56
+ }
57
+ a { color: var(--accent); }
58
+ .wrap { max-width: 1080px; margin: 0 auto; padding: 0 16px; }
59
+
60
+ /* Hero */
61
+ .hero { padding: 56px 0 28px; }
62
+ .eyebrow { font-size: 13px; font-weight: 600; letter-spacing: .06em; text-transform: uppercase; color: var(--accent); }
63
+ h1 { font-size: clamp(34px, 6vw, 52px); line-height: 1.05; margin: 10px 0 14px; letter-spacing: -.02em; }
64
+ .lede { font-size: clamp(17px, 2.2vw, 20px); color: var(--muted); max-width: 720px; margin: 0 0 22px; }
65
+ .lede strong { color: var(--text); }
66
+ .cta { display: flex; flex-wrap: wrap; gap: 10px; }
67
+ .btn {
68
+ display: inline-flex; align-items: center; gap: 8px; padding: 10px 16px; border-radius: 10px;
69
+ border: 1px solid var(--line); background: var(--surface); color: var(--text);
70
+ font-weight: 600; text-decoration: none; font-size: 15px;
71
+ }
72
+ .btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
73
+ @media (prefers-color-scheme: dark) { .btn.primary { color: #06140f; } }
74
+ .btn:hover { filter: brightness(1.05); }
75
+ .note {
76
+ margin: 22px 0 0; padding: 10px 14px; border-left: 3px solid var(--accent); background: var(--accent-soft);
77
+ border-radius: 0 8px 8px 0; font-size: 14px; color: var(--text); max-width: 760px;
78
+ }
79
+
80
+ /* Stats */
81
+ .stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin: 8px 0 28px; }
82
+ .stat { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; }
83
+ .stat b { display: block; font-size: 26px; line-height: 1.1; font-variant-numeric: tabular-nums; }
84
+ .stat span { font-size: 13px; color: var(--muted); }
85
+ @media (max-width: 720px) { .stats { grid-template-columns: repeat(2, 1fr); } }
86
+
87
+ /* Explorer */
88
+ h2 { font-size: 22px; margin: 0 0 6px; letter-spacing: -.01em; }
89
+ .section { margin: 0 0 44px; }
90
+ .section > p.sub { color: var(--muted); margin: 0 0 16px; }
91
+ .tabs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 14px; }
92
+ @media (max-width: 820px) { .tabs { grid-template-columns: repeat(2, 1fr); } }
93
+ .tab {
94
+ text-align: left; display: flex; gap: 10px; align-items: center; padding: 8px; border-radius: 12px;
95
+ border: 1px solid var(--line); background: var(--surface); color: var(--text); cursor: pointer; font: inherit; min-width: 0;
96
+ }
97
+ .tab[aria-selected="true"] { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
98
+ .tab img { width: 44px; height: 56px; object-fit: cover; object-position: top; border-radius: 6px; border: 1px solid var(--line); flex: none; background: #fff; }
99
+ .tab .t { min-width: 0; }
100
+ .tab .name { font-size: 13px; font-weight: 600; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
101
+ .pill { display: inline-block; font-size: 11.5px; font-weight: 700; padding: 1px 8px; border-radius: 99px; margin-top: 3px; text-transform: uppercase; letter-spacing: .03em; }
102
+ .pill.ok { background: var(--ok-soft); color: var(--ok); }
103
+ .pill.review { background: var(--warn-soft); color: var(--warn); }
104
+ .pill.failed { background: var(--bad-soft); color: var(--bad); }
105
+
106
+ .panel {
107
+ display: grid; grid-template-columns: minmax(0, 5fr) minmax(0, 7fr); gap: 0;
108
+ background: var(--surface); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; box-shadow: var(--shadow);
109
+ }
110
+ @media (max-width: 820px) { .panel { grid-template-columns: 1fr; } }
111
+ .doc { margin: 0; background: var(--surface-2); padding: 16px; display: flex; flex-direction: column; gap: 10px; border-right: 1px solid var(--line); }
112
+ @media (max-width: 820px) { .doc { border-right: 0; border-bottom: 1px solid var(--line); } }
113
+ .doc a { display: block; }
114
+ .doc img { width: 100%; height: auto; max-height: 560px; object-fit: contain; border-radius: 8px; background: #fff; border: 1px solid var(--line); }
115
+ .doc figcaption { font-size: 13px; color: var(--muted); }
116
+ .data { padding: 18px 20px 20px; min-width: 0; }
117
+ .verdict { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 10px; font-size: 14.5px; margin-bottom: 16px; }
118
+ .verdict.ok { background: var(--ok-soft); color: var(--ok); }
119
+ .verdict.review { background: var(--warn-soft); color: var(--warn); }
120
+ .verdict.failed { background: var(--bad-soft); color: var(--bad); }
121
+ .verdict .icon { font-weight: 800; flex: none; }
122
+ .verdict .msg { color: var(--text); }
123
+ .verdict .msg b { color: inherit; }
124
+ .fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 18px; margin: 0 0 16px; }
125
+ .fields div { min-width: 0; }
126
+ .fields dt { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
127
+ .fields dd { margin: 1px 0 0; font-weight: 600; overflow-wrap: anywhere; }
128
+ .fields dd.none { color: var(--muted); font-weight: 400; }
129
+ .tablewrap { overflow-x: auto; margin: 0 0 12px; }
130
+ table { width: 100%; border-collapse: collapse; font-size: 14px; }
131
+ th, td { padding: 7px 8px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
132
+ th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
133
+ td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
134
+ td.muted { color: var(--muted); }
135
+ .totals { margin-left: auto; max-width: 340px; }
136
+ .totals td { border-bottom: 0; padding: 4px 8px; }
137
+ .totals tr.grand td { border-top: 1px solid var(--line); font-weight: 800; padding-top: 8px; }
138
+ .totals tr.flag td { color: var(--bad); }
139
+ details { margin-top: 12px; }
140
+ summary { cursor: pointer; color: var(--muted); font-size: 14px; }
141
+ pre { background: var(--code-bg); color: var(--code-text); padding: 14px; border-radius: 10px; overflow: auto; font-size: 12.5px; line-height: 1.5; }
142
+ .meta { font-size: 12.5px; color: var(--muted); margin-top: 10px; }
143
+
144
+ /* How it works */
145
+ .steps { display: grid; grid-template-columns: repeat(5, 1fr); gap: 10px; counter-reset: s; }
146
+ @media (max-width: 900px) { .steps { grid-template-columns: 1fr; } }
147
+ .step { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 14px; position: relative; }
148
+ .step::before { counter-increment: s; content: counter(s); display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); font-weight: 800; font-size: 13px; margin-bottom: 8px; }
149
+ .step b { display: block; margin-bottom: 4px; }
150
+ .step span { font-size: 14px; color: var(--muted); }
151
+
152
+ .checks { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
153
+ @media (max-width: 720px) { .checks { grid-template-columns: 1fr; } }
154
+ .check { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; font-size: 14.5px; }
155
+ .check code { font-size: 12.5px; color: var(--accent); }
156
+ .check p { margin: 4px 0 0; color: var(--muted); }
157
+
158
+ .run pre { margin: 0 0 12px; }
159
+ .run p { color: var(--muted); }
160
+ footer { border-top: 1px solid var(--line); padding: 22px 0 40px; color: var(--muted); font-size: 14px; }
161
+ footer a { color: inherit; }
162
+ </style>
163
+ </head>
164
+ <body>
165
+ <main class="wrap">
166
+ <header class="hero">
167
+ <div class="eyebrow">Portfolio project · document automation</div>
168
+ <h1>Doc2Sheet</h1>
169
+ <p class="lede">Turn invoices and receipts (PDFs, scans, phone photos) into clean spreadsheet rows.
170
+ A vision LLM reads each document, and <strong>deterministic checks re-do the arithmetic</strong>, so a wrong
171
+ total gets flagged instead of slipping into your books.</p>
172
+ <div class="cta">
173
+ <a class="btn primary" id="gh" href="#">View the code on GitHub</a>
174
+ <a class="btn" href="#run">Run it yourself</a>
175
+ </div>
176
+ <p class="note" id="provenance"></p>
177
+ </header>
178
+
179
+ <section class="stats" id="stats" aria-label="Summary"></section>
180
+
181
+ <section class="section" aria-labelledby="results-h">
182
+ <h2 id="results-h">Real results on four sample documents</h2>
183
+ <p class="sub">Pick a document to see what was extracted and what the checks said. All four samples are fictional.</p>
184
+ <div class="tabs" id="tabs" role="tablist" aria-label="Sample documents"></div>
185
+ <div class="panel" id="panel" role="tabpanel"></div>
186
+ </section>
187
+
188
+ <section class="section" aria-labelledby="how-h">
189
+ <h2 id="how-h">How it works</h2>
190
+ <p class="sub">One model call per document, surrounded by plain code that doesn't trust the model.</p>
191
+ <div class="steps">
192
+ <div class="step"><b>Load</b><span>PDF pages are rendered to images; a digital PDF's text layer is kept too.</span></div>
193
+ <div class="step"><b>Read</b><span>Any OpenAI-compatible vision model returns JSON against a strict schema.</span></div>
194
+ <div class="step"><b>Validate</b><span>Pydantic parses money and dates (1.234,50 € · 01.09.2026). Malformed output gets one repair round.</span></div>
195
+ <div class="step"><b>Check</b><span>Line maths, items vs subtotal, subtotal − discount + charges + tax = total, dates, currency.</span></div>
196
+ <div class="step"><b>Export</b><span>Colour-coded Excel (Documents · Line items · Issues), CSV and JSON.</span></div>
197
+ </div>
198
+ </section>
199
+
200
+ <section class="section" aria-labelledby="checks-h">
201
+ <h2 id="checks-h">What the checks catch</h2>
202
+ <p class="sub">Each document ends up <span class="pill ok">ok</span>, <span class="pill review">review</span> or <span class="pill failed">failed</span>.</p>
203
+ <div class="checks">
204
+ <div class="check"><code>total_mismatch</code><p>Subtotal, discount, charges and tax don't add up to the printed total. Tax-inclusive pricing is recognised.</p></div>
205
+ <div class="check"><code>line_math</code> · <code>items_vs_subtotal</code><p>A quantity × unit price that doesn't match its line, or lines that don't sum to the subtotal.</p></div>
206
+ <div class="check"><code>due_before_issue</code> · <code>future_date</code><p>Impossible dates. Ambiguous ones like 05/03/2026 are refused rather than guessed.</p></div>
207
+ <div class="check"><code>missing_*</code> · <code>invalid_currency</code><p>No total, vendor, date or ISO currency code, so a person should take a look.</p></div>
208
+ </div>
209
+ </section>
210
+
211
+ <section class="section run" id="run" aria-labelledby="run-h">
212
+ <h2 id="run-h">Run it yourself</h2>
213
+ <p class="sub">Web UI, batch CLI and Python API. Works with Hugging Face Inference Providers, OpenAI, Gemini, OpenRouter, or fully offline with Ollama.</p>
214
+ <pre><code>git clone <span id="clone"></span>
215
+ cd doc2sheet
216
+ pip install -e ".[app]"
217
+ # put HF_TOKEN=hf_... in .env (or point DOC2SHEET_BASE_URL at Ollama)
218
+ python app.py # web UI on http://127.0.0.1:7860
219
+ python -m doc2sheet invoices/ -o results.xlsx # a whole folder → one workbook</code></pre>
220
+ <p>Hosting a live Gradio demo on Hugging Face now requires a paid plan, so this page shows recorded results instead.</p>
221
+ </section>
222
+
223
+ <footer>
224
+ Built by <a id="author" href="#">yesyesyanyan</a> · MIT licence · <a id="gh2" href="#">source &amp; docs</a>
225
+ </footer>
226
+ </main>
227
+
228
+ <script id="data" type="application/json">{"model": "google/gemma-4-31B-it", "recorded": "27 Sep 2026", "github": "https://github.com/yesyesyanyan/doc2sheet", "author_url": "https://github.com/yesyesyanyan", "results": [{"source": "invoice_pixel_pine_eur.pdf", "document": {"document_type": "invoice", "vendor_name": "Pixel & Pine Design Studio SARL", "vendor_address": "14 Rue des Exemples\n69002 Lyon, France", "vendor_tax_id": "FR00999999999", "customer_name": "Maple Street Bakery Ltd", "document_number": "INV-2026-0142", "issue_date": "2026-09-01", "due_date": "2026-10-01", "currency": "EUR", "subtotal": 2575.0, "discount": null, "other_charges": null, "tax": 515.0, "total": 3090.0, "line_items": [{"description": "Brand identity workshop (half day)", "quantity": 1.0, "unit_price": 850.0, "amount": 850.0}, {"description": "Logo design - 3 concepts, 2 revisions", "quantity": 1.0, "unit_price": 1200.0, "amount": 1200.0}, {"description": "Business card layout", "quantity": 2.0, "unit_price": 150.0, "amount": 300.0}, {"description": "Social media templates", "quantity": 5.0, "unit_price": 45.0, "amount": 225.0}]}, "issues": [], "model": "google/gemma-4-31B-it", "pages": 1, "elapsed_seconds": 42.09, "error": null, "status": "ok"}, {"source": "invoice_harbor_vine_scanned.pdf", "document": {"document_type": "invoice", "vendor_name": "Harbor & Vine Catering Pty Ltd", "vendor_address": "3/18 Example Wharf\nSydney NSW 2000, Australia", "vendor_tax_id": "00 000 000 000", "customer_name": "Lumen Analytics", "document_number": "1045", "issue_date": "2026-07-22", "due_date": "2026-08-05", "currency": "AUD", "subtotal": 630.0, "discount": null, "other_charges": 35.0, "tax": 66.5, "total": 731.5, "line_items": [{"description": "Canape platter (serves 20)", "quantity": 3.0, "unit_price": 120.0, "amount": 360.0}, {"description": "Event staff (hours)", "quantity": 6.0, "unit_price": 45.0, "amount": 270.0}]}, "issues": [], "model": "google/gemma-4-31B-it", "pages": 1, "elapsed_seconds": 48.7, "error": null, "status": "ok"}, {"source": "receipt_blue_heron_photo.png", "document": {"document_type": "receipt", "vendor_name": "BLUE HERON COFFEE CO.", "vendor_address": "400 Example Ave, Seattle WA", "vendor_tax_id": null, "customer_name": null, "document_number": "A-3317", "issue_date": "2026-09-14", "due_date": null, "currency": "USD", "subtotal": 27.75, "discount": null, "other_charges": 4.0, "tax": 2.87, "total": 34.62, "line_items": [{"description": "Oat Latte", "quantity": 2.0, "unit_price": null, "amount": 10.5}, {"description": "Blueberry Scone", "quantity": 1.0, "unit_price": 3.75, "amount": 3.75}, {"description": "Cold Brew", "quantity": 1.0, "unit_price": 4.5, "amount": 4.5}, {"description": "Avocado Toast", "quantity": 1.0, "unit_price": 9.0, "amount": 9.0}]}, "issues": [], "model": "google/gemma-4-31B-it", "pages": 1, "elapsed_seconds": 29.13, "error": null, "status": "ok"}, {"source": "invoice_kestrel_total_error.pdf", "document": {"document_type": "invoice", "vendor_name": "Kestrel Logistics Ltd", "vendor_address": "Unit 4, Example Trading Estate\nManchester M00 0AA, United Kingdom", "vendor_tax_id": "GB000000000", "customer_name": "Oakridge Garden Supplies", "document_number": "KL-88213", "issue_date": "2026-08-12", "due_date": "2026-09-11", "currency": "GBP", "subtotal": 383.4, "discount": null, "other_charges": null, "tax": 76.68, "total": 469.08, "line_items": [{"description": "Pallet freight Manchester -> Leeds", "quantity": 4.0, "unit_price": 85.0, "amount": 340.0}, {"description": "Tail-lift surcharge", "quantity": 1.0, "unit_price": 25.0, "amount": 25.0}, {"description": "Fuel surcharge", "quantity": 1.0, "unit_price": 18.4, "amount": 18.4}]}, "issues": [{"level": "error", "code": "total_mismatch", "message": "Totals don't add up: subtotal 383.40 + tax 76.68 = 460.08, but the document total is 469.08.", "field": "total"}], "model": "google/gemma-4-31B-it", "pages": 1, "elapsed_seconds": 20.24, "error": null, "status": "review"}], "samples": {"invoice_pixel_pine_eur.pdf": {"title": "Studio invoice · EUR", "note": "Digital PDF with European formatting: 2 575,00 € and dd.mm.yyyy dates.", "image": "assets/invoice_pixel_pine_eur.jpg", "thumb": "assets/invoice_pixel_pine_eur_thumb.jpg"}, "invoice_harbor_vine_scanned.pdf": {"title": "Scanned invoice · AUD", "note": "Image-only scan, slightly rotated, with no text layer. Delivery is a separate charge plus 10% GST.", "image": "assets/invoice_harbor_vine_scanned.jpg", "thumb": "assets/invoice_harbor_vine_scanned_thumb.jpg"}, "receipt_blue_heron_photo.png": {"title": "Receipt photo · USD", "note": "Phone photo of a till receipt, with sales tax and a tip. '2 x Oat Latte $10.50' is a line total.", "image": "assets/receipt_blue_heron_photo.jpg", "thumb": "assets/receipt_blue_heron_photo_thumb.jpg"}, "invoice_kestrel_total_error.pdf": {"title": "Wrong total · GBP", "note": "Built with a deliberate £9.00 error in the printed total. The model copies it faithfully and the check catches it.", "image": "assets/invoice_kestrel_total_error.jpg", "thumb": "assets/invoice_kestrel_total_error_thumb.jpg"}}}</script>
229
+ <script>
230
+ (function () {
231
+ var DATA = JSON.parse(document.getElementById("data").textContent);
232
+ var R = DATA.results;
233
+ function esc(s) {
234
+ return String(s == null ? "" : s).replace(/[&<>"']/g, function (c) {
235
+ return { "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;" }[c];
236
+ });
237
+ }
238
+ function money(v, cur) {
239
+ if (v == null) return null;
240
+ try {
241
+ return new Intl.NumberFormat("en-GB", { style: "currency", currency: cur || "XXX", currencyDisplay: "code" }).format(v).replace("XXX", "").trim();
242
+ } catch (e) { return Number(v).toFixed(2); }
243
+ }
244
+ function num(v) { return v == null ? "" : Number(v).toLocaleString("en-GB", { maximumFractionDigits: 3 }); }
245
+ function amt(v) { return v == null ? "—" : Number(v).toLocaleString("en-GB", { minimumFractionDigits: 2, maximumFractionDigits: 3 }); }
246
+
247
+ // Links
248
+ ["gh", "gh2"].forEach(function (id) { document.getElementById(id).href = DATA.github; });
249
+ document.getElementById("author").href = DATA.author_url;
250
+ document.getElementById("clone").textContent = DATA.github + ".git";
251
+ document.getElementById("provenance").innerHTML =
252
+ "Everything below is <b>real output from <code>" + esc(DATA.model) + "</code></b> (via Hugging Face Inference Providers), recorded on " +
253
+ esc(DATA.recorded) + ". Nothing on this page calls a model; the page just displays that saved run.";
254
+
255
+ // Stats
256
+ var ok = R.filter(function (r) { return r.status === "ok"; }).length;
257
+ var review = R.filter(function (r) { return r.status === "review"; }).length;
258
+ var avg = R.reduce(function (a, r) { return a + (r.elapsed_seconds || 0); }, 0) / Math.max(R.length, 1);
259
+ document.getElementById("stats").innerHTML = [
260
+ [R.length, "documents: PDF, scan and photo"],
261
+ [ok, "passed every check"],
262
+ [review, "flagged for a human to review"],
263
+ [Math.round(avg) + " s", "average model time per document"]
264
+ ].map(function (s) { return '<div class="stat"><b>' + esc(s[0]) + "</b><span>" + esc(s[1]) + "</span></div>"; }).join("");
265
+
266
+ // Tabs
267
+ var tabs = document.getElementById("tabs");
268
+ tabs.innerHTML = R.map(function (r, i) {
269
+ var s = DATA.samples[r.source] || {};
270
+ return '<button class="tab" role="tab" id="tab-' + i + '" aria-controls="panel" aria-selected="false" data-i="' + i + '">' +
271
+ '<img src="' + esc(s.thumb) + '" alt="">' +
272
+ '<span class="t"><span class="name">' + esc(s.title || r.source) + '</span>' +
273
+ '<span class="pill ' + esc(r.status) + '">' + esc(r.status) + "</span></span></button>";
274
+ }).join("");
275
+
276
+ function field(label, value) {
277
+ var empty = value == null || value === "";
278
+ return "<div><dt>" + esc(label) + '</dt><dd class="' + (empty ? "none" : "") + '">' + (empty ? "not on document" : esc(value)) + "</dd></div>";
279
+ }
280
+
281
+ function render(i) {
282
+ var r = R[i], d = r.document || {}, s = DATA.samples[r.source] || {}, cur = d.currency;
283
+ Array.prototype.forEach.call(tabs.children, function (b, j) { b.setAttribute("aria-selected", String(i === j)); });
284
+ document.getElementById("panel").setAttribute("aria-labelledby", "tab-" + i);
285
+
286
+ var verdict;
287
+ if (r.status === "ok") {
288
+ verdict = '<div class="verdict ok"><span class="icon">✓</span><span class="msg"><b>All checks passed.</b> Totals, line maths, dates and currency are consistent.</span></div>';
289
+ } else if (r.status === "review") {
290
+ verdict = '<div class="verdict review"><span class="icon">!</span><span class="msg"><b>Needs review.</b> ' +
291
+ r.issues.map(function (x) { return esc(x.message); }).join("<br>") + "</span></div>";
292
+ } else {
293
+ verdict = '<div class="verdict failed"><span class="icon">×</span><span class="msg"><b>Failed.</b> ' + esc(r.error) + "</span></div>";
294
+ }
295
+
296
+ var flagged = r.issues.some(function (x) { return x.code === "total_mismatch"; });
297
+ var items = (d.line_items || []).map(function (it) {
298
+ return "<tr><td>" + esc(it.description) + '</td><td class="num">' + esc(num(it.quantity)) + '</td><td class="num ' + (it.unit_price == null ? "muted" : "") + '">' +
299
+ esc(amt(it.unit_price)) + '</td><td class="num">' + esc(amt(it.amount)) + "</td></tr>";
300
+ }).join("");
301
+ var totals = [["Subtotal", d.subtotal], ["Discount", d.discount], ["Other charges", d.other_charges], ["Tax", d.tax]]
302
+ .filter(function (t) { return t[1] != null; })
303
+ .map(function (t) { return "<tr><td>" + t[0] + '</td><td class="num">' + esc(money(t[1], cur)) + "</td></tr>"; }).join("") +
304
+ '<tr class="grand' + (flagged ? " flag" : "") + '"><td>Total</td><td class="num">' + esc(money(d.total, cur) || "—") + "</td></tr>";
305
+
306
+ var json = JSON.stringify({ status: r.status, document: d, issues: r.issues }, null, 2);
307
+
308
+ document.getElementById("panel").innerHTML =
309
+ '<figure class="doc"><a href="' + esc(s.image) + '" target="_blank" rel="noopener"><img src="' + esc(s.image) + '" alt="' + esc(s.title) + '"></a>' +
310
+ "<figcaption>" + esc(s.note) + "</figcaption></figure>" +
311
+ '<div class="data">' + verdict +
312
+ '<dl class="fields">' +
313
+ field("Vendor", d.vendor_name) + field("Customer", d.customer_name) +
314
+ field("Number", d.document_number) + field("Type", d.document_type) +
315
+ field("Issue date", d.issue_date) + field("Due date", d.due_date) +
316
+ field("Currency", d.currency) + field("Vendor tax ID", d.vendor_tax_id) +
317
+ "</dl>" +
318
+ '<div class="tablewrap"><table><thead><tr><th>Line item</th><th class="num">Qty</th><th class="num">Unit</th><th class="num">Amount</th></tr></thead><tbody>' +
319
+ items + "</tbody></table></div>" +
320
+ '<table class="totals"><tbody>' + totals + "</tbody></table>" +
321
+ "<details><summary>Show the JSON</summary><pre>" + esc(json) + "</pre></details>" +
322
+ '<div class="meta">' + esc(r.source) + " · " + esc(r.pages) + " page(s) · " + esc(r.elapsed_seconds) + " s · " + esc(r.model) + "</div>" +
323
+ "</div>";
324
+ }
325
+
326
+ tabs.addEventListener("click", function (e) {
327
+ var b = e.target.closest(".tab");
328
+ if (b) render(Number(b.getAttribute("data-i")));
329
+ });
330
+ tabs.addEventListener("keydown", function (e) {
331
+ var cur = Array.prototype.findIndex.call(tabs.children, function (b) { return b.getAttribute("aria-selected") === "true"; });
332
+ var next = e.key === "ArrowRight" ? cur + 1 : e.key === "ArrowLeft" ? cur - 1 : null;
333
+ if (next == null) return;
334
+ next = (next + R.length) % R.length;
335
+ render(next);
336
+ tabs.children[next].focus();
337
+ });
338
+ render(0);
339
+ })();
340
+ </script>
341
+ </body>
342
  </html>