nopaddle 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. nopaddle-0.1.0/LICENSE +202 -0
  2. nopaddle-0.1.0/PKG-INFO +310 -0
  3. nopaddle-0.1.0/README.md +269 -0
  4. nopaddle-0.1.0/nopaddle/__init__.py +139 -0
  5. nopaddle-0.1.0/nopaddle/__main__.py +48 -0
  6. nopaddle-0.1.0/nopaddle/backends/__init__.py +5 -0
  7. nopaddle-0.1.0/nopaddle/backends/api_backend.py +425 -0
  8. nopaddle-0.1.0/nopaddle/backends/base.py +82 -0
  9. nopaddle-0.1.0/nopaddle/backends/errors.py +106 -0
  10. nopaddle-0.1.0/nopaddle/backends/onnx_backend.py +369 -0
  11. nopaddle-0.1.0/nopaddle/backends/paddleocr_vl_processor.py +227 -0
  12. nopaddle-0.1.0/nopaddle/config.py +94 -0
  13. nopaddle-0.1.0/nopaddle/ir.py +148 -0
  14. nopaddle-0.1.0/nopaddle/layout/__init__.py +6 -0
  15. nopaddle-0.1.0/nopaddle/layout/detector.py +424 -0
  16. nopaddle-0.1.0/nopaddle/layout/overlap.py +138 -0
  17. nopaddle-0.1.0/nopaddle/layout/postprocess.py +399 -0
  18. nopaddle-0.1.0/nopaddle/models.py +153 -0
  19. nopaddle-0.1.0/nopaddle/parsers/__init__.py +5 -0
  20. nopaddle-0.1.0/nopaddle/parsers/pdf_parser.py +879 -0
  21. nopaddle-0.1.0/nopaddle/parsers/region_output.py +987 -0
  22. nopaddle-0.1.0/nopaddle/render.py +153 -0
  23. nopaddle-0.1.0/nopaddle/server/__init__.py +0 -0
  24. nopaddle-0.1.0/nopaddle/server/main.py +287 -0
  25. nopaddle-0.1.0/nopaddle/server/schemas.py +97 -0
  26. nopaddle-0.1.0/nopaddle.egg-info/PKG-INFO +310 -0
  27. nopaddle-0.1.0/nopaddle.egg-info/SOURCES.txt +43 -0
  28. nopaddle-0.1.0/nopaddle.egg-info/dependency_links.txt +1 -0
  29. nopaddle-0.1.0/nopaddle.egg-info/entry_points.txt +3 -0
  30. nopaddle-0.1.0/nopaddle.egg-info/requires.txt +22 -0
  31. nopaddle-0.1.0/nopaddle.egg-info/top_level.txt +1 -0
  32. nopaddle-0.1.0/pyproject.toml +87 -0
  33. nopaddle-0.1.0/setup.cfg +4 -0
  34. nopaddle-0.1.0/tests/test_api_backend.py +201 -0
  35. nopaddle-0.1.0/tests/test_api_errors.py +220 -0
  36. nopaddle-0.1.0/tests/test_concurrency.py +128 -0
  37. nopaddle-0.1.0/tests/test_config.py +119 -0
  38. nopaddle-0.1.0/tests/test_dedup.py +446 -0
  39. nopaddle-0.1.0/tests/test_ir.py +408 -0
  40. nopaddle-0.1.0/tests/test_onnx_backend.py +298 -0
  41. nopaddle-0.1.0/tests/test_overlap.py +293 -0
  42. nopaddle-0.1.0/tests/test_parser.py +284 -0
  43. nopaddle-0.1.0/tests/test_postprocess.py +485 -0
  44. nopaddle-0.1.0/tests/test_quantization.py +44 -0
  45. nopaddle-0.1.0/tests/test_region_output.py +422 -0
nopaddle-0.1.0/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,310 @@
1
+ Metadata-Version: 2.4
2
+ Name: nopaddle
3
+ Version: 0.1.0
4
+ Summary: PaddleOCR-grade document parsing, minus PaddlePaddle, minus PyTorch.
5
+ Author: Bei Mi Chen
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/beimichen/nopaddle
8
+ Project-URL: Repository, https://github.com/beimichen/nopaddle
9
+ Project-URL: Issues, https://github.com/beimichen/nopaddle/issues
10
+ Keywords: ocr,pdf,document-parsing,document-ai,layout-analysis,onnx,paddleocr,vlm,table-recognition,formula-recognition
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Programming Language :: Python :: 3 :: Only
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Topic :: Scientific/Engineering :: Image Recognition
18
+ Classifier: Topic :: Text Processing
19
+ Requires-Python: >=3.10
20
+ Description-Content-Type: text/markdown
21
+ License-File: LICENSE
22
+ Requires-Dist: PyMuPDF>=1.24
23
+ Requires-Dist: pillow>=10.0
24
+ Requires-Dist: numpy>=1.26
25
+ Requires-Dist: opencv-python-headless>=4.9
26
+ Requires-Dist: onnxruntime>=1.17
27
+ Requires-Dist: huggingface_hub>=0.23
28
+ Provides-Extra: onnx
29
+ Requires-Dist: tokenizers>=0.20; extra == "onnx"
30
+ Provides-Extra: api
31
+ Requires-Dist: openai>=1.40; extra == "api"
32
+ Provides-Extra: serve
33
+ Requires-Dist: fastapi>=0.110; extra == "serve"
34
+ Requires-Dist: uvicorn[standard]>=0.29; extra == "serve"
35
+ Requires-Dist: python-multipart>=0.0.9; extra == "serve"
36
+ Provides-Extra: dev
37
+ Requires-Dist: pytest>=8.0; extra == "dev"
38
+ Requires-Dist: ruff>=0.5; extra == "dev"
39
+ Requires-Dist: mypy>=1.10; extra == "dev"
40
+ Dynamic: license-file
41
+
42
+ # nopaddle
43
+
44
+ **PaddleOCR-grade document parsing, minus PaddlePaddle, minus PyTorch, minus the GPU bill.** Turns PDFs into structured, typed regions (text, headings, tables, formulas, figures) in reading order.
45
+
46
+ > *Being up a creek without a paddle is supposed to be the bad ending. But when the paddle is PaddlePaddle, plus a multi-gigabyte PyTorch stack, plus a GPU that keeps asking for money, losing it is the best thing that can happen to you. Bon voyage.*
47
+
48
+ PaddleOCR-VL is a genuinely excellent document model that happens to come welded to PaddlePaddle (which drags in PyTorch, which would really love a GPU). nopaddle keeps the model and quietly drops the boat overboard: layout detection is pure ONNX, born-digital prose is read straight from the PDF's own text layer, and the VLM only ever sees the regions that truly need it (math, tables, figures, scanned text). What's left is a small, torch-free, paddle-free library you can `pip install`, run on a laptop, and self-host behind FastAPI.
49
+
50
+ [![License: Apache-2.0](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](./LICENSE)
51
+ [![PyPI](https://img.shields.io/pypi/v/nopaddle?color=blue)](https://pypi.org/project/nopaddle/)
52
+ ![Status: alpha](https://img.shields.io/badge/status-alpha-orange.svg)
53
+ ![Python: 3.10+](https://img.shields.io/badge/python-3.10%2B-blue.svg)
54
+ [![Open in Spaces](https://huggingface.co/datasets/huggingface/badges/resolve/main/open-in-hf-spaces-sm.svg)](https://huggingface.co/spaces/Bei0001/nopaddle)
55
+
56
+ ---
57
+
58
+ ## Why nopaddle
59
+
60
+ - **Top accuracy, near-zero cost.** nopaddle wraps **PaddleOCR-VL-1.5**, a 0.9B document specialist that scores **94.5** on OmniDocBench v1.5 (**~16 points above Mistral OCR**), and runs it **free, locally**. See [Benchmarks & cost](#benchmarks--cost).
61
+ - **All-machine by design.** Both the layout detector **and** the VLM run on `onnxruntime`, so the full pipeline is **truly platform-agnostic**: any OS/CPU (Linux, macOS, Windows), no Apple-Silicon or GPU requirement. The ONNX VLM path is **torch-free *and* transformers-free** (just NumPy/Pillow/onnxruntime/tokenizers).
62
+ - **Fast, built for digital PDFs.** Most PDFs are born-digital and carry an exact text layer. nopaddle reads prose **straight from that layer** (≈1 ms/region, no model) and sends *only* the visual minority (math, tables, figures, scanned regions) to the VLM. That's ~**2.9× fewer VLM calls** on typical documents, so most pages come back in milliseconds.
63
+ - **Tiny & dependency-light.** **No PyTorch, no PaddlePaddle, no CUDA wheels**: the whole core install is **~350 MB** (PyMuPDF, Pillow, NumPy, OpenCV-headless, onnxruntime) versus the multi-GB GPU stacks typical of VLM document parsers. Runs on a CPU-only laptop; the VLM loads lazily and is freed between documents.
64
+ - **Free, with an optional cheap fallback.** Everything runs locally for free. You can optionally offload just the math/table/figure minority to a hosted commercial VLM; prose stays free and local.
65
+ - **Self-hostable.** A FastAPI service and Docker image ship for drop-in `POST /parse` document parsing.
66
+
67
+ ---
68
+
69
+ ## Benchmarks & cost
70
+
71
+ > **TL;DR:** the top score on OmniDocBench v1.5 (**94.5 overall**), run locally for **$0**, or via a hosted API at a fraction of Mistral OCR's price.
72
+
73
+ nopaddle wraps **PaddleOCR-VL-1.5**, a 0.9B document-parsing specialist that tops [OmniDocBench](https://github.com/opendatalab/OmniDocBench), and runs it **free locally** (ONNX) or via a cheap hosted API. Accuracy below is PaddleOCR-VL's **published** OmniDocBench v1.5 score (we wrap that model); API cost is **estimated**, local cost is genuinely $0. ([caveats](#a-note-on-these-numbers))
74
+
75
+ ### Accuracy: OmniDocBench v1.5 *(higher is better)*
76
+
77
+ ![OmniDocBench v1.5 Overall: nopaddle vs others](docs/benchmarks/accuracy.png)
78
+
79
+ | System | Overall ↑ | Tables · TEDS ↑ | Text · edit ↓ |
80
+ | --- | --- | --- | --- |
81
+ | **PaddleOCR-VL-1.5 (nopaddle)** | **94.50** | **92.76** | **0.035** |
82
+ | MinerU2.5 | 90.67 | 88.22 | 0.047 |
83
+ | Gemini-3 Pro | 90.33 | 88.28 | 0.065 |
84
+ | Gemini-2.5 Pro | 88.03 | 85.71 | 0.075 |
85
+ | Mistral OCR (`mistral-ocr-latest`) | 78.83 | 70.03 | 0.164 |
86
+ | GPT-4o | 75.02 | 67.07 | 0.217 |
87
+
88
+ The 0.9B specialist beats **Mistral OCR by +15.7 points overall**, widest on **tables** (92.76 vs 70.03 TEDS) and **text fidelity** (0.035 vs 0.164 edit distance, ~4.7× fewer corrections). Source: PaddleOCR-VL-1.5 report ([arXiv 2601.21957](https://arxiv.org/abs/2601.21957), Table 2); the Mistral OCR row is the PaddleOCR team's measurement, not Mistral's self-report.
89
+
90
+ ### Cost: USD per 1,000 pages *(lower is better)*
91
+
92
+ ![Cost per 1,000 pages: nopaddle vs Mistral OCR](docs/benchmarks/cost.png)
93
+
94
+ | Path | $/1,000 pages | How |
95
+ | --- | --- | --- |
96
+ | **nopaddle local (ONNX)** | **$0.00** | runs on your own hardware, free **and** offline |
97
+ | nopaddle API, born-digital | ~$0.04-0.14 | only the visual minority hits the VLM; prose is read from the text layer |
98
+ | nopaddle API, Gemini 2.5 Flash-Lite (full-page) | ~$0.71 | ~1.1k image + 1.5k output tok/page ([Gemini pricing](https://ai.google.dev/gemini-api/docs/pricing)); ~$0.36 batch |
99
+ | Mistral OCR (batch / standard) | $1.00 / $2.00 | flat per page ([Mistral pricing](https://mistral.ai/pricing)) |
100
+
101
+ So you get **higher accuracy at $0** locally, or on the API path a **fraction of Mistral OCR's price**, *especially* on born-digital documents where the text-layer fast path keeps prose off the paid VLM entirely.
102
+
103
+ #### A note on these numbers
104
+
105
+ - **Accuracy is piggybacked, not re-run.** It's PaddleOCR-VL's *published* score for the reference weights; nopaddle runs the **ONNX** export (quantization can shift it slightly; we haven't independently re-benchmarked it). Read it as *"nopaddle wraps the model that scores 94.50."*
106
+ - **Metric directions differ.** `Overall` / `TEDS` are higher-better ↑; `Text · edit` is normalized edit distance, lower-better ↓ (0.035 ≈ near-perfect).
107
+ - **The Mistral OCR row is a competitor's measurement.** Mistral *self-reports* ~94.9 on its own internal set; treat vendor self-reports as claims, and don't mix the two scales.
108
+ - **API cost is estimated** (varies with page complexity / output length); the **local path is exactly $0**, and Mistral's per-page rate is official.
109
+ - "Mistral OCR" here is **OCR 3** (`mistral-ocr-latest`), not the Mixtral chat model.
110
+
111
+ ---
112
+
113
+ ## Quickstart
114
+
115
+ Install with the all-machine ONNX extra:
116
+
117
+ ```bash
118
+ pip install "nopaddle[onnx]"
119
+ ```
120
+
121
+ > `[onnx]` is the platform-agnostic local backend; it runs on any OS/CPU (Linux, macOS, Windows), no GPU required.
122
+ >
123
+ > Before the first PyPI release, install from source instead: `pip install "nopaddle[onnx] @ git+https://github.com/beimichen/nopaddle"`.
124
+
125
+ Parse a PDF from the command line:
126
+
127
+ ```bash
128
+ python -m nopaddle file.pdf # JSON to stdout
129
+ python -m nopaddle file.pdf --format markdown # Markdown to stdout
130
+ python -m nopaddle file.pdf -o out.json # write to a file
131
+ ```
132
+
133
+ Or from Python:
134
+
135
+ ```python
136
+ from nopaddle import parse_pdf
137
+
138
+ doc = parse_pdf("file.pdf") # auto-selects a runtime, frees the VLM when done
139
+ print(doc.to_markdown()) # or doc.to_json()
140
+ ```
141
+
142
+ `parse_pdf` returns a `ParsedDocument`: an ordered list of `Page`s, each holding typed `Region`s with bounding boxes normalized to a resolution-independent 0-1000 scale. Serialize it with `.to_dict()`, `.to_json()`, or `.to_markdown()`. A single region serializes like:
143
+
144
+ ```json
145
+ {
146
+ "type": "section_header",
147
+ "content": "ABSTRACT",
148
+ "bbox": {"x_min": 230, "y_min": 293, "x_max": 769, "y_max": 312},
149
+ "page": 1,
150
+ "confidence": 0.99
151
+ }
152
+ ```
153
+
154
+ Region `type`s include `title`, `section_header`, `text`, `table`, `formula`, `figure`, `caption`, and `footnote`.
155
+
156
+ ---
157
+
158
+ ## Runtimes
159
+
160
+ The parser core is written against a single `(image, prompt) -> text` backend seam and never imports a runtime directly. Pick one with `runtime=` (or `--runtime`), or let `"auto"` choose for you.
161
+
162
+ | Runtime | Backend | Where it runs | Status |
163
+ | -------- | ------------------------ | --------------------------- | ----------- |
164
+ | `onnx` | onnxruntime (torch-free) | All machines (platform-agnostic) | **Working** |
165
+ | `api` | OpenAI / Gemini (hosted) | Anywhere (optional) | **Working** |
166
+ | `none` | *(no VLM)* | Anywhere | **Working** |
167
+
168
+ **Auto-selection.** `runtime="auto"` (the default) resolves to **`onnx`**, the platform-agnostic local backend that runs anywhere. Override deployment-wide with `NOPADDLE_RUNTIME` (e.g. `api`).
169
+
170
+ **`runtime="none"`** runs layout detection plus the born-digital text-layer fast path with **zero model weights**: prose and figure bounding boxes come out fully, while math/table/scanned regions are emitted as bbox-only placeholders. This is the lightest way to parse a born-digital PDF.
171
+
172
+ ### ONNX precision (quantization)
173
+
174
+ The `onnx` backend reuses the [`onnx-community/PaddleOCR-VL-1.5-ONNX`](https://huggingface.co/onnx-community/PaddleOCR-VL-1.5-ONNX) export (Apache-2.0) and runs a host-side, KV-cached decode loop on raw `onnxruntime`. Pick the precision; the package **downloads and loads the matching graphs automatically** on first use:
175
+
176
+ | `quantization` | Size (3 graphs) | Notes |
177
+ | --------------- | --------------- | ---------------------------------------------------- |
178
+ | `fp32` | ~3.6 GB | full precision; most literal output (e.g. LaTeX units) |
179
+ | `q8` *(default)*| ~1.2 GB | int8; validated word-for-word |
180
+ | `quint8` | ~1.2 GB | uint8 decoder; vision falls back to q8 |
181
+ | `q4` | smallest | int4; fidelity not yet validated |
182
+
183
+ Set it per call (`parse_pdf(..., quantization="fp32")`, `make_parser("onnx", quantization=...)`), on the CLI (`--quantization fp32`), per request (`/parse?quantization=fp32`), or deployment-wide with `NOPADDLE_ONNX_QUANT`. There is no fp16 variant in the export; on CPU `fp32` is the high-fidelity choice (fp16 mostly helps on GPU).
184
+
185
+ ### API providers (hosted, optional)
186
+
187
+ `runtime="api"` sends each VLM-bound region to a hosted vision model over the OpenAI-compatible Chat API. Models are a **curated, vision-capable allow-list** (the provider is inferred from the model); set the provider's key via env:
188
+
189
+ | Model (`--model` / `model=`) | Provider | Key env var |
190
+ | ----------------------------------- | -------- | -------------------------------------- |
191
+ | `gemini-2.5-flash-lite` *(default)* | Gemini | `GEMINI_API_KEY` (or `GOOGLE_API_KEY`) |
192
+ | `gemini-2.5-flash`, `gemini-2.5-pro` | Gemini | `GEMINI_API_KEY` |
193
+ | `gpt-4o-mini`, `gpt-5.4-mini`, `gpt-4o`, `gpt-5.5` | OpenAI | `OPENAI_API_KEY` |
194
+
195
+ ```bash
196
+ pip install "nopaddle[api]"
197
+ GEMINI_API_KEY=... nopaddle doc.pdf --runtime api --model gemini-2.5-flash-lite --format markdown
198
+ ```
199
+
200
+ > DeepSeek's hosted API is text-only (no vision), so it's intentionally not in the list. For a self-hosted / third-party OpenAI-compatible vision endpoint (OpenRouter, vLLM, DeepSeek-VL, …), pass a custom `base_url` (or `NOPADDLE_API_BASE_URL`) with any model id.
201
+
202
+ **Error handling.** Failures are classified **transient** vs **fatal** with a named `ApiErrorKind` (e.g. `RATE_LIMIT (429)` vs `INSUFFICIENT_QUOTA (429)`):
203
+ - **Transient** (rate-limit, 5xx, timeout, network) → retried with backoff; if it still fails, that one region degrades to a placeholder and the document keeps parsing.
204
+ - **Fatal** (bad/missing key, depleted credits/quota, unknown model, bad request) → the parse aborts immediately with an actionable message, e.g. `[gemini INSUFFICIENT_QUOTA (429)] quota/credits exhausted … add credits`. Catch `nopaddle.FatalBackendError` / `nopaddle.TransientBackendError` in code.
205
+
206
+ ### Concurrency
207
+
208
+ Within a page, the VLM-bound regions (math, tables, figures, scanned text) can be processed in parallel; set it via `concurrency=N` (`parse_pdf`/`make_parser`), `--concurrency N`, `?concurrency=N`, or `NOPADDLE_CONCURRENCY`. Default is `1` (sequential).
209
+
210
+ **When to use it.** It's a win where the per-region work is **I/O-bound**, i.e. the **`api`** backend, where each region is an HTTP round-trip to OpenAI/Gemini, so firing them concurrently overlaps the network latency. The payoff scales with how many regions on a page hit the VLM:
211
+ - A **scanned page** (every region goes to the VLM) or a **dense page of formulas/tables** benefits most: e.g. a scanned 4-region page went **~12s → ~4.5s at `concurrency=8`** (≈2.6×).
212
+ - A typical **born-digital** page barely touches the VLM (prose is read from the text layer), so there's little to parallelize, and that's fine.
213
+ - The local **`onnx`** backend is compute-bound, so concurrency helps it far less, and only up to your CPU/GPU headroom.
214
+
215
+ **Guarantees.** Reading order is **always preserved** regardless of completion order. A **fatal** error (bad key, depleted credits) still aborts the whole parse with an actionable message; a **transient** one degrades just that region after retries. Parallelism is applied only to thread-safe backends.
216
+
217
+ ---
218
+
219
+ ## The born-digital fast path
220
+
221
+ Most real-world PDFs are *born-digital*: exported from LaTeX, Word, or a browser, they carry an exact, machine-readable text layer. Running a VLM over that prose is slow and pointless; the text is already there.
222
+
223
+ nopaddle exploits this with a per-page, data-driven gate (no flags):
224
+
225
+ 1. **Layout pass.** PP-DocLayoutV3 (ONNX) detects every region and its type.
226
+ 2. **Born-digital probe.** If a page exposes enough extractable text (`NOPADDLE_BORN_DIGITAL_MIN_CHARS`, default 100), it's treated as born-digital.
227
+ 3. **Hybrid extraction.** On born-digital pages, **text/heading regions are read straight from the PDF text layer**: exact, instant, free. Only the regions a text layer can't represent (**formulas, tables, figures, and scanned/empty regions**) are cropped and sent to the VLM.
228
+
229
+ Because prose is the overwhelming majority of a typical page, this routes only the visual minority to the model (about **2.9× fewer VLM calls** on born-digital documents) while keeping the same structured output. Scanned or sparse pages fall back to the VLM automatically, so quality never depends on a guess.
230
+
231
+ ---
232
+
233
+ ## FastAPI & Docker
234
+
235
+ Install the service extra and run the API locally:
236
+
237
+ ```bash
238
+ pip install "nopaddle[serve,onnx]"
239
+ nopaddle-serve # or: uvicorn nopaddle.server.main:app --host 0.0.0.0 --port 8000
240
+ ```
241
+
242
+ POST a PDF and get structured JSON back:
243
+
244
+ ```bash
245
+ curl -sS -X POST http://127.0.0.1:8000/parse -F "file=@mydoc.pdf"
246
+ ```
247
+
248
+ A Docker image is provided for self-hosting:
249
+
250
+ ```bash
251
+ docker build -t nopaddle -f docker/Dockerfile .
252
+ docker run --rm -p 8000:8000 nopaddle
253
+ ```
254
+
255
+ The server loads models lazily and frees the detector + VLM between requests, so a long-running instance keeps a small resident footprint.
256
+
257
+ ---
258
+
259
+ ## Models
260
+
261
+ nopaddle pulls models from the Hugging Face Hub on first use and caches them on disk.
262
+
263
+ | Role | Model | Notes |
264
+ | -------------- | ------------------------------------------------ | -------------------------------------- |
265
+ | Layout | `Bei0001/PP-DocLayoutV3-ONNX` | ONNX detector, runs everywhere |
266
+ | VLM | `onnx-community/PaddleOCR-VL-1.5-ONNX` | torch-free ONNX; `quantization=` picks precision (q8 default) |
267
+
268
+ Configuration via environment variables:
269
+
270
+ | Variable | Purpose |
271
+ | --------------------------------- | ------------------------------------------------------------- |
272
+ | `MODEL_CACHE_DIR` | Where downloaded models live (default: `~/.cache/nopaddle/models`). |
273
+ | `HF_TOKEN` | Hugging Face token, only needed for gated/private repos. |
274
+ | `NOPADDLE_RUNTIME` | Override the auto-selected runtime deployment-wide. |
275
+ | `NOPADDLE_ONNX_QUANT` | ONNX VLM precision: `fp32` / `q8` (default) / `q4` / `quint8`. |
276
+ | `NOPADDLE_API_MODEL` | Default hosted model for `runtime=api` (e.g. `gemini-2.5-flash-lite`). |
277
+ | `GEMINI_API_KEY` / `OPENAI_API_KEY` | API key for the chosen `runtime=api` provider. |
278
+ | `NOPADDLE_API_BASE_URL` | Custom OpenAI-compatible vision endpoint (advanced). |
279
+ | `NOPADDLE_CONCURRENCY` | Max VLM regions per page to run concurrently (default 1). |
280
+ | `NOPADDLE_BORN_DIGITAL_MIN_CHARS` | Text threshold for the born-digital fast path (default 100). |
281
+ | `NOPADDLE_RENDER_SCALE` | Page→image render scale for the VLM (default 2.0 ≈ 144 DPI). |
282
+ | `NOPADDLE_LAYOUT_REPO` | Point the layout detector at a fork/mirror. |
283
+
284
+ ---
285
+
286
+ ## Status
287
+
288
+ This is an early (alpha) release, and it's honest about what's done:
289
+
290
+ - ✅ **Layout detection (ONNX)**: works on all machines, today.
291
+ - ✅ **Born-digital text-layer fast path**: works on all machines with no VLM weights.
292
+ - ✅ **Cross-platform ONNX VLM backend**: runs on all machines via raw `onnxruntime`, **torch- and transformers-free**. Reuses `onnx-community/PaddleOCR-VL-1.5-ONNX` with a host-side KV-cached decode loop; the SigLIP preprocessor is a numpy/PIL port validated byte-for-byte against the reference. Validated at **q8** (word-for-word OCR + tables + formulas); `q4`/`quint8` are wired but their fidelity isn't validated yet, and only CPU has been exercised (CUDA is coded but untested). See [`docs/onnx_port.md`](./docs/onnx_port.md).
293
+ - ✅ **Hosted API backend (OpenAI / Gemini)**: optional `runtime="api"` with a curated model allow-list, a transient/fatal error taxonomy, and per-page concurrency. Validated against real Gemini (formula + table OCR). See [`docs/api_backend.md`](./docs/api_backend.md).
294
+
295
+ In short: **the full pipeline (layout, born-digital fast path, and the ONNX VLM) works on any machine right now**, torch-free, with an optional hosted-API backend. Remaining polish: validating the smaller ONNX quantizations and the CUDA path.
296
+
297
+ ---
298
+
299
+ ## License
300
+
301
+ [Apache-2.0](./LICENSE).
302
+
303
+ ## Acknowledgements
304
+
305
+ nopaddle stands on excellent open work from the PaddlePaddle team:
306
+
307
+ - **[PaddleOCR-VL](https://github.com/PaddlePaddle/PaddleOCR)**: the vision-language OCR model nopaddle wraps for math, tables, figures, and scanned text.
308
+ - **PP-DocLayoutV3**: the document layout detector, re-exported to ONNX for portable, runtime-light layout analysis.
309
+
310
+ nopaddle is an independent re-packaging that runs these models without PaddlePaddle or PyTorch; it is not affiliated with or endorsed by the PaddlePaddle project.