pyocr-toolkit 0.3.0__py3-none-any.whl

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 (57) hide show
  1. pyocr_toolkit/__init__.py +3 -0
  2. pyocr_toolkit/__main__.py +3 -0
  3. pyocr_toolkit/api.py +603 -0
  4. pyocr_toolkit/cli.py +315 -0
  5. pyocr_toolkit/compare.py +142 -0
  6. pyocr_toolkit/config.py +86 -0
  7. pyocr_toolkit/credentials.py +108 -0
  8. pyocr_toolkit/documents.py +326 -0
  9. pyocr_toolkit/env.example +48 -0
  10. pyocr_toolkit/jobs.py +205 -0
  11. pyocr_toolkit/llm/__init__.py +44 -0
  12. pyocr_toolkit/llm/anthropic_provider.py +188 -0
  13. pyocr_toolkit/llm/base.py +126 -0
  14. pyocr_toolkit/llm/catalog.py +337 -0
  15. pyocr_toolkit/llm/gemini_provider.py +98 -0
  16. pyocr_toolkit/llm/openai_provider.py +183 -0
  17. pyocr_toolkit/llm/prompts.py +61 -0
  18. pyocr_toolkit/search.py +88 -0
  19. pyocr_toolkit/service.py +269 -0
  20. pyocr_toolkit/static/common.js +538 -0
  21. pyocr_toolkit/static/compare.js +157 -0
  22. pyocr_toolkit/static/document.js +89 -0
  23. pyocr_toolkit/static/jobs.js +13 -0
  24. pyocr_toolkit/static/library.js +28 -0
  25. pyocr_toolkit/static/models.js +98 -0
  26. pyocr_toolkit/static/providers.js +44 -0
  27. pyocr_toolkit/static/reader.js +78 -0
  28. pyocr_toolkit/static/search.js +34 -0
  29. pyocr_toolkit/static/styles.css +819 -0
  30. pyocr_toolkit/static/workspace.js +420 -0
  31. pyocr_toolkit/static/workspaces.js +81 -0
  32. pyocr_toolkit/templates/_doc_card.html +30 -0
  33. pyocr_toolkit/templates/_doctabs.html +14 -0
  34. pyocr_toolkit/templates/_icons.html +55 -0
  35. pyocr_toolkit/templates/_llm_picker.html +12 -0
  36. pyocr_toolkit/templates/base.html +97 -0
  37. pyocr_toolkit/templates/compare.html +84 -0
  38. pyocr_toolkit/templates/document.html +80 -0
  39. pyocr_toolkit/templates/error.html +11 -0
  40. pyocr_toolkit/templates/help.html +244 -0
  41. pyocr_toolkit/templates/home.html +90 -0
  42. pyocr_toolkit/templates/jobs.html +15 -0
  43. pyocr_toolkit/templates/library.html +44 -0
  44. pyocr_toolkit/templates/models.html +67 -0
  45. pyocr_toolkit/templates/providers.html +104 -0
  46. pyocr_toolkit/templates/reader.html +28 -0
  47. pyocr_toolkit/templates/search.html +22 -0
  48. pyocr_toolkit/templates/workspace.html +109 -0
  49. pyocr_toolkit/templates/workspace_detail.html +42 -0
  50. pyocr_toolkit/templates/workspaces.html +42 -0
  51. pyocr_toolkit/web.py +186 -0
  52. pyocr_toolkit/workspaces.py +330 -0
  53. pyocr_toolkit-0.3.0.dist-info/METADATA +483 -0
  54. pyocr_toolkit-0.3.0.dist-info/RECORD +57 -0
  55. pyocr_toolkit-0.3.0.dist-info/WHEEL +4 -0
  56. pyocr_toolkit-0.3.0.dist-info/entry_points.txt +3 -0
  57. pyocr_toolkit-0.3.0.dist-info/licenses/LICENSE +201 -0
@@ -0,0 +1,483 @@
1
+ Metadata-Version: 2.5
2
+ Name: pyocr-toolkit
3
+ Version: 0.3.0
4
+ Summary: Inspect and compare PDF/image text extraction - native text, Tesseract OCR and LLMs (Claude, GPT, Gemini, Azure, local) - in your browser.
5
+ Project-URL: Homepage, https://github.com/utkarsh5026/pyocr
6
+ Project-URL: Issues, https://github.com/utkarsh5026/pyocr/issues
7
+ Author: utkarsh5026
8
+ License: Apache License
9
+ Version 2.0, January 2004
10
+ http://www.apache.org/licenses/
11
+
12
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
13
+
14
+ 1. Definitions.
15
+
16
+ "License" shall mean the terms and conditions for use, reproduction,
17
+ and distribution as defined by Sections 1 through 9 of this document.
18
+
19
+ "Licensor" shall mean the copyright owner or entity authorized by
20
+ the copyright owner that is granting the License.
21
+
22
+ "Legal Entity" shall mean the union of the acting entity and all
23
+ other entities that control, are controlled by, or are under common
24
+ control with that entity. For the purposes of this definition,
25
+ "control" means (i) the power, direct or indirect, to cause the
26
+ direction or management of such entity, whether by contract or
27
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
28
+ outstanding shares, or (iii) beneficial ownership of such entity.
29
+
30
+ "You" (or "Your") shall mean an individual or Legal Entity
31
+ exercising permissions granted by this License.
32
+
33
+ "Source" form shall mean the preferred form for making modifications,
34
+ including but not limited to software source code, documentation
35
+ source, and configuration files.
36
+
37
+ "Object" form shall mean any form resulting from mechanical
38
+ transformation or translation of a Source form, including but
39
+ not limited to compiled object code, generated documentation,
40
+ and conversions to other media types.
41
+
42
+ "Work" shall mean the work of authorship, whether in Source or
43
+ Object form, made available under the License, as indicated by a
44
+ copyright notice that is included in or attached to the work
45
+ (an example is provided in the Appendix below).
46
+
47
+ "Derivative Works" shall mean any work, whether in Source or Object
48
+ form, that is based on (or derived from) the Work and for which the
49
+ editorial revisions, annotations, elaborations, or other modifications
50
+ represent, as a whole, an original work of authorship. For the purposes
51
+ of this License, Derivative Works shall not include works that remain
52
+ separable from, or merely link (or bind by name) to the interfaces of,
53
+ the Work and Derivative Works thereof.
54
+
55
+ "Contribution" shall mean any work of authorship, including
56
+ the original version of the Work and any modifications or additions
57
+ to that Work or Derivative Works thereof, that is intentionally
58
+ submitted to Licensor for inclusion in the Work by the copyright owner
59
+ or by an individual or Legal Entity authorized to submit on behalf of
60
+ the copyright owner. For the purposes of this definition, "submitted"
61
+ means any form of electronic, verbal, or written communication sent
62
+ to the Licensor or its representatives, including but not limited to
63
+ communication on electronic mailing lists, source code control systems,
64
+ and issue tracking systems that are managed by, or on behalf of, the
65
+ Licensor for the purpose of discussing and improving the Work, but
66
+ excluding communication that is conspicuously marked or otherwise
67
+ designated in writing by the copyright owner as "Not a Contribution."
68
+
69
+ "Contributor" shall mean Licensor and any individual or Legal Entity
70
+ on behalf of whom a Contribution has been received by Licensor and
71
+ subsequently incorporated within the Work.
72
+
73
+ 2. Grant of Copyright License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ copyright license to reproduce, prepare Derivative Works of,
77
+ publicly display, publicly perform, sublicense, and distribute the
78
+ Work and such Derivative Works in Source or Object form.
79
+
80
+ 3. Grant of Patent License. Subject to the terms and conditions of
81
+ this License, each Contributor hereby grants to You a perpetual,
82
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
83
+ (except as stated in this section) patent license to make, have made,
84
+ use, offer to sell, sell, import, and otherwise transfer the Work,
85
+ where such license applies only to those patent claims licensable
86
+ by such Contributor that are necessarily infringed by their
87
+ Contribution(s) alone or by combination of their Contribution(s)
88
+ with the Work to which such Contribution(s) was submitted. If You
89
+ institute patent litigation against any entity (including a
90
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
91
+ or a Contribution incorporated within the Work constitutes direct
92
+ or contributory patent infringement, then any patent licenses
93
+ granted to You under this License for that Work shall terminate
94
+ as of the date such litigation is filed.
95
+
96
+ 4. Redistribution. You may reproduce and distribute copies of the
97
+ Work or Derivative Works thereof in any medium, with or without
98
+ modifications, and in Source or Object form, provided that You
99
+ meet the following conditions:
100
+
101
+ (a) You must give any other recipients of the Work or
102
+ Derivative Works a copy of this License; and
103
+
104
+ (b) You must cause any modified files to carry prominent notices
105
+ stating that You changed the files; and
106
+
107
+ (c) You must retain, in the Source form of any Derivative Works
108
+ that You distribute, all copyright, patent, trademark, and
109
+ attribution notices from the Source form of the Work,
110
+ excluding those notices that do not pertain to any part of
111
+ the Derivative Works; and
112
+
113
+ (d) If the Work includes a "NOTICE" text file as part of its
114
+ distribution, then any Derivative Works that You distribute must
115
+ include a readable copy of the attribution notices contained
116
+ within such NOTICE file, excluding those notices that do not
117
+ pertain to any part of the Derivative Works, in at least one
118
+ of the following places: within a NOTICE text file distributed
119
+ as part of the Derivative Works; within the Source form or
120
+ documentation, if provided along with the Derivative Works; or,
121
+ within a display generated by the Derivative Works, if and
122
+ wherever such third-party notices normally appear. The contents
123
+ of the NOTICE file are for informational purposes only and
124
+ do not modify the License. You may add Your own attribution
125
+ notices within Derivative Works that You distribute, alongside
126
+ or as an addendum to the NOTICE text from the Work, provided
127
+ that such additional attribution notices cannot be construed
128
+ as modifying the License.
129
+
130
+ You may add Your own copyright statement to Your modifications and
131
+ may provide additional or different license terms and conditions
132
+ for use, reproduction, or distribution of Your modifications, or
133
+ for any such Derivative Works as a whole, provided Your use,
134
+ reproduction, and distribution of the Work otherwise complies with
135
+ the conditions stated in this License.
136
+
137
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
138
+ any Contribution intentionally submitted for inclusion in the Work
139
+ by You to the Licensor shall be under the terms and conditions of
140
+ this License, without any additional terms or conditions.
141
+ Notwithstanding the above, nothing herein shall supersede or modify
142
+ the terms of any separate license agreement you may have executed
143
+ with Licensor regarding such Contributions.
144
+
145
+ 6. Trademarks. This License does not grant permission to use the trade
146
+ names, trademarks, service marks, or product names of the Licensor,
147
+ except as required for reasonable and customary use in describing the
148
+ origin of the Work and reproducing the content of the NOTICE file.
149
+
150
+ 7. Disclaimer of Warranty. Unless required by applicable law or
151
+ agreed to in writing, Licensor provides the Work (and each
152
+ Contributor provides its Contributions) on an "AS IS" BASIS,
153
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
154
+ implied, including, without limitation, any warranties or conditions
155
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
156
+ PARTICULAR PURPOSE. You are solely responsible for determining the
157
+ appropriateness of using or redistributing the Work and assume any
158
+ risks associated with Your exercise of permissions under this License.
159
+
160
+ 8. Limitation of Liability. In no event and under no legal theory,
161
+ whether in tort (including negligence), contract, or otherwise,
162
+ unless required by applicable law (such as deliberate and grossly
163
+ negligent acts) or agreed to in writing, shall any Contributor be
164
+ liable to You for damages, including any direct, indirect, special,
165
+ incidental, or consequential damages of any character arising as a
166
+ result of this License or out of the use or inability to use the
167
+ Work (including but not limited to damages for loss of goodwill,
168
+ work stoppage, computer failure or malfunction, or any and all
169
+ other commercial damages or losses), even if such Contributor
170
+ has been advised of the possibility of such damages.
171
+
172
+ 9. Accepting Warranty or Additional Liability. While redistributing
173
+ the Work or Derivative Works thereof, You may choose to offer,
174
+ and charge a fee for, acceptance of support, warranty, indemnity,
175
+ or other liability obligations and/or rights consistent with this
176
+ License. However, in accepting such obligations, You may act only
177
+ on Your own behalf and on Your sole responsibility, not on behalf
178
+ of any other Contributor, and only if You agree to indemnify,
179
+ defend, and hold each Contributor harmless for any liability
180
+ incurred by, or claims asserted against, such Contributor by reason
181
+ of your accepting any such warranty or additional liability.
182
+
183
+ END OF TERMS AND CONDITIONS
184
+
185
+ APPENDIX: How to apply the Apache License to your work.
186
+
187
+ To apply the Apache License to your work, attach the following
188
+ boilerplate notice, with the fields enclosed by brackets "[]"
189
+ replaced with your own identifying information. (Don't include
190
+ the brackets!) The text should be enclosed in the appropriate
191
+ comment syntax for the file format. We also recommend that a
192
+ file or class name and description of purpose be included on the
193
+ same "printed page" as the copyright notice for easier
194
+ identification within third-party archives.
195
+
196
+ Copyright [yyyy] [name of copyright owner]
197
+
198
+ Licensed under the Apache License, Version 2.0 (the "License");
199
+ you may not use this file except in compliance with the License.
200
+ You may obtain a copy of the License at
201
+
202
+ http://www.apache.org/licenses/LICENSE-2.0
203
+
204
+ Unless required by applicable law or agreed to in writing, software
205
+ distributed under the License is distributed on an "AS IS" BASIS,
206
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
207
+ See the License for the specific language governing permissions and
208
+ limitations under the License.
209
+ License-File: LICENSE
210
+ Keywords: claude,document-ai,llm,ocr,openai,pdf,pymupdf,rag,tesseract,text-extraction
211
+ Classifier: Development Status :: 4 - Beta
212
+ Classifier: Environment :: Web Environment
213
+ Classifier: Framework :: FastAPI
214
+ Classifier: Intended Audience :: Developers
215
+ Classifier: Intended Audience :: Science/Research
216
+ Classifier: License :: OSI Approved :: Apache Software License
217
+ Classifier: Operating System :: OS Independent
218
+ Classifier: Programming Language :: Python :: 3
219
+ Classifier: Programming Language :: Python :: 3.10
220
+ Classifier: Programming Language :: Python :: 3.11
221
+ Classifier: Programming Language :: Python :: 3.12
222
+ Classifier: Programming Language :: Python :: 3.13
223
+ Classifier: Topic :: Scientific/Engineering :: Image Recognition
224
+ Classifier: Topic :: Text Processing
225
+ Requires-Python: >=3.10
226
+ Requires-Dist: anthropic>=1.0
227
+ Requires-Dist: fastapi>=0.110
228
+ Requires-Dist: google-genai>=1.0
229
+ Requires-Dist: jinja2>=3.1
230
+ Requires-Dist: openai>=1.40
231
+ Requires-Dist: pydantic-settings>=2.2
232
+ Requires-Dist: pymupdf>=1.24
233
+ Requires-Dist: python-multipart>=0.0.9
234
+ Requires-Dist: rapidfuzz>=3.6
235
+ Requires-Dist: uvicorn[standard]>=0.29
236
+ Provides-Extra: dev
237
+ Requires-Dist: httpx>=0.27; extra == 'dev'
238
+ Requires-Dist: pytest>=8; extra == 'dev'
239
+ Requires-Dist: rich>=13; extra == 'dev'
240
+ Requires-Dist: ruff>=0.5; extra == 'dev'
241
+ Description-Content-Type: text/markdown
242
+
243
+ <div align="center">
244
+
245
+ <img src="https://raw.githubusercontent.com/utkarsh5026/pyocr/main/docs/logo.svg" width="72" height="72" alt="pyocr-toolkit logo">
246
+
247
+ # pyocr-toolkit
248
+
249
+ **See exactly what text you get out of a PDF or image, and compare how different extraction methods read it.**
250
+
251
+ [![CI](https://github.com/utkarsh5026/pyocr/actions/workflows/ci.yml/badge.svg)](https://github.com/utkarsh5026/pyocr/actions/workflows/ci.yml)
252
+ ![Python](https://img.shields.io/badge/python-3.10%20%7C%203.11%20%7C%203.12%20%7C%203.13-3776ab?logo=python&logoColor=white)
253
+ [![License](https://img.shields.io/badge/license-Apache%202.0-4f46e5)](https://github.com/utkarsh5026/pyocr/blob/main/LICENSE)
254
+ ![Runs locally](https://img.shields.io/badge/runs-locally-15803d)
255
+
256
+ [**Website**](https://utkarsh5026.github.io/pyocr/) ·
257
+ [Install](#install) ·
258
+ [Tours](#tours) ·
259
+ [Providers](#configure-llm-providers) ·
260
+ [CLI](#command-line) ·
261
+ [How it works](#how-it-works)
262
+
263
+ <br>
264
+
265
+ <img src="https://raw.githubusercontent.com/utkarsh5026/pyocr/main/docs/tours/compare-light.webp" alt="Compare view, animated: Tesseract OCR scored against an LLM transcription of a scanned document, with the error rate per page and a word-level diff" width="100%">
266
+
267
+ <sub>▶ The <a href="https://utkarsh5026.github.io/pyocr/">website</a> opens with a 24-second video of what it does.</sub>
268
+
269
+ </div>
270
+
271
+ ---
272
+
273
+ Many GenAI workflows start with "get the text out of this PDF". **pyocr-toolkit** is a local web app (plus CLI) for
274
+ checking that step. Upload a document and you get three versions of every page:
275
+
276
+ | | Source | What it is | Good at | Weak at |
277
+ |---|---|---|---|---|
278
+ | 📄 | **Native text** | Text already embedded in the file (PyMuPDF) | Born-digital PDFs. Exact and instant. | Scans have none. Broken font maps produce gibberish. |
279
+ | 🔍 | **Tesseract OCR** | Classic OCR on the rendered page image | Free, local, fast, gives word positions | Tables, columns, poor scans, handwriting |
280
+ | ✨ | **LLM transcription** | A vision LLM told to copy the page *verbatim* | Hard pages, layout, context | Costs money. May quietly "fix" or skip text. |
281
+
282
+ Then you can:
283
+
284
+ - **Extract** page by page, a range like `1-5,9`, or the whole document, as background jobs
285
+ - **Compare** any two sources: character and word error rate (CER/WER), word-level diffs, a per-page chart
286
+ - **Search** across every document and every source at once
287
+ - **Export** clean text as TXT, Markdown, JSON or JSONL for your pipeline
288
+
289
+ **LLM providers:** Claude (Anthropic API), OpenAI, Azure OpenAI, Claude on Azure (Microsoft Foundry), Google
290
+ Gemini, and any OpenAI-compatible server (Ollama, vLLM, LM Studio, OpenRouter) for local or private models.
291
+
292
+ **Inputs:** PDF, XPS, EPUB, CBZ, MOBI, FB2, SVG, PNG, JPEG, TIFF (multi-page), BMP, GIF, WebP and anything else
293
+ [PyMuPDF](https://pymupdf.readthedocs.io/) opens.
294
+
295
+ ## Tours
296
+
297
+ Short recordings of the app on demo data (made by [`.claude/skills/demo/tour_shots.py`](https://github.com/utkarsh5026/pyocr/blob/main/.claude/skills/demo/tour_shots.py);
298
+ each is also in dark mode, as `docs/tours/*-dark.webp`).
299
+
300
+ <table>
301
+ <tr>
302
+ <td width="50%"><b>Page inspector</b>: a scanned page has no embedded text, so it's flagged <code>scan</code>; then its OCR
303
+ and LLM text, all three side by side, and a diff.<br><br><img src="https://raw.githubusercontent.com/utkarsh5026/pyocr/main/docs/tours/inspector-light.webp" alt="Page inspector tour"></td>
304
+ <td width="50%"><b>Compare</b>: Tesseract scored against an LLM across the document, a bar per page, and each page's
305
+ diff.<br><br><img src="https://raw.githubusercontent.com/utkarsh5026/pyocr/main/docs/tours/compare-light.webp" alt="Compare tour"></td>
306
+ </tr>
307
+ <tr>
308
+ <td><b>Search</b>: every document and every source at once; a hit opens on its page, highlighted on the image.<br><br><img src="https://raw.githubusercontent.com/utkarsh5026/pyocr/main/docs/tours/search-light.webp" alt="Search tour"></td>
309
+ <td><b>Upload and extract</b>: drop a scan, run Tesseract on every page as a background job, read the result.<br><br><img src="https://raw.githubusercontent.com/utkarsh5026/pyocr/main/docs/tours/upload-light.webp" alt="Upload and extract tour"></td>
310
+ </tr>
311
+ <tr>
312
+ <td colspan="2"><b>Library</b>: how much of each document has native, OCR and LLM text.<br><br><img src="https://raw.githubusercontent.com/utkarsh5026/pyocr/main/docs/tours/library-light.webp" alt="Library tour" width="50%"></td>
313
+ </tr>
314
+ </table>
315
+
316
+ > [!NOTE]
317
+ > The LLM in these recordings is a local stand-in that answers with each sample page's true text (and "fixes" one
318
+ > misspelling, as real models do), so they can be remade without an API key. Native text and OCR are the real thing.
319
+
320
+ ---
321
+
322
+ ## Install
323
+
324
+ You need **Python 3.10+**. **Tesseract** is optional but recommended (it enables the OCR source).
325
+
326
+ ```bash
327
+ # Tesseract (optional)
328
+ sudo apt-get install tesseract-ocr tesseract-ocr-eng # Debian / Ubuntu
329
+ brew install tesseract # macOS
330
+ choco install tesseract # Windows (or the UB Mannheim installer)
331
+ ```
332
+
333
+ **Option A: pipx** (recommended, installs it as an isolated command):
334
+
335
+ ```bash
336
+ pipx install git+https://github.com/utkarsh5026/pyocr
337
+ ```
338
+
339
+ **Option B: pip** in a virtual environment:
340
+
341
+ ```bash
342
+ python -m venv .venv && source .venv/bin/activate # Windows: .venv\Scripts\activate
343
+ pip install git+https://github.com/utkarsh5026/pyocr
344
+ ```
345
+
346
+ > [!NOTE]
347
+ > The PyPI name is `pyocr-toolkit` (plain `pyocr` is a different, unrelated library). Once it's published to
348
+ > PyPI, `pipx install pyocr-toolkit` will also work.
349
+
350
+ **Option C: Docker** (Tesseract and several language packs included):
351
+
352
+ ```bash
353
+ git clone https://github.com/utkarsh5026/pyocr && cd pyocr
354
+ cp .env.example .env # add your keys
355
+ docker compose up -d # → http://localhost:8000
356
+ ```
357
+
358
+ ## Run
359
+
360
+ ```bash
361
+ pyocr init # writes a .env template in the current folder: add the API keys you have
362
+ pyocr doctor # checks Tesseract, providers and the data folder
363
+ pyocr serve --open # starts the app on http://127.0.0.1:8000 and opens your browser
364
+ ```
365
+
366
+ Everything you upload and extract is stored in `./data` (change it with `DATA_DIR`). The in-app **Help** page
367
+ (`/help`) covers every feature in detail.
368
+
369
+ ## The web app
370
+
371
+ | Page | What you do there |
372
+ |---|---|
373
+ | **Home** `/` | Drop files to upload; see setup status and recent documents. |
374
+ | **Library** `/documents` | Document cards showing native / OCR / LLM coverage and how many pages still have no text. Filter by status, workspace or name; delete. |
375
+ | **Workspaces** `/workspaces` | Named groups of documents. Uploading several files or a `.zip` offers to create one, with suggested names (from the file names, or `adjective-scientist` like `festive-albattani`). Open one to rename it, add files or remove documents. |
376
+ | **Overview** `/documents/{id}` | Start background extraction (Tesseract or any LLM) for all pages or a range such as `1-5,9`; follow progress; see every *source* (engine + model + prompt) with token usage; export; page thumbnails. |
377
+ | **Page inspector** `/documents/{id}/pages/{n}` | Page image next to native, OCR and LLM text; run OCR or an LLM on just this page; per-page diff; a *Side by side* tab with all three texts in synced columns; search hits drawn on the image. Keyboard: `←/→`, `/`, `1-5`, `t`, `o`. |
378
+ | **Full text** `/documents/{id}/text` | Read the whole document from one source, optionally beside the page images; find, copy, download. |
379
+ | **Compare** `/documents/{id}/compare` | Score source B against source A on every page: document-level CER/WER, a clickable CER-per-page chart, and an aligned side-by-side diff of the selected page (opens on the worst page). Works for OCR vs LLM, native vs LLM, or **model vs model**. |
380
+ | **Search** `/search` | Search all documents at once. |
381
+ | **Jobs** `/jobs` | All background extractions, with progress, errors and tokens. |
382
+ | **Providers** `/providers` | Which settings are set or missing, a form to set keys/endpoints in the browser, plus a **Test connection** button per provider. |
383
+ | **Models** `/models` | Search a catalog of vision models rated for transcription (excellent / good / fair / not suitable, with price and reason); list the models your key can use and pick one. |
384
+ | **Help** `/help` | The full guide: concepts, metrics, workflows, troubleshooting. |
385
+ | **API docs** `/docs` | Interactive OpenAPI docs for the JSON API. |
386
+
387
+ ## Configure LLM providers
388
+
389
+ Paste keys on the **Providers** page (saved to `DATA_DIR/credentials.json`, owner-only, applied immediately and
390
+ taking precedence over the environment), or set them in `.env` (created by `pyocr init`) or as environment
391
+ variables and restart. Keys stay on the server and are never sent to the browser.
392
+
393
+ | Provider | Required | Optional |
394
+ |---|---|---|
395
+ | Claude (Anthropic API) | `ANTHROPIC_API_KEY` | `ANTHROPIC_MODEL` (default `claude-opus-5-5`), `ANTHROPIC_EFFORT` |
396
+ | OpenAI | `OPENAI_API_KEY` | `OPENAI_MODEL` (default `gpt-6.2-sol`), `OPENAI_BASE_URL` |
397
+ | Azure OpenAI | `AZURE_OPENAI_API_KEY`, `AZURE_OPENAI_ENDPOINT` | `AZURE_OPENAI_DEPLOYMENT`, `AZURE_OPENAI_API_VERSION` |
398
+ | Claude on Azure (Foundry) | `ANTHROPIC_FOUNDRY_API_KEY`, `ANTHROPIC_FOUNDRY_RESOURCE` | `ANTHROPIC_FOUNDRY_MODEL` |
399
+ | Google Gemini | `GEMINI_API_KEY` | `GEMINI_MODEL` (default `gemini-3.8-flash`) |
400
+ | Ollama / vLLM / LM Studio / OpenRouter | `OPENAI_COMPATIBLE_BASE_URL` | `OPENAI_COMPATIBLE_MODEL`, `OPENAI_COMPATIBLE_API_KEY` |
401
+
402
+ Any model or deployment name can be typed in the UI; the defaults are just starting points. The **Models** page
403
+ and the hint under each model box say whether a model suits transcription (custom names are marked as such). The model must accept
404
+ images. For a fully local setup, run Ollama with a vision model and set
405
+ `OPENAI_COMPATIBLE_BASE_URL=http://localhost:11434/v1`.
406
+
407
+ ## Command line
408
+
409
+ ```bash
410
+ pyocr extract report.pdf --engine llm -p anthropic --pages 1-5 --format jsonl -o report.jsonl
411
+ pyocr extract scan.tiff --engine ocr --format md # Tesseract, Markdown to stdout
412
+ pyocr extract born-digital.pdf --engine native # embedded text only, no network
413
+ pyocr compare scan.pdf -p openai -m gpt-6.2-sol # per-page OCR / native CER vs an LLM
414
+ pyocr import a.pdf b.pdf scans.zip folder/ -w invoices # add many files as one workspace (zips unpacked)
415
+ pyocr providers # which providers are ready
416
+ python -m pyocr_toolkit --help # same CLI without the script on PATH
417
+ ```
418
+
419
+ Documents processed on the command line also appear in the web app's library.
420
+
421
+ ### Batch uploads and workspaces
422
+
423
+ Upload several files, or a `.zip`, and they land together in a **workspace** whose name you can edit. pyocr suggests
424
+ names: the one the files share (`invoices-2024.zip` → `invoices-2024`) first, then short `adjective-scientist` ideas.
425
+ Zips are unpacked; files that can't be used (unsupported type, zip in a zip, encrypted, broken) are skipped and
426
+ reported with the reason. A single file still uploads straight to the library. Workspaces only reference documents
427
+ (`data/workspaces/<id>.json`), so removing a document from one, or deleting a workspace, keeps the document unless
428
+ you ask otherwise.
429
+
430
+ ## How it works
431
+
432
+ 1. **Native text.** A PDF page is a list of drawing instructions ("glyph 37 at (72, 700)"). Born-digital files map
433
+ each glyph back to a character, so the text can be rebuilt exactly. A scan is only a picture, so it has no text.
434
+ 2. **OCR.** The page is rendered to pixels (300 DPI) and Tesseract recognises characters from their shapes,
435
+ reporting a box for each word. That is why search can highlight OCR hits on the page.
436
+ 3. **LLM.** The page image goes to a vision model with a strict "transcribe, don't correct" prompt
437
+ ([`prompts.py`](https://github.com/utkarsh5026/pyocr/blob/main/src/pyocr_toolkit/llm/prompts.py)). It reads in context, so it is strong on hard pages, but it can
438
+ "fix" typos, which the diff view exposes.
439
+ 4. **Comparison.** *Edit distance* is the minimum number of character insertions, deletions and substitutions
440
+ between two texts. **CER** = edits / reference characters; **WER** is the same count over words. For example,
441
+ "the cat sat" → "the bat sat" has 1 edit, so CER = 1/11 = 9%. Whitespace is normalised first, because line
442
+ breaks aren't reading errors. Disagreement between two engines is not proof of error: compare against a
443
+ born-digital PDF's native text when you need ground truth.
444
+
445
+ The Help page explains each of these in more depth.
446
+
447
+ ## Privacy and security
448
+
449
+ - Uploads, OCR output and LLM output are stored as plain files under `DATA_DIR`.
450
+ - A page image is sent to an LLM provider only when you start a transcription, and only to the provider you
451
+ picked. Native text and Tesseract run entirely locally.
452
+
453
+ > [!WARNING]
454
+ > **There is no login.** `pyocr serve` listens on `127.0.0.1` by default. If you use `--host 0.0.0.0` or Docker,
455
+ > put it behind your own authentication.
456
+
457
+ ## Development
458
+
459
+ ```bash
460
+ git clone https://github.com/utkarsh5026/pyocr && cd pyocr
461
+ pip install -e ".[dev]"
462
+ pytest # LLM providers are tested against mocked HTTP: no keys, no network
463
+ ruff check src tests
464
+ pyocr serve
465
+ ```
466
+
467
+ Or use the task runner: `make` lists every developer command grouped by category (`make install`, `make check`,
468
+ `make dev` for auto-reload, `make docker-up`, ...). Without `make` (e.g. on Windows), run `python makefile.py <task>`.
469
+
470
+ See [CONTRIBUTING.md](https://github.com/utkarsh5026/pyocr/blob/main/CONTRIBUTING.md) for the code layout and how to add a provider.
471
+
472
+ The project website lives in [`docs/`](https://github.com/utkarsh5026/pyocr/tree/main/docs) (plain HTML and CSS, no build step) and is deployed to GitHub Pages by
473
+ [`.github/workflows/pages.yml`](https://github.com/utkarsh5026/pyocr/blob/main/.github/workflows/pages.yml) on every push to `main` that touches it. Its media are
474
+ made from code, on demo data that needs no API key:
475
+
476
+ ```bash
477
+ python .claude/skills/demo/tour_shots.py # docs/tours/*.webp: the app's tours, light and dark (needs Tesseract, Playwright)
478
+ cd hero-video && npm install && npm run render # docs/media/hero-demo.mp4: the website's hero video (Remotion)
479
+ ```
480
+
481
+ ## License
482
+
483
+ Apache-2.0. See [LICENSE](https://github.com/utkarsh5026/pyocr/blob/main/LICENSE).
@@ -0,0 +1,57 @@
1
+ pyocr_toolkit/__init__.py,sha256=1I23fM8K9PSjWatHomx7SU-eDdy4ZXwRK4g8i3LowGg,131
2
+ pyocr_toolkit/__main__.py,sha256=bYt9eEaoRQWdejEHFD8REx9jxVEdZptECFsV7F49Ink,30
3
+ pyocr_toolkit/api.py,sha256=-_kGqGLBxhTz_HXDkCRV2GPB2_5QOAtilyHX7BZp8Y8,29025
4
+ pyocr_toolkit/cli.py,sha256=NRN0-__brqx2r9Cg2BtnceHn22-mHvMMx_eQgzIpAmQ,14259
5
+ pyocr_toolkit/compare.py,sha256=Z3PWSp_iCSCA12YBKemrr8jrTHZHicrRGZpvHeadpjs,5547
6
+ pyocr_toolkit/config.py,sha256=eaHC67Hp7AA6p25o_oO0gIdBwjnQDEJbH0JKiDOzd50,3369
7
+ pyocr_toolkit/credentials.py,sha256=PweR1du-7yuBQPU1fjCDpIp1r-tKC0s9gmZ7JJix1t4,4759
8
+ pyocr_toolkit/documents.py,sha256=HNu85-b_ZGWJ6zWFDhgy57k-OmWSbVvtnnGNvktvntM,13002
9
+ pyocr_toolkit/env.example,sha256=ertHObJpUOzsRbVqsLB3oeKT_szkSxW5vCBWwLrnhEY,1984
10
+ pyocr_toolkit/jobs.py,sha256=l1R3dFwNOEIlmfxG9wUrmTqfJ66Fj5GRw-hrjw1vpno,8967
11
+ pyocr_toolkit/search.py,sha256=8xDwAeZzy1rYg_pTUK-F6SS3RnNCUvnzuBl5Z1NWOEU,2945
12
+ pyocr_toolkit/service.py,sha256=eeEz_FrFoNZI82C6Rw-r9l9T9P7chCNolBE6yJXpv0s,12646
13
+ pyocr_toolkit/web.py,sha256=A8SuSZpujMmFDOBDaEy5vxJd4EPPVBCEgy8LSNgaWcQ,8649
14
+ pyocr_toolkit/workspaces.py,sha256=Q4Yuk_smVw82nZkz-Cz7pT5P2vvfjM5qMTgrHnbQ7Vs,13395
15
+ pyocr_toolkit/llm/__init__.py,sha256=dP9m96M0TBMfNl9RRxHpG7j3JGVVKXyOKldrjKDWzHc,1109
16
+ pyocr_toolkit/llm/anthropic_provider.py,sha256=2XXs52zDG5v1LYe4JLAHrKH1G3M01gDt-s6aim7Nq90,7940
17
+ pyocr_toolkit/llm/base.py,sha256=JRGBL2auR5M5vLevcNW9I_d6UKDg6af1TVp51e0ZVjQ,4465
18
+ pyocr_toolkit/llm/catalog.py,sha256=HZfgSMHpeFN4_fUmP9p1oxAYDkpevkLosrAPMdsVhvQ,19962
19
+ pyocr_toolkit/llm/gemini_provider.py,sha256=QhTBLNLzJMcRfwNgQUW6r7dFrFhGFZGD7nSWpHjyL3E,3959
20
+ pyocr_toolkit/llm/openai_provider.py,sha256=OqkqyFhXtc3WK80uT-3nOSxQArQuwA3woURv4CE2lqI,7412
21
+ pyocr_toolkit/llm/prompts.py,sha256=04ob_iQw1AMzP9uKlZhuNhqd2ux3ZJxPom6XDH4lSYs,2680
22
+ pyocr_toolkit/static/common.js,sha256=TwZgRtGSF_ugiYEUFiHKfMaJ7yDJvc9rV6msiMGvqXw,25387
23
+ pyocr_toolkit/static/compare.js,sha256=inYKcXWC4uxVX8Tbt4XhROGuofhWp5Ccbf_HMoC6AP8,8152
24
+ pyocr_toolkit/static/document.js,sha256=plVM9Yg40_VjKbh1eMJkY1pMrczWiPro3-Bv2jIdnEM,3749
25
+ pyocr_toolkit/static/jobs.js,sha256=xsvjIBKepgA_9XAZXXg2Zu5BuN3uKop0pLi_z4Akblo,448
26
+ pyocr_toolkit/static/library.js,sha256=ocaepRp_M4qOO6AxHWCMTTEKMo5wCsoapk9YH_okgHI,1181
27
+ pyocr_toolkit/static/models.js,sha256=bZZo5LaOwA_ikAuAmNONmGQLS6G1uWMuPqWCdl8Sxmw,5377
28
+ pyocr_toolkit/static/providers.js,sha256=sXc0ck5hzsXjcXkrdYBJxzheUMaKIPnISG5gSICI6WQ,2215
29
+ pyocr_toolkit/static/reader.js,sha256=_TrsznuW5Nj4rhE1mECEU3InAChIf7q7UYJZR7Nryvc,3750
30
+ pyocr_toolkit/static/search.js,sha256=p7wpn-5Fm1m44pbht3XmFsmAl93cU0kEs0pDBO82WMg,1718
31
+ pyocr_toolkit/static/styles.css,sha256=8dh1SCQW0kq_OlVwKrgTb9MrdHhOwnNFOidAJ70Gqt8,58563
32
+ pyocr_toolkit/static/workspace.js,sha256=hKH2qN248popnAfy_Pb-BxHayCFyU3X_tT5XNOOcSEA,19377
33
+ pyocr_toolkit/static/workspaces.js,sha256=v28mma0OHYOX56oQEeATZWiJVNYbS4E2E3pqK4BOgR4,3772
34
+ pyocr_toolkit/templates/_doc_card.html,sha256=PdSqH8gc0HJ0b1-KT2cLQEY-gg-K_IDEGGH_0AUXJTY,2690
35
+ pyocr_toolkit/templates/_doctabs.html,sha256=9JeZhAWmTYiW6A74rphoBlgAbfY1KT7MtvcZ_qktq9Y,1106
36
+ pyocr_toolkit/templates/_icons.html,sha256=DzHlr4b8UFhyUfmGL6OsUinIQKr7EmexiFVfDJbtOSI,5785
37
+ pyocr_toolkit/templates/_llm_picker.html,sha256=YHwuM2d4tZpEP688lpJX2z-pINBN3wYiaeh4Il6VaFE,618
38
+ pyocr_toolkit/templates/base.html,sha256=_UIelzXFoY7FabOySVYCRatWpwXU9OsIPoSkcxLeIpw,5725
39
+ pyocr_toolkit/templates/compare.html,sha256=R7V8WMC1LhcOmMZoSc-xQ2bO_ZhEGmqO0inJSrm-va0,4143
40
+ pyocr_toolkit/templates/document.html,sha256=2S5e47IMG7k0RZaQFIRtVQ-zSSUPSPaTsk0zlrqyumM,4351
41
+ pyocr_toolkit/templates/error.html,sha256=i-GxJfg_mEgzbMRCt-g4qiTDd4weJr8PLvZ6sAeZglA,438
42
+ pyocr_toolkit/templates/help.html,sha256=fGaZlGgXfJxR1Zt7q5DObHuLuPb6Ds-gPNvQM5DosPQ,20993
43
+ pyocr_toolkit/templates/home.html,sha256=TSV_k2vYkXPxC77ejROb3opVEt7qVoM0S7VSHpJttc4,4811
44
+ pyocr_toolkit/templates/jobs.html,sha256=ahCJfjxFQ5Blfk8dgDh9sg5QcOxqo0O2FfiUr6Lxr_A,782
45
+ pyocr_toolkit/templates/library.html,sha256=WgmI62ginxScjM_VBW0Opizza8y8byyg98VhQIupYpI,2137
46
+ pyocr_toolkit/templates/models.html,sha256=ZnsOUYgLHg2PFNLXg0-XXGS6UaxOz-atoGC0If_Monk,3793
47
+ pyocr_toolkit/templates/providers.html,sha256=2eGtHr3F5c4GTYXsxTeBba6HE8mSInM-FZ-SURA-WJc,6810
48
+ pyocr_toolkit/templates/reader.html,sha256=O8ev42I_TSwvWdqmRT9d_VNMk_NEfLkAczfwoX_shE4,1294
49
+ pyocr_toolkit/templates/search.html,sha256=_l3mJ44-1IMusOfBCgnSCQfVy5YU_fqd19sNJppituM,1063
50
+ pyocr_toolkit/templates/workspace.html,sha256=yVsiQa15jF1Ubi9ey770ZY63oINz2rvPLsSATYCvIm4,5992
51
+ pyocr_toolkit/templates/workspace_detail.html,sha256=lPuGx8W5_SZ4pGix5NHr2HJCrKlhjmWnrv2SGJVe96M,2358
52
+ pyocr_toolkit/templates/workspaces.html,sha256=Ej-gpP_ijySyRJyp3XzPXcV84bNgkKYO9u7WoapqhEM,1938
53
+ pyocr_toolkit-0.3.0.dist-info/METADATA,sha256=wV_8-7RDov5S1pFUOx4Y-RpX-zXqIiGHl1rtBQ5Y5ok,29027
54
+ pyocr_toolkit-0.3.0.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
55
+ pyocr_toolkit-0.3.0.dist-info/entry_points.txt,sha256=GlgtjglwQ4Lqd_j7uyMGFjSNka3clKOKhOIqGsgUovI,88
56
+ pyocr_toolkit-0.3.0.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
57
+ pyocr_toolkit-0.3.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: hatchling 1.33.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,3 @@
1
+ [console_scripts]
2
+ pyocr = pyocr_toolkit.cli:main
3
+ pyocr-toolkit = pyocr_toolkit.cli:main