davanstrien HF Staff commited on
Commit
6e0b466
·
verified ·
1 Parent(s): 41d7fc8

Upload folder using huggingface_hub

Browse files
Files changed (2) hide show
  1. app.py +11 -4
  2. index.html +285 -193
app.py CHANGED
@@ -156,10 +156,11 @@ app = Server()
156
 
157
  @app.api(name="run_diffusiongemma")
158
  @spaces.GPU(duration=90, size="xlarge")
159
- def run_diffusiongemma(ocr_text: str, canvas_init: bool = False) -> dict:
160
  """Correct OCR text with DiffusionGemma. canvas_init=True seeds the first
161
  denoising canvas with the OCR text itself (experimental — under-corrects;
162
- see the results tab) instead of random noise."""
 
163
  if err := _validate(ocr_text):
164
  return {"error": err}
165
  inputs = _prepare_inputs(dg_processor, dg_model, ocr_text)
@@ -183,6 +184,7 @@ def run_diffusiongemma(ocr_text: str, canvas_init: bool = False) -> dict:
183
  return {
184
  "text": text,
185
  "diff": diff_segments(ocr_text.strip(), text),
 
186
  "seconds": round(seconds, 2),
187
  "tokens_per_second": round(n_tokens / seconds, 1),
188
  "denoising_steps": len(streamer.snapshots),
@@ -194,7 +196,7 @@ def run_diffusiongemma(ocr_text: str, canvas_init: bool = False) -> dict:
194
 
195
  @app.api(name="run_gemma4")
196
  @spaces.GPU(duration=60, size="xlarge")
197
- def run_gemma4(ocr_text: str) -> dict:
198
  """Correct OCR text with the autoregressive Gemma-4-E4B baseline (greedy)."""
199
  if err := _validate(ocr_text):
200
  return {"error": err}
@@ -208,6 +210,7 @@ def run_gemma4(ocr_text: str) -> dict:
208
  return {
209
  "text": text,
210
  "diff": diff_segments(ocr_text.strip(), text),
 
211
  "seconds": round(seconds, 2),
212
  "tokens_per_second": round(n_tokens / seconds, 1),
213
  "error": None,
@@ -225,18 +228,22 @@ async def homepage():
225
  @app.get("/data/examples")
226
  async def get_examples():
227
  examples = json.loads((HERE / "examples.json").read_text())
228
- cached = {}
229
  cached_path = HERE / "examples_cached.json"
230
  if cached_path.exists():
231
  for e in json.loads(cached_path.read_text()):
232
  for m, out in e["output"].items():
233
  out.pop("_raw", None)
234
  cached[e["id"]] = e["output"]
 
235
  for e in examples:
236
  e["cached"] = cached.get(e["id"])
 
237
  if e["cached"]:
238
  for m, out in e["cached"].items():
239
  out["diff"] = diff_segments(e["ocr_input"].strip(), out["text"])
 
 
240
  return JSONResponse(examples)
241
 
242
 
 
156
 
157
  @app.api(name="run_diffusiongemma")
158
  @spaces.GPU(duration=90, size="xlarge")
159
+ def run_diffusiongemma(ocr_text: str, canvas_init: bool = False, gold: str = "") -> dict:
160
  """Correct OCR text with DiffusionGemma. canvas_init=True seeds the first
161
  denoising canvas with the OCR text itself (experimental — under-corrects;
162
+ see the results tab) instead of random noise. If a gold transcription is
163
+ supplied (demo examples), a diff against it is returned too."""
164
  if err := _validate(ocr_text):
165
  return {"error": err}
166
  inputs = _prepare_inputs(dg_processor, dg_model, ocr_text)
 
184
  return {
185
  "text": text,
186
  "diff": diff_segments(ocr_text.strip(), text),
187
+ "diff_gold": diff_segments(gold.strip(), text) if gold.strip() else None,
188
  "seconds": round(seconds, 2),
189
  "tokens_per_second": round(n_tokens / seconds, 1),
190
  "denoising_steps": len(streamer.snapshots),
 
196
 
197
  @app.api(name="run_gemma4")
198
  @spaces.GPU(duration=60, size="xlarge")
199
+ def run_gemma4(ocr_text: str, gold: str = "") -> dict:
200
  """Correct OCR text with the autoregressive Gemma-4-E4B baseline (greedy)."""
201
  if err := _validate(ocr_text):
202
  return {"error": err}
 
210
  return {
211
  "text": text,
212
  "diff": diff_segments(ocr_text.strip(), text),
213
+ "diff_gold": diff_segments(gold.strip(), text) if gold.strip() else None,
214
  "seconds": round(seconds, 2),
215
  "tokens_per_second": round(n_tokens / seconds, 1),
216
  "error": None,
 
228
  @app.get("/data/examples")
229
  async def get_examples():
230
  examples = json.loads((HERE / "examples.json").read_text())
231
+ cached, golds = {}, {}
232
  cached_path = HERE / "examples_cached.json"
233
  if cached_path.exists():
234
  for e in json.loads(cached_path.read_text()):
235
  for m, out in e["output"].items():
236
  out.pop("_raw", None)
237
  cached[e["id"]] = e["output"]
238
+ golds[e["id"]] = e.get("gold", "")
239
  for e in examples:
240
  e["cached"] = cached.get(e["id"])
241
+ e["gold"] = golds.get(e["id"], "")
242
  if e["cached"]:
243
  for m, out in e["cached"].items():
244
  out["diff"] = diff_segments(e["ocr_input"].strip(), out["text"])
245
+ if e["gold"]:
246
+ out["diff_gold"] = diff_segments(e["gold"].strip(), out["text"])
247
  return JSONResponse(examples)
248
 
249
 
index.html CHANGED
@@ -19,118 +19,123 @@
19
  --ochre-edge: #a8842a;
20
  --green-ink: #2e5d34;
21
  --red-ink: #9c2b22;
22
- --col-gap: 2.5rem;
23
  }
24
  * { box-sizing: border-box; }
25
  html { background: #d9cdaf; }
26
  body {
27
- margin: 0 auto;
28
- max-width: 1180px;
29
- padding: 2.2rem 2.4rem 4rem;
30
  background:
31
- url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.05 0'/%3E%3C/filter%3E%3Crect width='180' height='180' filter='url(%23n)'/%3E%3C/svg%3E"),
32
  var(--paper);
33
  color: var(--ink);
34
  font-family: "Old Standard TT", "Iowan Old Style", Georgia, serif;
35
- font-size: 17px;
36
- line-height: 1.55;
37
- box-shadow: 0 0 60px rgba(0,0,0,.35);
38
- min-height: 100vh;
39
  }
40
 
41
  /* ---------- masthead ---------- */
42
- header { text-align: center; animation: settle .7s ease-out both; }
43
- .gazette-name {
44
- font-family: "UnifrakturCook", serif;
45
- font-size: clamp(2.4rem, 5.5vw, 4.2rem);
46
- margin: 0;
47
- letter-spacing: .01em;
48
- }
49
- .gazette-name .amp { color: var(--oxblood); }
50
  .dateline {
51
- display: flex; align-items: center; gap: 1rem;
52
- margin: .65rem 0 0;
53
- font-variant: small-caps; letter-spacing: .22em; font-size: .8rem; color: var(--ink-soft);
54
  }
55
  .dateline::before, .dateline::after { content: ""; flex: 1; border-top: 1px solid var(--rule); }
56
- .double-rule { border: 0; border-top: 3px double var(--rule); margin: .8rem 0 0; }
57
- .standfirst {
58
- max-width: 62ch; margin: 1.1rem auto 0; font-style: italic; color: var(--ink-soft); font-size: 1.02rem;
59
- }
60
  .standfirst a { color: var(--oxblood); }
61
 
62
- /* ---------- composing desk ---------- */
63
- .desk { margin-top: 2rem; animation: settle .7s .12s ease-out both; }
64
- .desk-head {
65
- font-variant: small-caps; letter-spacing: .3em; font-size: .78rem;
66
- color: var(--ink-soft); text-align: center; margin-bottom: .8rem;
67
- }
68
- .desk-head::before { content: "❧ "; color: var(--oxblood); }
69
- .desk-head::after { content: " ☙"; color: var(--oxblood); }
70
- .chips { display: flex; flex-wrap: wrap; gap: .5rem; justify-content: center; }
71
  .chip {
72
- font-family: inherit; font-size: .82rem; cursor: pointer;
73
- background: transparent; color: var(--ink);
74
- border: 1px solid var(--rule); border-radius: 0; padding: .3rem .7rem;
75
- transition: background .15s, color .15s;
76
  }
77
  .chip:hover { background: var(--ink); color: var(--paper); }
78
  .chip.active { background: var(--oxblood); color: var(--paper); border-color: var(--oxblood); }
79
  textarea {
80
- width: 100%; min-height: 9.5rem; margin-top: 1rem; padding: 1rem 1.1rem;
81
- font-family: "Special Elite", "Courier New", monospace; font-size: .92rem; line-height: 1.7;
82
  color: var(--ink); background: var(--paper-deep);
83
  border: 1px solid var(--rule); outline: none; resize: vertical;
84
- box-shadow: inset 0 1px 6px rgba(0,0,0,.12);
85
  }
86
  textarea:focus { border-color: var(--oxblood); }
87
- .controls { display: flex; flex-wrap: wrap; align-items: center; gap: 1.2rem; margin-top: .9rem; }
 
 
 
 
88
  .run-btn {
89
- font-family: inherit; font-variant: small-caps; letter-spacing: .18em; font-size: 1rem;
90
  background: var(--ink); color: var(--paper); border: 1px solid var(--ink);
91
- padding: .55rem 1.6rem; cursor: pointer; transition: background .15s, transform .05s;
92
  }
93
  .run-btn:hover { background: var(--oxblood); border-color: var(--oxblood); }
94
- .run-btn:active { transform: translateY(1px); }
95
  .run-btn[disabled] { opacity: .45; cursor: wait; }
96
- label.toggle {
97
- display: inline-flex; align-items: center; gap: .45rem; font-size: .88rem; color: var(--ink-soft); cursor: pointer;
98
- }
99
  label.toggle input { accent-color: var(--oxblood); }
100
- .toggle .tag {
101
- font-variant: small-caps; font-size: .68rem; letter-spacing: .12em;
102
- border: 1px solid var(--ochre-edge); color: var(--ochre-edge); padding: 0 .35rem;
103
- }
104
- .charcount { margin-left: auto; font-size: .78rem; color: var(--ink-soft); font-variant: small-caps; letter-spacing: .1em; }
105
  .charcount.over { color: var(--red-ink); }
106
 
107
- /* ---------- columns ---------- */
108
- .columns {
109
- display: grid; grid-template-columns: 1fr 1fr; gap: 0 var(--col-gap);
110
- margin-top: 2.4rem; position: relative; animation: settle .7s .22s ease-out both;
 
 
111
  }
112
- .columns::before {
113
- content: ""; position: absolute; top: 0; bottom: 0; left: 50%;
114
- border-left: 1px solid var(--rule);
 
 
 
 
 
 
115
  }
116
- @media (max-width: 760px) {
117
- .columns { grid-template-columns: 1fr; gap: 2.2rem; }
118
- .columns::before { display: none; }
 
 
 
119
  }
120
- .col-head { border-top: 3px double var(--rule); border-bottom: 1px solid var(--rule); padding: .45rem 0 .4rem; text-align: center; }
121
- .col-head h2 { margin: 0; font-size: 1.25rem; letter-spacing: .04em; font-weight: 700; }
122
- .col-head .col-sub { font-variant: small-caps; letter-spacing: .25em; font-size: .7rem; color: var(--ink-soft); }
123
- .col-head .col-sub a { color: inherit; text-decoration: none; border-bottom: 1px dotted var(--ink-soft); }
124
- .statline {
125
- display: flex; justify-content: center; gap: 1.6rem; padding: .55rem 0;
126
- border-bottom: 1px solid var(--rule); font-size: .8rem; font-variant: small-caps; letter-spacing: .08em;
127
- color: var(--ink-soft); min-height: 2.2rem; align-items: baseline;
 
 
 
 
 
 
 
 
128
  }
129
- .statline b { font-size: 1.25rem; color: var(--ink); font-variant: normal; letter-spacing: 0; }
130
- .statline .cached-tag { color: var(--oxblood); font-style: italic; font-variant: normal; letter-spacing: 0; }
131
- .proof {
132
- padding: 1rem .2rem 0; min-height: 8rem; font-size: 1rem; line-height: 1.75; word-wrap: break-word;
 
 
 
 
 
 
 
 
133
  }
 
 
 
134
  .proof .placeholder { color: var(--ink-soft); font-style: italic; opacity: .7; }
135
  .proof .spinner { font-style: italic; color: var(--oxblood); }
136
  .proof .spinner::after { content: ""; animation: dots 1.2s steps(4) infinite; }
@@ -138,48 +143,25 @@
138
  .seg-changed { background: var(--ochre-bg); border-bottom: 2px solid var(--ochre-edge); }
139
  .seg-added { color: var(--green-ink); border-bottom: 2px solid var(--green-ink); font-weight: 700; }
140
  .seg-removed { color: var(--red-ink); text-decoration: line-through; opacity: .75; }
141
- .error-box {
142
- border: 1px solid var(--red-ink); color: var(--red-ink); padding: .6rem .9rem; font-style: italic; margin-top: 1rem;
143
- }
144
-
145
- /* ---------- press (denoising scrubber) ---------- */
146
- .press { margin-top: 1.4rem; border-top: 1px solid var(--rule); padding-top: .8rem; display: none; }
147
- .press.visible { display: block; }
148
- .press .press-head { font-variant: small-caps; letter-spacing: .2em; font-size: .72rem; color: var(--ink-soft); display: flex; justify-content: space-between; }
149
- .press input[type=range] { width: 100%; accent-color: var(--oxblood); margin: .5rem 0; }
150
- .press .canvas-view {
151
- font-family: "Special Elite", monospace; font-size: .8rem; line-height: 1.65;
152
- background: var(--paper-deep); border: 1px dashed var(--rule);
153
- padding: .8rem .9rem; min-height: 5.5rem; max-height: 14rem; overflow-y: auto; white-space: pre-wrap;
154
- }
155
-
156
- /* ---------- legend ---------- */
157
- .legend { display: flex; gap: 1.6rem; justify-content: center; margin-top: 2rem; font-size: .8rem; color: var(--ink-soft); flex-wrap: wrap; }
158
- .legend span.swatch { padding: 0 .4rem; }
159
 
160
- /* ---------- results ---------- */
161
- .results { margin-top: 3rem; animation: settle .7s .3s ease-out both; }
162
- .section-head {
163
- text-align: center; border-top: 3px double var(--rule); padding-top: .6rem; margin-bottom: 1.1rem;
164
- }
165
- .section-head h2 { margin: 0; font-size: 1.45rem; letter-spacing: .03em; }
166
- .section-head .col-sub { font-variant: small-caps; letter-spacing: .25em; font-size: .72rem; color: var(--ink-soft); }
167
- table { border-collapse: collapse; margin: 0 auto; font-size: .92rem; }
168
- th, td { padding: .45rem .9rem; border-bottom: 1px solid #00000022; text-align: right; }
169
  th:first-child, td:first-child { text-align: left; }
170
- thead th { border-bottom: 2px solid var(--rule); font-variant: small-caps; letter-spacing: .06em; font-weight: 700; }
171
- tbody tr:first-child td { color: var(--ink-soft); font-style: italic; }
172
- tbody tr:nth-child(2) td:first-child::before { content: "★ "; color: var(--oxblood); }
173
- .footnotes { max-width: 75ch; margin: 1.3rem auto 0; font-size: .85rem; color: var(--ink-soft); }
 
 
174
  .footnotes p { margin: .3rem 0; }
175
 
176
- footer {
177
- margin-top: 3.5rem; border-top: 3px double var(--rule); padding-top: 1rem;
178
- text-align: center; font-size: .82rem; color: var(--ink-soft);
179
- }
180
  footer a { color: var(--oxblood); }
181
 
182
- @keyframes settle { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
183
  @media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
184
  </style>
185
  </head>
@@ -187,77 +169,95 @@
187
 
188
  <header>
189
  <h1 class="gazette-name">The Post‑OCR Gazette</h1>
190
- <div class="dateline"><span>Vol. I — Diffusion <span style="font-variant:normal">vs</span> Autoregression Price one GPU‑second</span></div>
191
  <hr class="double-rule" />
192
  <p class="standfirst">
193
- In which <a href="https://huggingface.co/google/diffusiongemma-26B-A4B-it">DiffusionGemma‑26B‑A4B</a>,
194
- an experimental block‑diffusion language model, and
195
- <a href="https://huggingface.co/google/gemma-4-E4B-it">Gemma‑4‑E4B</a>, its autoregressive cousin,
196
- are set against one another in the correction of nineteenth‑century newspaper OCR.
197
- Marks upon the proofs show what each model <em>changed</em> in your text.
198
  </p>
199
  </header>
200
 
201
  <section class="desk">
202
- <div class="desk-head">The Composing Desk</div>
203
  <div class="chips" id="chips"></div>
204
  <textarea id="ocr-input" spellcheck="false" placeholder="Paste noisy OCR text here, or pick a passage above…"></textarea>
 
 
 
 
205
  <div class="controls">
206
  <button class="run-btn" id="run">Correct the Proofs</button>
207
  <label class="toggle">
208
  <input type="checkbox" id="canvas-toggle" />
209
- seed canvas with OCR text <span class="tag">experimental — under‑corrects</span>
210
  </label>
211
  <span class="charcount" id="charcount"></span>
212
  </div>
213
  </section>
214
 
215
- <section class="columns">
216
- <div class="col" id="col-dg">
217
- <div class="col-head">
218
- <h2>The Diffusionist</h2>
219
- <div class="col-sub"><a href="https://huggingface.co/google/diffusiongemma-26B-A4B-it">DiffusionGemma‑26B‑A4B‑it</a> · denoises 256 tokens in parallel</div>
 
 
 
 
 
 
220
  </div>
221
- <div class="statline" id="stats-dg"><span class="placeholder">awaiting copy</span></div>
222
- <div class="proof" id="proof-dg"><span class="placeholder">The diffusion model’s corrected proof will appear here.</span></div>
223
- <div class="press" id="press">
224
- <div class="press-head"><span>The Press denoising, step by step</span><span id="press-step"></span></div>
225
- <input type="range" id="press-slider" min="0" max="0" value="0" step="1" />
226
- <div class="canvas-view" id="press-canvas"></div>
227
  </div>
 
 
 
 
 
 
 
 
228
  </div>
229
- <div class="col" id="col-g4">
230
- <div class="col-head">
231
- <h2>The Autoregressive</h2>
232
- <div class="col-sub"><a href="https://huggingface.co/google/gemma-4-E4B-it">Gemma‑4‑E4B‑it</a> · one token after another, greedily</div>
 
 
 
 
 
 
 
 
 
 
 
 
233
  </div>
234
- <div class="statline" id="stats-g4"><span class="placeholder">awaiting copy</span></div>
235
- <div class="proof" id="proof-g4"><span class="placeholder">The autoregressive model’s corrected proof will appear here.</span></div>
 
 
 
 
236
  </div>
237
  </section>
238
 
239
- <div class="legend">
240
- <span><span class="swatch seg-changed">changed</span> — altered from the input</span>
241
- <span><span class="swatch seg-added">added</span> — inserted text</span>
242
- <span><span class="swatch seg-removed">removed</span> — deleted from the input</span>
243
- </div>
244
-
245
- <section class="results">
246
- <div class="section-head">
247
- <h2>The Ledger</h2>
248
- <div class="col-sub">75 passages of BLN600 · A100‑80GB · full methodology in the repository</div>
249
- </div>
250
  <div id="results-table"><p style="text-align:center;font-style:italic">Fetching the ledger…</p></div>
251
  <div class="footnotes" id="results-notes"></div>
252
  </section>
253
 
254
  <footer>
255
  <p>
256
- Benchmark texts: <a href="https://doi.org/10.15131/shef.data.25439023">BLN600</a> (CC‑BY‑NC metrics only republished here).
257
- Demo passages: ICDAR2019 post‑OCR (CC‑BY‑4.0). DiffusionGemma is experimental and one day old at press time;
258
- its sampler has no greedy mode, so the comparison is defaults‑vs‑greedy. Single run, no significance testing.
259
  </p>
260
- <p>Set in Old Standard &amp; Special Elite · powered by ZeroGPU · by <a href="https://huggingface.co/davanstrien">davanstrien</a></p>
261
  </footer>
262
 
263
  <script type="module">
@@ -265,11 +265,21 @@ import { Client } from "https://cdn.jsdelivr.net/npm/@gradio/client/dist/index.m
265
 
266
  const $ = (id) => document.getElementById(id);
267
  const MAX_CHARS = 1200;
268
- let client = null, examples = [], activeExample = null, snapshots = [];
 
 
 
269
 
270
  const connect = (async () => { client = await Client.connect(window.location.origin); })();
271
 
272
- /* ---------- helpers ---------- */
 
 
 
 
 
 
 
273
  function renderDiff(el, segs) {
274
  el.innerHTML = "";
275
  for (const s of segs) {
@@ -279,6 +289,30 @@ function renderDiff(el, segs) {
279
  el.appendChild(span);
280
  }
281
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
282
  function stats(el, r, extra = "") {
283
  el.innerHTML = `<span><b>${r.seconds}</b> s</span><span><b>${r.tokens_per_second}</b> tok/s</span>` +
284
  (r.denoising_steps ? `<span><b>${r.denoising_steps}</b> steps</span>` : "") + extra;
@@ -286,22 +320,41 @@ function stats(el, r, extra = "") {
286
  function spinner(el, msg) { el.innerHTML = `<span class="spinner">${msg}</span>`; }
287
  function showError(el, msg) { el.innerHTML = `<div class="error-box">${msg}</div>`; }
288
 
289
- function showSnapshots(snaps) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
290
  snapshots = snaps || [];
291
- const press = $("press");
292
- if (!snapshots.length) { press.classList.remove("visible"); return; }
293
- press.classList.add("visible");
294
  const slider = $("press-slider");
295
- slider.max = snapshots.length - 1;
296
- slider.value = snapshots.length - 1;
297
- updatePress();
 
 
 
 
298
  }
299
- function updatePress() {
300
- const i = +$("press-slider").value;
301
- $("press-step").textContent = `step ${i + 1} of ${snapshots.length}`;
302
- $("press-canvas").textContent = snapshots[i] || "";
303
- }
304
- $("press-slider").addEventListener("input", updatePress);
305
 
306
  /* ---------- examples ---------- */
307
  async function loadExamples() {
@@ -317,6 +370,7 @@ async function loadExamples() {
317
  $("ocr-input").value = e.ocr_input;
318
  activeExample = e;
319
  updateCount();
 
320
  if (e.cached) renderCached(e);
321
  };
322
  chips.appendChild(b);
@@ -325,62 +379,81 @@ async function loadExamples() {
325
  }
326
  function renderCached(e) {
327
  const dg = e.cached.diffusiongemma, g4 = e.cached.gemma4;
328
- const tag = `<span class="cached-tag">— from the morning edition (pre‑computed)</span>`;
329
  if (dg) {
 
330
  stats($("stats-dg"), { seconds: dg.seconds, tokens_per_second: Math.round(dg.tokens_generated / dg.seconds), denoising_steps: dg.denoising_steps }, tag);
331
- renderDiff($("proof-dg"), dg.diff);
332
  }
333
  if (g4) {
 
334
  stats($("stats-g4"), { seconds: g4.seconds, tokens_per_second: Math.round(g4.tokens_generated / g4.seconds) }, tag);
335
- renderDiff($("proof-g4"), g4.diff);
336
  }
337
- showSnapshots([]);
 
 
 
 
338
  }
339
 
340
- /* ---------- character count ---------- */
341
  function updateCount() {
342
  const n = $("ocr-input").value.length;
343
  const el = $("charcount");
344
- el.textContent = `${n} / ${MAX_CHARS} characters`;
345
  el.classList.toggle("over", n > MAX_CHARS);
346
  }
347
- $("ocr-input").addEventListener("input", () => { activeExample = null; updateCount(); });
348
  updateCount();
349
 
350
  /* ---------- run ---------- */
351
  $("run").addEventListener("click", async () => {
352
  const text = $("ocr-input").value.trim();
353
  if (!text) return;
354
- if (text.length > MAX_CHARS) { showError($("proof-dg"), `Input too long (${text.length} chars; the cap is ${MAX_CHARS} — DiffusionGemma writes a single 256‑token block).`); return; }
 
 
 
 
355
  const btn = $("run");
356
  btn.disabled = true;
357
  await connect;
358
- spinner($("proof-dg"), "denoising the canvas"); $("stats-dg").innerHTML = "";
359
- spinner($("proof-g4"), "queued behind the diffusionist"); $("stats-g4").innerHTML = "";
360
- showSnapshots([]);
 
 
 
 
 
361
  try {
362
  const dg = (await client.predict("/run_diffusiongemma", {
363
- ocr_text: text, canvas_init: $("canvas-toggle").checked,
364
  })).data[0];
365
- if (dg.error) showError($("proof-dg"), dg.error);
366
  else {
 
367
  stats($("stats-dg"), dg, dg.canvas_init ? `<span class="cached-tag">— OCR‑seeded canvas</span>` : "");
368
- renderDiff($("proof-dg"), dg.diff);
369
- showSnapshots(dg.snapshots);
370
  }
371
- spinner($("proof-g4"), "composing, one token at a time");
372
- const g4 = (await client.predict("/run_gemma4", { ocr_text: text })).data[0];
373
  if (g4.error) showError($("proof-g4"), g4.error);
374
- else { stats($("stats-g4"), g4); renderDiff($("proof-g4"), g4.diff); }
375
  } catch (err) {
376
- showError($("proof-dg"), `The press has jammed: ${err.message || err}`);
377
- $("proof-g4").innerHTML = "";
378
  } finally {
379
  btn.disabled = false;
380
  }
381
  });
382
 
383
- /* ---------- results ledger ---------- */
 
 
 
 
 
 
 
384
  async function loadResults() {
385
  try {
386
  const res = await fetch("data/results");
@@ -391,16 +464,35 @@ async function loadResults() {
391
  const parse = (l) => l.split("|").slice(1, -1).map(c => c.trim());
392
  const head = parse(tableLines[0]);
393
  const rows = tableLines.slice(2).map(parse);
394
- let html = "<table><thead><tr>" + head.map(h => `<th>${h}</th>`).join("") + "</tr></thead><tbody>";
395
- for (const r of rows) html += "<tr>" + r.map(c => `<td>${c}</td>`).join("") + "</tr>";
396
- html += "</tbody></table>";
397
- $("results-table").innerHTML = html;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
398
  }
399
  const notes = lines.filter(l => /^(Micro|Mean)/.test(l)).map(l => `<p>${l}</p>`).join("");
400
  $("results-notes").innerHTML = notes +
401
- `<p>Over‑correction: of input characters already correct (vs the gold transcription), the share the model changed.
402
- Fix rate: of input characters that were wrong, the share the model changed.
403
- The OCR‑seeded‑canvas condition (toggle above) converges in 2–5 steps but barely edits a negative result, reported honestly.</p>`;
 
404
  } catch { $("results-table").innerHTML = "<p style='text-align:center;font-style:italic'>The ledger could not be fetched.</p>"; }
405
  }
406
 
 
19
  --ochre-edge: #a8842a;
20
  --green-ink: #2e5d34;
21
  --red-ink: #9c2b22;
 
22
  }
23
  * { box-sizing: border-box; }
24
  html { background: #d9cdaf; }
25
  body {
26
+ margin: 0 auto; max-width: 1080px; padding: 2rem 2.2rem 3.5rem;
 
 
27
  background:
28
+ url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.04 0'/%3E%3C/filter%3E%3Crect width='180' height='180' filter='url(%23n)'/%3E%3C/svg%3E"),
29
  var(--paper);
30
  color: var(--ink);
31
  font-family: "Old Standard TT", "Iowan Old Style", Georgia, serif;
32
+ font-size: 17px; line-height: 1.55;
33
+ box-shadow: 0 0 50px rgba(0,0,0,.3); min-height: 100vh;
 
 
34
  }
35
 
36
  /* ---------- masthead ---------- */
37
+ header { text-align: center; animation: settle .6s ease-out both; }
38
+ .gazette-name { font-family: "UnifrakturCook", serif; font-size: clamp(2.2rem, 5vw, 3.4rem); margin: 0; }
 
 
 
 
 
 
39
  .dateline {
40
+ display: flex; align-items: center; gap: 1rem; margin: .5rem 0 0;
41
+ font-variant: small-caps; letter-spacing: .2em; font-size: .78rem; color: var(--ink-soft);
 
42
  }
43
  .dateline::before, .dateline::after { content: ""; flex: 1; border-top: 1px solid var(--rule); }
44
+ .double-rule { border: 0; border-top: 3px double var(--rule); margin: .7rem 0 0; }
45
+ .standfirst { max-width: 60ch; margin: .9rem auto 0; font-style: italic; color: var(--ink-soft); font-size: .98rem; }
 
 
46
  .standfirst a { color: var(--oxblood); }
47
 
48
+ /* ---------- desk ---------- */
49
+ .desk { margin-top: 1.7rem; animation: settle .6s .1s ease-out both; }
50
+ .chips { display: flex; flex-wrap: wrap; gap: .45rem; justify-content: center; }
 
 
 
 
 
 
51
  .chip {
52
+ font-family: inherit; font-size: .8rem; cursor: pointer; background: transparent; color: var(--ink);
53
+ border: 1px solid var(--rule); padding: .28rem .65rem; transition: background .15s, color .15s;
 
 
54
  }
55
  .chip:hover { background: var(--ink); color: var(--paper); }
56
  .chip.active { background: var(--oxblood); color: var(--paper); border-color: var(--oxblood); }
57
  textarea {
58
+ width: 100%; min-height: 7.5rem; margin-top: .9rem; padding: .9rem 1rem;
59
+ font-family: "Special Elite", "Courier New", monospace; font-size: .9rem; line-height: 1.65;
60
  color: var(--ink); background: var(--paper-deep);
61
  border: 1px solid var(--rule); outline: none; resize: vertical;
62
+ box-shadow: inset 0 1px 5px rgba(0,0,0,.1);
63
  }
64
  textarea:focus { border-color: var(--oxblood); }
65
+ .authority { margin-top: .7rem; border: 1px solid var(--rule); background: var(--paper-deep); display: none; }
66
+ .authority.visible { display: block; }
67
+ .authority summary { cursor: pointer; padding: .4rem .8rem; font-variant: small-caps; letter-spacing: .15em; font-size: .76rem; color: var(--ink-soft); }
68
+ .authority .gold-text { padding: 0 1rem .7rem; font-size: .93rem; line-height: 1.65; }
69
+ .controls { display: flex; flex-wrap: wrap; align-items: center; gap: 1.1rem; margin-top: .8rem; }
70
  .run-btn {
71
+ font-family: inherit; font-variant: small-caps; letter-spacing: .15em; font-size: 1rem;
72
  background: var(--ink); color: var(--paper); border: 1px solid var(--ink);
73
+ padding: .5rem 1.5rem; cursor: pointer; transition: background .15s;
74
  }
75
  .run-btn:hover { background: var(--oxblood); border-color: var(--oxblood); }
 
76
  .run-btn[disabled] { opacity: .45; cursor: wait; }
77
+ label.toggle { display: inline-flex; align-items: center; gap: .4rem; font-size: .85rem; color: var(--ink-soft); cursor: pointer; }
 
 
78
  label.toggle input { accent-color: var(--oxblood); }
79
+ .charcount { margin-left: auto; font-size: .76rem; color: var(--ink-soft); }
 
 
 
 
80
  .charcount.over { color: var(--red-ink); }
81
 
82
+ /* ---------- tabs ---------- */
83
+ .tabs { display: flex; justify-content: center; gap: 0; margin-top: 2rem; border-bottom: 3px double var(--rule); animation: settle .6s .18s ease-out both; }
84
+ .tabs button {
85
+ font-family: inherit; font-variant: small-caps; letter-spacing: .14em; font-size: .92rem;
86
+ background: transparent; color: var(--ink-soft); border: 0; padding: .5rem 1.3rem; cursor: pointer;
87
+ border-bottom: 3px solid transparent; margin-bottom: -3px;
88
  }
89
+ .tabs button.active { color: var(--ink); border-bottom-color: var(--oxblood); font-weight: 700; }
90
+ .pane { display: none; padding-top: 1.5rem; }
91
+ .pane.active { display: block; }
92
+
93
+ /* ---------- the press (hero) ---------- */
94
+ .press-stage { max-width: 760px; margin: 0 auto; }
95
+ .press-status {
96
+ display: flex; justify-content: space-between; align-items: baseline;
97
+ font-variant: small-caps; letter-spacing: .15em; font-size: .78rem; color: var(--ink-soft); min-height: 1.6rem;
98
  }
99
+ .press-status b { font-size: 1.1rem; color: var(--oxblood); font-variant: normal; letter-spacing: 0; }
100
+ .press-canvas {
101
+ margin-top: .5rem; padding: 1.1rem 1.2rem; min-height: 11rem;
102
+ background: var(--paper-deep); border: 1px solid var(--rule);
103
+ font-size: 1rem; line-height: 1.8; white-space: pre-wrap; word-wrap: break-word;
104
+ box-shadow: inset 0 1px 6px rgba(0,0,0,.08);
105
  }
106
+ .press-canvas.settling { font-family: "Special Elite", monospace; font-size: .88rem; }
107
+ .press-canvas .placeholder { color: var(--ink-soft); font-style: italic; opacity: .75; }
108
+ .press-controls { display: flex; align-items: center; gap: .9rem; margin-top: .6rem; }
109
+ .press-controls input[type=range] { flex: 1; accent-color: var(--oxblood); }
110
+ .press-controls button {
111
+ font-family: inherit; background: transparent; border: 1px solid var(--rule); cursor: pointer;
112
+ font-size: .8rem; padding: .2rem .7rem;
113
+ }
114
+ .press-stats { text-align: center; margin-top: .8rem; font-size: .85rem; color: var(--ink-soft); min-height: 1.4rem; }
115
+ .press-stats b { color: var(--ink); font-size: 1.05rem; }
116
+
117
+ /* ---------- comparison ---------- */
118
+ .mode-switch { display: flex; justify-content: center; margin-bottom: 1.2rem; }
119
+ .mode-switch button {
120
+ font-family: inherit; font-variant: small-caps; letter-spacing: .1em; font-size: .76rem;
121
+ background: transparent; color: var(--ink); border: 1px solid var(--rule); padding: .28rem .8rem; cursor: pointer;
122
  }
123
+ .mode-switch button.active { background: var(--ink); color: var(--paper); }
124
+ .mode-switch button[disabled] { opacity: .4; cursor: not-allowed; }
125
+ .columns { display: grid; grid-template-columns: 1fr 1fr; gap: 0 2.4rem; position: relative; }
126
+ .columns::before { content: ""; position: absolute; top: 0; bottom: 0; left: 50%; border-left: 1px solid var(--rule); }
127
+ @media (max-width: 720px) { .columns { grid-template-columns: 1fr; gap: 2rem; } .columns::before { display: none; } }
128
+ .col-head { border-bottom: 1px solid var(--rule); padding-bottom: .35rem; text-align: center; }
129
+ .col-head h2 { margin: 0; font-size: 1.15rem; }
130
+ .col-head .col-sub { font-size: .74rem; color: var(--ink-soft); }
131
+ .col-head .col-sub a { color: inherit; }
132
+ .statline {
133
+ display: flex; justify-content: center; gap: 1.4rem; padding: .5rem 0; border-bottom: 1px solid var(--rule);
134
+ font-size: .78rem; color: var(--ink-soft); min-height: 2rem; align-items: baseline;
135
  }
136
+ .statline b { font-size: 1.15rem; color: var(--ink); }
137
+ .statline .cached-tag { color: var(--oxblood); font-style: italic; }
138
+ .proof { padding: .9rem .1rem 0; min-height: 7rem; font-size: .98rem; line-height: 1.75; word-wrap: break-word; }
139
  .proof .placeholder { color: var(--ink-soft); font-style: italic; opacity: .7; }
140
  .proof .spinner { font-style: italic; color: var(--oxblood); }
141
  .proof .spinner::after { content: ""; animation: dots 1.2s steps(4) infinite; }
 
143
  .seg-changed { background: var(--ochre-bg); border-bottom: 2px solid var(--ochre-edge); }
144
  .seg-added { color: var(--green-ink); border-bottom: 2px solid var(--green-ink); font-weight: 700; }
145
  .seg-removed { color: var(--red-ink); text-decoration: line-through; opacity: .75; }
146
+ .error-box { border: 1px solid var(--red-ink); color: var(--red-ink); padding: .55rem .85rem; font-style: italic; margin-top: .9rem; }
147
+ .legend { display: flex; gap: 1.4rem; justify-content: center; margin-top: 1.6rem; font-size: .78rem; color: var(--ink-soft); flex-wrap: wrap; }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
148
 
149
+ /* ---------- ledger ---------- */
150
+ table { border-collapse: collapse; margin: 0 auto; font-size: .9rem; }
151
+ th, td { padding: .42rem .85rem; border-bottom: 1px solid #00000022; text-align: right; }
 
 
 
 
 
 
152
  th:first-child, td:first-child { text-align: left; }
153
+ thead th { border-bottom: 2px solid var(--rule); font-variant: small-caps; letter-spacing: .05em; }
154
+ thead th .hint { display: block; font-variant: normal; letter-spacing: 0; font-weight: 400; font-style: italic; font-size: .68rem; color: var(--ink-soft); }
155
+ tbody tr.baseline td { color: var(--ink-soft); font-style: italic; }
156
+ tbody tr.dimmed td { color: var(--ink-soft); opacity: .7; }
157
+ td.win { font-weight: 700; }
158
+ .footnotes { max-width: 72ch; margin: 1.2rem auto 0; font-size: .84rem; color: var(--ink-soft); }
159
  .footnotes p { margin: .3rem 0; }
160
 
161
+ footer { margin-top: 3rem; border-top: 3px double var(--rule); padding-top: .9rem; text-align: center; font-size: .8rem; color: var(--ink-soft); }
 
 
 
162
  footer a { color: var(--oxblood); }
163
 
164
+ @keyframes settle { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
165
  @media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }
166
  </style>
167
  </head>
 
169
 
170
  <header>
171
  <h1 class="gazette-name">The Post‑OCR Gazette</h1>
172
+ <div class="dateline"><span>Diffusion <span style="font-variant:normal">vs</span> Autoregression · June 2026</span></div>
173
  <hr class="double-rule" />
174
  <p class="standfirst">
175
+ Watch <a href="https://huggingface.co/google/diffusiongemma-26B-A4B-it">DiffusionGemma</a>, an experimental
176
+ diffusion language model, correct 19th‑century newspaper OCR — step by step — and compare it against
177
+ autoregressive <a href="https://huggingface.co/google/gemma-4-E4B-it">Gemma‑4‑E4B</a>.
 
 
178
  </p>
179
  </header>
180
 
181
  <section class="desk">
 
182
  <div class="chips" id="chips"></div>
183
  <textarea id="ocr-input" spellcheck="false" placeholder="Paste noisy OCR text here, or pick a passage above…"></textarea>
184
+ <details class="authority" id="authority">
185
+ <summary>Human transcription of this passage</summary>
186
+ <div class="gold-text" id="gold-text"></div>
187
+ </details>
188
  <div class="controls">
189
  <button class="run-btn" id="run">Correct the Proofs</button>
190
  <label class="toggle">
191
  <input type="checkbox" id="canvas-toggle" />
192
+ seed canvas with OCR text <em style="font-size:.78em">(experimental — barely edits)</em>
193
  </label>
194
  <span class="charcount" id="charcount"></span>
195
  </div>
196
  </section>
197
 
198
+ <nav class="tabs">
199
+ <button class="active" data-pane="pane-press">The Press</button>
200
+ <button data-pane="pane-compare">Side by Side</button>
201
+ <button data-pane="pane-ledger">The Ledger</button>
202
+ </nav>
203
+
204
+ <section class="pane active" id="pane-press">
205
+ <div class="press-stage">
206
+ <div class="press-status">
207
+ <span id="press-label">the denoising press</span>
208
+ <span id="press-step"></span>
209
  </div>
210
+ <div class="press-canvas settling" id="press-canvas"><span class="placeholder">Run a passage and watch DiffusionGemma denoise all 256 tokens in parallel — from rough draft to corrected proof in a handful of steps.</span></div>
211
+ <div class="press-controls">
212
+ <button id="press-replay" disabled>replay</button>
213
+ <input type="range" id="press-slider" min="0" max="0" value="0" step="1" disabled />
 
 
214
  </div>
215
+ <div class="press-stats" id="press-stats"></div>
216
+ </div>
217
+ </section>
218
+
219
+ <section class="pane" id="pane-compare">
220
+ <div class="mode-switch" id="mode-switch">
221
+ <button class="active" data-mode="diff">marks vs the OCR input</button>
222
+ <button data-mode="diff_gold" id="gold-mode-btn" disabled>marks vs the human transcription</button>
223
  </div>
224
+ <div class="columns">
225
+ <div class="col">
226
+ <div class="col-head">
227
+ <h2>The Diffusionist</h2>
228
+ <div class="col-sub"><a href="https://huggingface.co/google/diffusiongemma-26B-A4B-it">DiffusionGemma‑26B‑A4B</a> · parallel denoising</div>
229
+ </div>
230
+ <div class="statline" id="stats-dg"><span class="placeholder">awaiting copy</span></div>
231
+ <div class="proof" id="proof-dg"><span class="placeholder">Corrected proof appears here.</span></div>
232
+ </div>
233
+ <div class="col">
234
+ <div class="col-head">
235
+ <h2>The Autoregressive</h2>
236
+ <div class="col-sub"><a href="https://huggingface.co/google/gemma-4-E4B-it">Gemma‑4‑E4B</a> · token by token, greedy</div>
237
+ </div>
238
+ <div class="statline" id="stats-g4"><span class="placeholder">awaiting copy</span></div>
239
+ <div class="proof" id="proof-g4"><span class="placeholder">Corrected proof appears here.</span></div>
240
  </div>
241
+ </div>
242
+ <div class="legend">
243
+ <span><span class="seg-changed">changed</span></span>
244
+ <span><span class="seg-added">added</span></span>
245
+ <span><span class="seg-removed">removed</span></span>
246
+ <span id="legend-note">relative to the OCR input</span>
247
  </div>
248
  </section>
249
 
250
+ <section class="pane" id="pane-ledger">
 
 
 
 
 
 
 
 
 
 
251
  <div id="results-table"><p style="text-align:center;font-style:italic">Fetching the ledger…</p></div>
252
  <div class="footnotes" id="results-notes"></div>
253
  </section>
254
 
255
  <footer>
256
  <p>
257
+ Benchmark: 75 passages of <a href="https://doi.org/10.15131/shef.data.25439023">BLN600</a> (CC‑BY‑NC; metrics only republished).
258
+ Demo passages: ICDAR2019 (CC‑BY‑4.0). DiffusionGemma is experimental; single run, no significance testing.
 
259
  </p>
260
+ <p>Powered by ZeroGPU · by <a href="https://huggingface.co/davanstrien">davanstrien</a></p>
261
  </footer>
262
 
263
  <script type="module">
 
265
 
266
  const $ = (id) => document.getElementById(id);
267
  const MAX_CHARS = 1200;
268
+ let client = null, examples = [], activeExample = null;
269
+ let diffMode = "diff";
270
+ let lastResults = { dg: null, g4: null };
271
+ let snapshots = [], replayTimer = null;
272
 
273
  const connect = (async () => { client = await Client.connect(window.location.origin); })();
274
 
275
+ /* ---------- tabs ---------- */
276
+ document.querySelectorAll(".tabs button").forEach(b => b.addEventListener("click", () => {
277
+ document.querySelectorAll(".tabs button").forEach(x => x.classList.toggle("active", x === b));
278
+ document.querySelectorAll(".pane").forEach(p => p.classList.toggle("active", p.id === b.dataset.pane));
279
+ }));
280
+ function switchTab(paneId) { document.querySelector(`.tabs button[data-pane=${paneId}]`).click(); }
281
+
282
+ /* ---------- diff rendering ---------- */
283
  function renderDiff(el, segs) {
284
  el.innerHTML = "";
285
  for (const s of segs) {
 
289
  el.appendChild(span);
290
  }
291
  }
292
+ function renderProofs() {
293
+ for (const [key, el] of [["dg", $("proof-dg")], ["g4", $("proof-g4")]]) {
294
+ const r = lastResults[key];
295
+ if (!r) continue;
296
+ renderDiff(el, diffMode === "diff_gold" && r.diff_gold ? r.diff_gold : r.diff);
297
+ }
298
+ $("legend-note").textContent = diffMode === "diff_gold"
299
+ ? "relative to the human transcription (remaining errors)" : "relative to the OCR input";
300
+ }
301
+ function setMode(mode) {
302
+ diffMode = mode;
303
+ document.querySelectorAll("#mode-switch button").forEach(b => b.classList.toggle("active", b.dataset.mode === mode));
304
+ renderProofs();
305
+ }
306
+ document.querySelectorAll("#mode-switch button").forEach(b =>
307
+ b.addEventListener("click", () => { if (!b.disabled) setMode(b.dataset.mode); }));
308
+ function setGoldAvailable(gold) {
309
+ const btn = $("gold-mode-btn");
310
+ if (gold) { btn.disabled = false; $("authority").classList.add("visible"); $("gold-text").textContent = gold; }
311
+ else { btn.disabled = true; $("authority").classList.remove("visible"); if (diffMode === "diff_gold") setMode("diff"); }
312
+ }
313
+ function currentGold() {
314
+ return activeExample && $("ocr-input").value === activeExample.ocr_input ? (activeExample.gold || "") : "";
315
+ }
316
  function stats(el, r, extra = "") {
317
  el.innerHTML = `<span><b>${r.seconds}</b> s</span><span><b>${r.tokens_per_second}</b> tok/s</span>` +
318
  (r.denoising_steps ? `<span><b>${r.denoising_steps}</b> steps</span>` : "") + extra;
 
320
  function spinner(el, msg) { el.innerHTML = `<span class="spinner">${msg}</span>`; }
321
  function showError(el, msg) { el.innerHTML = `<div class="error-box">${msg}</div>`; }
322
 
323
+ /* ---------- the press (hero replay) ---------- */
324
+ function pressShow(i) {
325
+ const canvas = $("press-canvas");
326
+ const last = i >= snapshots.length - 1;
327
+ canvas.classList.toggle("settling", !last);
328
+ if (last && lastResults.dg) { renderDiff(canvas, lastResults.dg.diff); }
329
+ else { canvas.textContent = snapshots[i] || ""; }
330
+ $("press-step").textContent = snapshots.length ? `step ${Math.min(i + 1, snapshots.length)} of ${snapshots.length}` : "";
331
+ $("press-slider").value = i;
332
+ }
333
+ function pressReplay() {
334
+ if (!snapshots.length) return;
335
+ clearInterval(replayTimer);
336
+ let i = 0;
337
+ pressShow(0);
338
+ replayTimer = setInterval(() => {
339
+ i += 1;
340
+ if (i >= snapshots.length) { clearInterval(replayTimer); pressShow(snapshots.length - 1); return; }
341
+ pressShow(i);
342
+ }, 450);
343
+ }
344
+ function pressLoad(snaps, dgResult) {
345
  snapshots = snaps || [];
346
+ clearInterval(replayTimer);
 
 
347
  const slider = $("press-slider");
348
+ slider.disabled = $("press-replay").disabled = !snapshots.length;
349
+ slider.max = Math.max(snapshots.length - 1, 0);
350
+ $("press-stats").innerHTML = dgResult
351
+ ? `corrected <b>${dgResult.tokens_per_second ? "" : ""}256 tokens</b> in <b>${dgResult.denoising_steps}</b> parallel steps · <b>${dgResult.seconds}s</b>` +
352
+ (dgResult.canvas_init ? " · <em>OCR-seeded canvas</em>" : "")
353
+ : "";
354
+ if (snapshots.length) pressReplay();
355
  }
356
+ $("press-slider").addEventListener("input", (e) => { clearInterval(replayTimer); pressShow(+e.target.value); });
357
+ $("press-replay").addEventListener("click", pressReplay);
 
 
 
 
358
 
359
  /* ---------- examples ---------- */
360
  async function loadExamples() {
 
370
  $("ocr-input").value = e.ocr_input;
371
  activeExample = e;
372
  updateCount();
373
+ setGoldAvailable(e.gold || "");
374
  if (e.cached) renderCached(e);
375
  };
376
  chips.appendChild(b);
 
379
  }
380
  function renderCached(e) {
381
  const dg = e.cached.diffusiongemma, g4 = e.cached.gemma4;
382
+ const tag = `<span class="cached-tag">— pre‑computed</span>`;
383
  if (dg) {
384
+ lastResults.dg = dg;
385
  stats($("stats-dg"), { seconds: dg.seconds, tokens_per_second: Math.round(dg.tokens_generated / dg.seconds), denoising_steps: dg.denoising_steps }, tag);
 
386
  }
387
  if (g4) {
388
+ lastResults.g4 = g4;
389
  stats($("stats-g4"), { seconds: g4.seconds, tokens_per_second: Math.round(g4.tokens_generated / g4.seconds) }, tag);
 
390
  }
391
+ renderProofs();
392
+ pressLoad([], null);
393
+ $("press-canvas").classList.add("settling");
394
+ $("press-canvas").innerHTML = `<span class="placeholder">Pre‑computed result loaded in the Side by Side tab — press “Correct the Proofs” to watch the denoising live.</span>`;
395
+ $("press-stats").innerHTML = ""; $("press-step").textContent = "";
396
  }
397
 
 
398
  function updateCount() {
399
  const n = $("ocr-input").value.length;
400
  const el = $("charcount");
401
+ el.textContent = `${n} / ${MAX_CHARS}`;
402
  el.classList.toggle("over", n > MAX_CHARS);
403
  }
404
+ $("ocr-input").addEventListener("input", () => { activeExample = null; updateCount(); setGoldAvailable(""); });
405
  updateCount();
406
 
407
  /* ---------- run ---------- */
408
  $("run").addEventListener("click", async () => {
409
  const text = $("ocr-input").value.trim();
410
  if (!text) return;
411
+ if (text.length > MAX_CHARS) {
412
+ switchTab("pane-press");
413
+ $("press-canvas").innerHTML = `<div class="error-box">Input too long (${text.length} chars; cap ${MAX_CHARS} — DiffusionGemma writes a single 256‑token block).</div>`;
414
+ return;
415
+ }
416
  const btn = $("run");
417
  btn.disabled = true;
418
  await connect;
419
+ switchTab("pane-press");
420
+ clearInterval(replayTimer);
421
+ $("press-canvas").classList.add("settling");
422
+ $("press-canvas").innerHTML = `<span class="spinner" style="font-style:italic;color:var(--oxblood)">the press is running</span>`;
423
+ $("press-step").textContent = ""; $("press-stats").innerHTML = "";
424
+ spinner($("proof-dg"), "denoising"); $("stats-dg").innerHTML = "";
425
+ spinner($("proof-g4"), "queued"); $("stats-g4").innerHTML = "";
426
+ const gold = currentGold();
427
  try {
428
  const dg = (await client.predict("/run_diffusiongemma", {
429
+ ocr_text: text, canvas_init: $("canvas-toggle").checked, gold: gold,
430
  })).data[0];
431
+ if (dg.error) { showError($("proof-dg"), dg.error); $("press-canvas").innerHTML = `<div class="error-box">${dg.error}</div>`; }
432
  else {
433
+ lastResults.dg = dg;
434
  stats($("stats-dg"), dg, dg.canvas_init ? `<span class="cached-tag">— OCR‑seeded canvas</span>` : "");
435
+ renderProofs();
436
+ pressLoad(dg.snapshots, dg);
437
  }
438
+ spinner($("proof-g4"), "composing, token by token");
439
+ const g4 = (await client.predict("/run_gemma4", { ocr_text: text, gold: gold })).data[0];
440
  if (g4.error) showError($("proof-g4"), g4.error);
441
+ else { lastResults.g4 = g4; stats($("stats-g4"), g4); renderProofs(); }
442
  } catch (err) {
443
+ $("press-canvas").innerHTML = `<div class="error-box">The press has jammed: ${err.message || err}</div>`;
 
444
  } finally {
445
  btn.disabled = false;
446
  }
447
  });
448
 
449
+ /* ---------- ledger ---------- */
450
+ function columnDirection(header) {
451
+ if (/reduction|Fix rate|tok\/s|↑/i.test(header)) return "higher";
452
+ if (/CER|WER|Over|Median|↓/i.test(header)) return "lower";
453
+ return null;
454
+ }
455
+ const parseNum = (c) => { const m = c.replace(/[*%]/g, "").match(/-?\d+(\.\d+)?/); return m ? parseFloat(m[0]) : null; };
456
+
457
  async function loadResults() {
458
  try {
459
  const res = await fetch("data/results");
 
464
  const parse = (l) => l.split("|").slice(1, -1).map(c => c.trim());
465
  const head = parse(tableLines[0]);
466
  const rows = tableLines.slice(2).map(parse);
467
+ const isBaseline = (r) => /uncorrected/i.test(r[0]);
468
+ const isCanvas = (r) => /canvas/i.test(r[0]);
469
+ const contenders = rows.filter(r => !isBaseline(r) && !isCanvas(r));
470
+ const best = head.map((h, j) => {
471
+ const dir = columnDirection(h);
472
+ if (!dir || j === 0) return null;
473
+ const vals = contenders.map(r => parseNum(r[j])).filter(v => v !== null);
474
+ return vals.length ? (dir === "lower" ? Math.min(...vals) : Math.max(...vals)) : null;
475
+ });
476
+ const headHtml = head.map((h, j) => {
477
+ const dir = columnDirection(h);
478
+ return `<th>${h.replace(/[↓↑]/g, "").trim()}${dir && j > 0 ? `<span class="hint">${dir} is better</span>` : ""}</th>`;
479
+ }).join("");
480
+ let html = `<table><thead><tr>${headHtml}</tr></thead><tbody>`;
481
+ for (const r of rows) {
482
+ const cls = isBaseline(r) ? "baseline" : isCanvas(r) ? "dimmed" : "";
483
+ html += `<tr class="${cls}">` + r.map((c, j) => {
484
+ const win = cls === "" && best[j] !== null && parseNum(c) === best[j];
485
+ return `<td${win ? ' class="win"' : ""}>${c.replace(/\*\*/g, "")}</td>`;
486
+ }).join("") + "</tr>";
487
+ }
488
+ $("results-table").innerHTML = html + "</tbody></table>";
489
  }
490
  const notes = lines.filter(l => /^(Micro|Mean)/.test(l)).map(l => `<p>${l}</p>`).join("");
491
  $("results-notes").innerHTML = notes +
492
+ `<p><b>Bold</b> marks the better of the two main models on each measure.
493
+ The OCR‑seeded‑canvas row is greyed out: it converges fastest but barely edits anything (a negative result),
494
+ so highlighting its numbers would mislead. Over‑correction: share of already‑correct characters the model changed.
495
+ Fix rate: share of wrong characters the model changed.</p>`;
496
  } catch { $("results-table").innerHTML = "<p style='text-align:center;font-style:italic'>The ledger could not be fetched.</p>"; }
497
  }
498