Skip to content

Commit bb5abab

Browse files
artizclaude
andcommitted
wasm scan demo: fetch layout into ./models/ via download_dependencies.sh in www/
Point the same-origin layout paths at ./models/ and document running the installer from crates/docling-wasm/www/ — it writes ./models/ relative to the current directory, so the page reads ./models/layout_heron_int8.onnx (fallback ./models/layout_heron.onnx) with no copy step. gitignore the www/models/ tree the installer populates. 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_01EY5KAiquN4YpVf2PXEQkVT
1 parent a3fb2bc commit bb5abab

2 files changed

Lines changed: 22 additions & 14 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ onnxruntime_profile_*.json
88

99
# wasm-bindgen output for the docling-wasm demo (built from source, see its README)
1010
crates/docling-wasm/www/pkg/
11+
# ML models the scan demo fetches same-origin (download_dependencies.sh, run in www/)
12+
crates/docling-wasm/www/models/
1113

1214
# Secrets — never commit (holds CARGO_REGISTRY_TOKEN)
1315
.env

crates/docling-wasm/www/scan.html

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,22 +48,27 @@ <h1>docling.rs → wasm: scanned PDF / image, full lite profile</h1>
4848
reconstruction (TableFormer is stage 3). Nothing leaves this page.
4949
</p>
5050
<details id="setup">
51-
<summary>The layout model is served from this page's own origin — fetch it once (~68&nbsp;MB int8)</summary>
51+
<summary>The layout model is served from this page's own origin — fetch it once into <code>./models/</code></summary>
5252
<p>
5353
Unlike the recognition model (fetched from Hugging Face, which sends CORS
5454
headers), the RT-DETR layout export lives on this repo's GitHub Release,
5555
and <strong>GitHub Release assets can't be fetched cross-origin from a
5656
browser</strong> (no <code>Access-Control-Allow-Origin</code>). So this
57-
page loads the layout model <em>same-origin</em> — put it next to this
58-
file and serve the directory:
57+
page loads the layout model <em>same-origin</em>, from a
58+
<code>models/</code> directory next to it. Run the installer <strong>from
59+
this <code>www/</code> directory</strong> — it writes <code>./models/</code>
60+
relative to the current directory:
5961
</p>
60-
<pre>curl -fsSL https://raw.githubusercontent.com/docling-project/docling.rs/master/scripts/install/download_dependencies.sh | sh
61-
cp models/layout_heron_int8.onnx crates/docling-wasm/www/ # ~68 MB int8 (or layout_heron.onnx, ~172 MB fp32)</pre>
62+
<pre>cd crates/docling-wasm/www/
63+
curl -fsSL https://raw.githubusercontent.com/docling-project/docling.rs/master/scripts/install/download_dependencies.sh | sh</pre>
6264
<p>
63-
These are the exact models the native pipeline uses. The page prefers the
64-
int8 export and falls back to fp32; both decode identically here (same
65-
<code>pixel_values</code>&nbsp;→&nbsp;<code>logits</code>,&nbsp;<code>pred_boxes</code>
66-
contract).
65+
That populates <code>./models/</code> (this page reads
66+
<code>./models/layout_heron_int8.onnx</code>, ~68&nbsp;MB, falling back to
67+
<code>./models/layout_heron.onnx</code>, ~172&nbsp;MB — int8 needs a
68+
release that hosts it, otherwise fp32 is fetched). These are the exact
69+
conformance-validated models the native pipeline uses; both decode
70+
identically here (same <code>pixel_values</code>&nbsp;→&nbsp;<code>logits</code>,&nbsp;<code>pred_boxes</code>
71+
contract). The recognition model still streams from Hugging Face on demand.
6772
</p>
6873
</details>
6974
<div id="drop">drop a scanned PDF or image here, or click to pick</div>
@@ -88,13 +93,14 @@ <h1>docling.rs → wasm: scanned PDF / image, full lite profile</h1>
8893
pdfjs.GlobalWorkerOptions.workerSrc =
8994
"https://cdn.jsdelivr.net/npm/pdfjs-dist/build/pdf.worker.min.mjs";
9095

91-
// The layout model is loaded SAME-ORIGIN (see the setup note above): GitHub
92-
// Release assets carry no CORS header, so a browser fetch of the release URL
93-
// fails — the model has to sit next to this page instead. Prefer the
96+
// The layout model is loaded SAME-ORIGIN from ./models/ (see the setup note
97+
// above): GitHub Release assets carry no CORS header, so a browser fetch of
98+
// the release URL fails — download_dependencies.sh, run from this www/
99+
// directory, drops the models next to this page instead. Prefer the
94100
// conv-only static-INT8 export (~68 MB, a big first-load win over the
95101
// ~172 MB fp32) and fall back to fp32; both share the same interop
96102
// contract, so the wrapper below is unchanged.
97-
const LAYOUT_PATHS = ["./layout_heron_int8.onnx", "./layout_heron.onnx"];
103+
const LAYOUT_PATHS = ["./models/layout_heron_int8.onnx", "./models/layout_heron.onnx"];
98104
const SCALE = 2.0; // px per PDF point — the native pipeline's RENDER_SCALE
99105

100106
const meta = document.getElementById("meta");
@@ -214,7 +220,7 @@ <h1>docling.rs → wasm: scanned PDF / image, full lite profile</h1>
214220
const layoutSession = await loadLayout();
215221
if (!layoutSession) {
216222
document.getElementById("setup").open = true;
217-
ready("layout model not found next to this page — see the note above");
223+
ready("layout model not found under ./models/ — see the note above");
218224
throw new Error("no layout model available");
219225
}
220226
await recFor(lang.value);

0 commit comments

Comments
 (0)