Commit 27ff3a8
wasm: in-browser OCR via ONNX Runtime Web interop (#157 stage 1)
First slice of the browser ML pipeline: scanned images OCR fully
client-side.
docling-pdf grows an `ocr-prep` feature (pure Rust + the image crate, no
ort/pdfium): the ONNX-free half of the PP-OCRv3 recognition pipeline —
line segmentation, crop prep, deterministic width-batching, CTC decode,
dictionary handling — moved verbatim from ocr.rs into a public ocr_prep
module. ocr.rs now consumes it, so there is exactly ONE implementation
of the pre/post-processing; the native path is byte-identical after the
refactor (verified: the scanned-tiff conversion diffs empty against the
pre-refactor output, full docling-pdf suite green). Any wasm-vs-native
drift can therefore only come from the runtime's kernels — the #157
conformance story depends on that property.
docling-wasm (default `ocr` feature): `ocr_image(bytes, dict, session,
to)` — decode the image in Rust, segment/prep/batch via ocr_prep,
delegate each width-batch to a JS `RecSession` wrapper around an
ort-web InferenceSession (`run(n, h, w, data) -> {data, dims}`), CTC-
decode, and export a DoclingDocument as Markdown or docling JSON. No
layout model yet (stage 2): the whole image is one text region split by
the ink-projection profile — right for single-column scans, degraded on
complex layouts, and said so in the docs.
www/ocr.html: complete drop-an-image demo — ort-web from CDN, the ~10 MB
en_PP-OCRv3 model + dictionary fetched from their public hosting and
browser-cached, timing readout. Compiles for wasm32-unknown-unknown and
the host (rlib tests); clippy clean; the existing wasm CI check is
unaffected.
Refs #157
Signed-off-by: artiz <artem.kustikov@gmail.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EY5KAiquN4YpVf2PXEQkVT1 parent e983bd2 commit 27ff3a8
10 files changed
Lines changed: 568 additions & 157 deletions
File tree
- crates
- docling-pdf
- src
- docling-wasm
- src
- www
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
21 | 24 | | |
| 25 | + | |
22 | 26 | | |
23 | 27 | | |
24 | 28 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
| 31 | + | |
30 | 32 | | |
31 | 33 | | |
32 | 34 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
9 | | - | |
10 | | - | |
| 8 | + | |
11 | 9 | | |
12 | 10 | | |
13 | 11 | | |
14 | 12 | | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
15 | 19 | | |
16 | 20 | | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | 21 | | |
58 | 22 | | |
59 | 23 | | |
60 | 24 | | |
61 | 25 | | |
62 | 26 | | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | 27 | | |
91 | 28 | | |
92 | 29 | | |
| |||
194 | 131 | | |
195 | 132 | | |
196 | 133 | | |
197 | | - | |
198 | | - | |
199 | | - | |
200 | | - | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
201 | 138 | | |
202 | 139 | | |
203 | 140 | | |
| |||
208 | 145 | | |
209 | 146 | | |
210 | 147 | | |
211 | | - | |
212 | | - | |
213 | | - | |
214 | | - | |
215 | | - | |
216 | | - | |
217 | | - | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
218 | 156 | | |
219 | 157 | | |
220 | 158 | | |
| |||
277 | 215 | | |
278 | 216 | | |
279 | 217 | | |
280 | | - | |
281 | | - | |
282 | | - | |
283 | | - | |
284 | | - | |
285 | | - | |
| 218 | + | |
286 | 219 | | |
287 | | - | |
288 | | - | |
289 | | - | |
290 | | - | |
291 | | - | |
292 | | - | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
293 | 223 | | |
294 | 224 | | |
295 | 225 | | |
| |||
305 | 235 | | |
306 | 236 | | |
307 | 237 | | |
308 | | - | |
309 | | - | |
310 | | - | |
311 | | - | |
312 | | - | |
313 | | - | |
314 | | - | |
315 | | - | |
316 | | - | |
317 | | - | |
318 | | - | |
319 | | - | |
320 | | - | |
321 | | - | |
322 | | - | |
323 | | - | |
324 | | - | |
325 | | - | |
326 | | - | |
327 | | - | |
328 | | - | |
329 | | - | |
330 | | - | |
331 | | - | |
332 | | - | |
333 | | - | |
334 | | - | |
335 | | - | |
336 | | - | |
337 | | - | |
338 | | - | |
339 | | - | |
340 | | - | |
341 | | - | |
342 | | - | |
343 | | - | |
344 | | - | |
345 | | - | |
346 | | - | |
347 | | - | |
348 | | - | |
349 | | - | |
350 | | - | |
351 | | - | |
352 | | - | |
353 | | - | |
354 | | - | |
355 | | - | |
356 | | - | |
357 | | - | |
358 | | - | |
359 | | - | |
360 | | - | |
361 | | - | |
362 | | - | |
363 | | - | |
364 | | - | |
365 | | - | |
366 | | - | |
367 | | - | |
368 | | - | |
369 | | - | |
370 | | - | |
371 | | - | |
0 commit comments