@@ -93,50 +93,58 @@ for await (const chunk of streamFileMarkdown('paper.pdf')) {
9393}
9494```
9595
96- ### PDF / images: installing the ML models
96+ ### PDF / images: getting the ML models
9797
9898Declarative formats (Markdown, HTML, DOCX, XLSX, …) are pure Rust and need
9999nothing. The ** PDF/image** path needs native assets that are * not* bundled in the
100- addon — pdfium plus the ONNX models (layout, OCR, TableFormer) — the same way
101- Python docling downloads its models on first use. Converting a PDF/image/METS
102- input ** throws ** until they're installed :
100+ addon — pdfium plus the ONNX models (layout, OCR, TableFormer). Converting a
101+ PDF/image/METS input ** throws ** until they're on disk. Fetch them with a
102+ one-liner from your app's directory (where you'll ` npm install fleischwolf ` ) :
103103
104- ``` js
105- import { installDependencies , checkDependencies , convertFileAsync } from ' fleischwolf'
104+ ``` bash
105+ curl -fsSL https://raw.githubusercontent.com/artiz/fleischwolf/master/scripts/download_dependencies.sh | sh
106+ ```
106107
107- await convertFileAsync (' paper.pdf' ) // ❌ throws: "requires the PDF/ML dependencies … call installDependencies()"
108+ ``` js
109+ import { convertFileAsync } from ' fleischwolf'
108110
109- await installDependencies () // provisions everything, then:
110- await convertFileAsync (' paper.pdf' ) // ✅ works
111+ const res = await convertFileAsync (' paper.pdf' , { to: ' markdown' }) // ✅ works
111112```
112113
113- What ` installDependencies() ` fetches, into ` ~/.cache/fleischwolf ` (override with
114- ` dir ` or ` $FLEISCHWOLF_HOME ` ), wiring the matching ` DOCLING_* ` /
115- ` PDFIUM_DYNAMIC_LIB_PATH ` env vars in-process:
116-
117- | Asset | Source | Required for |
118- | --- | --- | --- |
119- | ** pdfium** | bblanchon prebuilt (auto, platform-detected) | PDF |
120- | ** OCR** rec model + dictionary | HuggingFace / GitHub (auto) | scanned pages |
121- | ** layout** (` layout_heron.onnx ` ) | your ` modelsUrl ` (see below) | PDF ** and** image |
122- | ** TableFormer** (` tableformer/*.onnx ` ) | your ` modelsUrl ` | tables (else geometric fallback) |
123-
124- > ** layout + TableFormer have no public prebuilt download.** They're PyTorch→ONNX
125- > exports (` docling-project/docling-layout-heron ` , ` docling_ibm_models ` ). Host the
126- > exported ` .onnx ` yourself and point ` installDependencies ` at the base URL via
127- > ` { modelsUrl } ` or ` FLEISCHWOLF_MODELS_URL ` — it fetches ` layout_heron.onnx ` and
128- > ` tableformer/{encoder,decoder,bbox}.onnx ` from there. Or export them locally
129- > (repo ` scripts/export_layout.py ` , ` scripts/export_tableformer.py ` ) and set
130- > ` DOCLING_LAYOUT_ONNX ` / ` DOCLING_TABLEFORMER_* ` — ` installDependencies ` detects
131- > those as already installed. Without a layout source it installs pdfium/OCR and
132- > throws, naming what's missing.
114+ ` scripts/download_dependencies.sh ` fetches everything from this repo's
115+ [ GitHub Releases] ( https://github.com/artiz/fleischwolf/releases ) straight into
116+ ` ./models ` and ` ./.pdfium ` — which this package (and the Rust CLI) look for by
117+ default, relative to the process's current directory, so no env vars or setup
118+ call are needed afterwards:
119+
120+ | Asset | Destination |
121+ | --- | --- |
122+ | ** pdfium** | ` .pdfium/lib/libpdfium.so ` |
123+ | ** layout** (` layout_heron.onnx ` ) | ` models/layout_heron.onnx ` |
124+ | ** OCR** rec model + dictionary | ` models/ocr_rec.onnx ` , ` models/ppocr_keys_v1.txt ` |
125+ | ** TableFormer** | ` models/tableformer/{encoder,decoder,bbox}.onnx ` |
126+
127+ > ** layout + TableFormer are PyTorch→ONNX exports**
128+ > (` docling-project/docling-layout-heron ` , Apache-2.0;
129+ > ` docling-project/docling-models ` , CDLA-Permissive-2.0/Apache-2.0 — see
130+ > [ ` MODELS_NOTICE.md ` ] ( ../../MODELS_NOTICE.md ) for full attribution), not
131+ > fleischwolf's own weights — fleischwolf hosts the converted ` .onnx ` as a
132+ > GitHub Release purely so you don't need a local Python/torch toolchain.
133+ > pdfium and the OCR model are re-hosted, unmodified, from their own public
134+ > releases, on the same host for convenience.
135+ >
136+ > Run it from wherever your app lives — the script only writes to ` ./models `
137+ > and ` ./.pdfium ` under the current directory, e.g. in a container build step:
138+ > ``` bash
139+ > cd /path/to/your/app && curl -fsSL https://raw.githubusercontent.com/artiz/fleischwolf/master/scripts/download_dependencies.sh | sh
140+ > ` ` `
141+ >
142+ > To use your own export/host instead, point the env vars at it directly:
143+ > ` DOCLING_LAYOUT_ONNX` , ` DOCLING_OCR_REC_ONNX` , ` DOCLING_OCR_DICT` ,
144+ > ` DOCLING_TABLEFORMER_{ENCODER,DECODER,BBOX}` , ` PDFIUM_DYNAMIC_LIB_PATH` — an
145+ > env var always wins over the ` ./models` / ` ./.pdfium` default.
133146
134147` ` ` js
135- await installDependencies ({
136- modelsUrl: ' https://you.example/fleischwolf-models' , // serves layout_heron.onnx, tableformer/*.onnx
137- onProgress : (m ) => console .log (m),
138- })
139-
140148checkDependencies () // { home, pdfium, layout, ocr, tableformer, ready, missing }
141149` ` `
142150
@@ -188,7 +196,6 @@ JSON output always embeds extracted images as data URIs.
188196| ` streamFileMarkdown(path, options? )` | ` AsyncGenerator< string> ` | Markdown chunks in document order. |
189197| ` supportedFormats()` | ` string[]` | Supported input format ids. |
190198| ` formatFromName(name)` | ` string \| null` | Detect a format id from a filename/extension. |
191- | ` installDependencies(options?) ` | ` Promise<DependencyStatus> ` | Download/validate the PDF/image models + pdfium. |
192199| ` checkDependencies(options? )` | ` DependencyStatus` | Report which PDF/image deps are present. |
193200
194201` Pipeline` is the reusable warm PDF/image converter: ` new Pipeline(converterOptions)`
@@ -235,12 +242,12 @@ cd examples
235242npm install
236243node node-basic.mjs # ESM: file, bytes, JSON, reuse
237244bun run bun-basic.ts # Bun + TypeScript: async + streaming
238- node pdf-pipeline.mjs # installDependencies + warm Pipeline for PDFs
245+ node pdf-pipeline.mjs # warm Pipeline for PDFs (run scripts/download_dependencies.sh first)
239246```
240247
241248- [`examples/node-basic.mjs`](examples/node-basic.mjs) — Node.js (ESM): file, bytes, JSON, reuse.
242249- [`examples/bun-basic.ts`](examples/bun-basic.ts) — Bun + TypeScript, with async and streaming.
243- - [ ` examples/pdf-pipeline.mjs ` ] ( examples/pdf-pipeline.mjs ) — ` installDependencies ` + warm ` Pipeline ` for PDFs.
250+ - [`examples/pdf-pipeline.mjs`](examples/pdf-pipeline.mjs) — warm `Pipeline` for PDFs.
244251
245252The smoke test exercises the locally-built addon instead: `npm run build` once at
246253the package root, then `node test/smoke.mjs` (or `bun test/smoke.mjs`).
0 commit comments