pyocr-toolkit 0.3.0__tar.gz → 0.5.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.
- {pyocr_toolkit-0.3.0 → pyocr_toolkit-0.5.0}/.env.example +28 -0
- {pyocr_toolkit-0.3.0 → pyocr_toolkit-0.5.0}/CHANGELOG.md +59 -0
- {pyocr_toolkit-0.3.0 → pyocr_toolkit-0.5.0}/PKG-INFO +100 -10
- {pyocr_toolkit-0.3.0 → pyocr_toolkit-0.5.0}/README.md +74 -7
- {pyocr_toolkit-0.3.0 → pyocr_toolkit-0.5.0}/pyproject.toml +16 -4
- {pyocr_toolkit-0.3.0 → pyocr_toolkit-0.5.0}/src/pyocr_toolkit/__init__.py +1 -1
- {pyocr_toolkit-0.3.0 → pyocr_toolkit-0.5.0}/src/pyocr_toolkit/api.py +158 -50
- pyocr_toolkit-0.5.0/src/pyocr_toolkit/brands.py +56 -0
- {pyocr_toolkit-0.3.0 → pyocr_toolkit-0.5.0}/src/pyocr_toolkit/cli.py +110 -25
- {pyocr_toolkit-0.3.0 → pyocr_toolkit-0.5.0}/src/pyocr_toolkit/config.py +56 -0
- {pyocr_toolkit-0.3.0 → pyocr_toolkit-0.5.0}/src/pyocr_toolkit/credentials.py +23 -8
- {pyocr_toolkit-0.3.0 → pyocr_toolkit-0.5.0}/src/pyocr_toolkit/documents.py +100 -19
- {pyocr_toolkit-0.3.0 → pyocr_toolkit-0.5.0}/src/pyocr_toolkit/env.example +28 -0
- pyocr_toolkit-0.5.0/src/pyocr_toolkit/export.py +146 -0
- {pyocr_toolkit-0.3.0 → pyocr_toolkit-0.5.0}/src/pyocr_toolkit/jobs.py +77 -28
- {pyocr_toolkit-0.3.0 → pyocr_toolkit-0.5.0}/src/pyocr_toolkit/llm/__init__.py +15 -1
- {pyocr_toolkit-0.3.0 → pyocr_toolkit-0.5.0}/src/pyocr_toolkit/llm/anthropic_provider.py +20 -11
- {pyocr_toolkit-0.3.0 → pyocr_toolkit-0.5.0}/src/pyocr_toolkit/llm/base.py +30 -14
- {pyocr_toolkit-0.3.0 → pyocr_toolkit-0.5.0}/src/pyocr_toolkit/llm/gemini_provider.py +12 -4
- {pyocr_toolkit-0.3.0 → pyocr_toolkit-0.5.0}/src/pyocr_toolkit/llm/openai_provider.py +10 -8
- pyocr_toolkit-0.5.0/src/pyocr_toolkit/llm/prompts.py +135 -0
- pyocr_toolkit-0.5.0/src/pyocr_toolkit/ocr/__init__.py +34 -0
- pyocr_toolkit-0.5.0/src/pyocr_toolkit/ocr/base.py +271 -0
- pyocr_toolkit-0.5.0/src/pyocr_toolkit/ocr/cloud.py +301 -0
- pyocr_toolkit-0.5.0/src/pyocr_toolkit/ocr/local.py +188 -0
- pyocr_toolkit-0.5.0/src/pyocr_toolkit/ocr/tesseract.py +71 -0
- pyocr_toolkit-0.5.0/src/pyocr_toolkit/pdftext.py +217 -0
- pyocr_toolkit-0.5.0/src/pyocr_toolkit/preprocess.py +332 -0
- pyocr_toolkit-0.5.0/src/pyocr_toolkit/service.py +606 -0
- {pyocr_toolkit-0.3.0 → pyocr_toolkit-0.5.0}/src/pyocr_toolkit/static/common.js +47 -1
- {pyocr_toolkit-0.3.0 → pyocr_toolkit-0.5.0}/src/pyocr_toolkit/static/compare.js +5 -2
- pyocr_toolkit-0.5.0/src/pyocr_toolkit/static/document.js +292 -0
- pyocr_toolkit-0.5.0/src/pyocr_toolkit/static/logos/README.md +12 -0
- pyocr_toolkit-0.5.0/src/pyocr_toolkit/static/logos/claude.svg +1 -0
- pyocr_toolkit-0.5.0/src/pyocr_toolkit/static/logos/googlecloud.svg +1 -0
- pyocr_toolkit-0.5.0/src/pyocr_toolkit/static/logos/googlegemini.svg +1 -0
- pyocr_toolkit-0.5.0/src/pyocr_toolkit/static/logos/mistralai.svg +1 -0
- pyocr_toolkit-0.5.0/src/pyocr_toolkit/static/logos/paddlepaddle.svg +1 -0
- {pyocr_toolkit-0.3.0 → pyocr_toolkit-0.5.0}/src/pyocr_toolkit/static/providers.js +29 -2
- {pyocr_toolkit-0.3.0 → pyocr_toolkit-0.5.0}/src/pyocr_toolkit/static/reader.js +4 -1
- {pyocr_toolkit-0.3.0 → pyocr_toolkit-0.5.0}/src/pyocr_toolkit/static/search.js +6 -2
- {pyocr_toolkit-0.3.0 → pyocr_toolkit-0.5.0}/src/pyocr_toolkit/static/styles.css +130 -2
- pyocr_toolkit-0.5.0/src/pyocr_toolkit/static/workspace.js +854 -0
- pyocr_toolkit-0.5.0/src/pyocr_toolkit/templates/_brand.html +9 -0
- {pyocr_toolkit-0.3.0 → pyocr_toolkit-0.5.0}/src/pyocr_toolkit/templates/_icons.html +1 -0
- {pyocr_toolkit-0.3.0 → pyocr_toolkit-0.5.0}/src/pyocr_toolkit/templates/_llm_picker.html +1 -1
- {pyocr_toolkit-0.3.0 → pyocr_toolkit-0.5.0}/src/pyocr_toolkit/templates/base.html +1 -1
- pyocr_toolkit-0.5.0/src/pyocr_toolkit/templates/document.html +138 -0
- {pyocr_toolkit-0.3.0 → pyocr_toolkit-0.5.0}/src/pyocr_toolkit/templates/help.html +96 -5
- {pyocr_toolkit-0.3.0 → pyocr_toolkit-0.5.0}/src/pyocr_toolkit/templates/home.html +6 -5
- {pyocr_toolkit-0.3.0 → pyocr_toolkit-0.5.0}/src/pyocr_toolkit/templates/providers.html +83 -37
- pyocr_toolkit-0.5.0/src/pyocr_toolkit/templates/workspace.html +171 -0
- {pyocr_toolkit-0.3.0 → pyocr_toolkit-0.5.0}/src/pyocr_toolkit/templates/workspace_detail.html +1 -1
- {pyocr_toolkit-0.3.0 → pyocr_toolkit-0.5.0}/src/pyocr_toolkit/web.py +6 -3
- pyocr_toolkit-0.5.0/tests/test_batch.py +258 -0
- pyocr_toolkit-0.5.0/tests/test_ocr_engines.py +503 -0
- pyocr_toolkit-0.5.0/tests/test_pdftext.py +140 -0
- pyocr_toolkit-0.5.0/tests/test_preprocess.py +187 -0
- {pyocr_toolkit-0.3.0 → pyocr_toolkit-0.5.0}/tests/test_web.py +59 -1
- pyocr_toolkit-0.3.0/src/pyocr_toolkit/llm/prompts.py +0 -61
- pyocr_toolkit-0.3.0/src/pyocr_toolkit/service.py +0 -269
- pyocr_toolkit-0.3.0/src/pyocr_toolkit/static/document.js +0 -89
- pyocr_toolkit-0.3.0/src/pyocr_toolkit/static/workspace.js +0 -420
- pyocr_toolkit-0.3.0/src/pyocr_toolkit/templates/document.html +0 -80
- pyocr_toolkit-0.3.0/src/pyocr_toolkit/templates/workspace.html +0 -109
- {pyocr_toolkit-0.3.0 → pyocr_toolkit-0.5.0}/.gitignore +0 -0
- {pyocr_toolkit-0.3.0 → pyocr_toolkit-0.5.0}/CONTRIBUTING.md +0 -0
- {pyocr_toolkit-0.3.0 → pyocr_toolkit-0.5.0}/LICENSE +0 -0
- {pyocr_toolkit-0.3.0 → pyocr_toolkit-0.5.0}/hero-video/README.md +0 -0
- {pyocr_toolkit-0.3.0 → pyocr_toolkit-0.5.0}/hero-video/src/HeroDemo.tsx +0 -0
- {pyocr_toolkit-0.3.0 → pyocr_toolkit-0.5.0}/hero-video/src/Root.tsx +0 -0
- {pyocr_toolkit-0.3.0 → pyocr_toolkit-0.5.0}/hero-video/src/assets.d.ts +0 -0
- {pyocr_toolkit-0.3.0 → pyocr_toolkit-0.5.0}/hero-video/src/index.ts +0 -0
- {pyocr_toolkit-0.3.0 → pyocr_toolkit-0.5.0}/hero-video/src/motion.tsx +0 -0
- {pyocr_toolkit-0.3.0 → pyocr_toolkit-0.5.0}/hero-video/src/scenes/CatchScene.tsx +0 -0
- {pyocr_toolkit-0.3.0 → pyocr_toolkit-0.5.0}/hero-video/src/scenes/ColdOpenScene.tsx +0 -0
- {pyocr_toolkit-0.3.0 → pyocr_toolkit-0.5.0}/hero-video/src/scenes/MeasureScene.tsx +0 -0
- {pyocr_toolkit-0.3.0 → pyocr_toolkit-0.5.0}/hero-video/src/scenes/MontageScene.tsx +0 -0
- {pyocr_toolkit-0.3.0 → pyocr_toolkit-0.5.0}/hero-video/src/scenes/OutroScene.tsx +0 -0
- {pyocr_toolkit-0.3.0 → pyocr_toolkit-0.5.0}/hero-video/src/scenes/ThreeWaysScene.tsx +0 -0
- {pyocr_toolkit-0.3.0 → pyocr_toolkit-0.5.0}/hero-video/src/theme.ts +0 -0
- {pyocr_toolkit-0.3.0 → pyocr_toolkit-0.5.0}/hero-video/src/ui.tsx +0 -0
- {pyocr_toolkit-0.3.0 → pyocr_toolkit-0.5.0}/src/pyocr_toolkit/__main__.py +0 -0
- {pyocr_toolkit-0.3.0 → pyocr_toolkit-0.5.0}/src/pyocr_toolkit/compare.py +0 -0
- {pyocr_toolkit-0.3.0 → pyocr_toolkit-0.5.0}/src/pyocr_toolkit/llm/catalog.py +0 -0
- {pyocr_toolkit-0.3.0 → pyocr_toolkit-0.5.0}/src/pyocr_toolkit/search.py +0 -0
- {pyocr_toolkit-0.3.0 → pyocr_toolkit-0.5.0}/src/pyocr_toolkit/static/jobs.js +0 -0
- {pyocr_toolkit-0.3.0 → pyocr_toolkit-0.5.0}/src/pyocr_toolkit/static/library.js +0 -0
- {pyocr_toolkit-0.3.0 → pyocr_toolkit-0.5.0}/src/pyocr_toolkit/static/models.js +0 -0
- {pyocr_toolkit-0.3.0 → pyocr_toolkit-0.5.0}/src/pyocr_toolkit/static/workspaces.js +0 -0
- {pyocr_toolkit-0.3.0 → pyocr_toolkit-0.5.0}/src/pyocr_toolkit/templates/_doc_card.html +0 -0
- {pyocr_toolkit-0.3.0 → pyocr_toolkit-0.5.0}/src/pyocr_toolkit/templates/_doctabs.html +0 -0
- {pyocr_toolkit-0.3.0 → pyocr_toolkit-0.5.0}/src/pyocr_toolkit/templates/compare.html +0 -0
- {pyocr_toolkit-0.3.0 → pyocr_toolkit-0.5.0}/src/pyocr_toolkit/templates/error.html +0 -0
- {pyocr_toolkit-0.3.0 → pyocr_toolkit-0.5.0}/src/pyocr_toolkit/templates/jobs.html +0 -0
- {pyocr_toolkit-0.3.0 → pyocr_toolkit-0.5.0}/src/pyocr_toolkit/templates/library.html +0 -0
- {pyocr_toolkit-0.3.0 → pyocr_toolkit-0.5.0}/src/pyocr_toolkit/templates/models.html +0 -0
- {pyocr_toolkit-0.3.0 → pyocr_toolkit-0.5.0}/src/pyocr_toolkit/templates/reader.html +0 -0
- {pyocr_toolkit-0.3.0 → pyocr_toolkit-0.5.0}/src/pyocr_toolkit/templates/search.html +0 -0
- {pyocr_toolkit-0.3.0 → pyocr_toolkit-0.5.0}/src/pyocr_toolkit/templates/workspaces.html +0 -0
- {pyocr_toolkit-0.3.0 → pyocr_toolkit-0.5.0}/src/pyocr_toolkit/workspaces.py +0 -0
- {pyocr_toolkit-0.3.0 → pyocr_toolkit-0.5.0}/tests/__init__.py +0 -0
- {pyocr_toolkit-0.3.0 → pyocr_toolkit-0.5.0}/tests/conftest.py +0 -0
- {pyocr_toolkit-0.3.0 → pyocr_toolkit-0.5.0}/tests/test_api.py +0 -0
- {pyocr_toolkit-0.3.0 → pyocr_toolkit-0.5.0}/tests/test_core.py +0 -0
- {pyocr_toolkit-0.3.0 → pyocr_toolkit-0.5.0}/tests/test_makefile.py +0 -0
- {pyocr_toolkit-0.3.0 → pyocr_toolkit-0.5.0}/tests/test_models.py +0 -0
- {pyocr_toolkit-0.3.0 → pyocr_toolkit-0.5.0}/tests/test_providers.py +0 -0
- {pyocr_toolkit-0.3.0 → pyocr_toolkit-0.5.0}/tests/test_workspaces.py +0 -0
|
@@ -35,6 +35,33 @@ GEMINI_API_KEY=
|
|
|
35
35
|
# OPENAI_COMPATIBLE_MODEL=qwen2.5vl:7b
|
|
36
36
|
# OPENAI_COMPATIBLE_API_KEY=
|
|
37
37
|
|
|
38
|
+
# --- Extra OCR engines (Tesseract needs no settings) ------------------------------
|
|
39
|
+
# Local engines need an extra install, e.g. pip install "pyocr-toolkit[easyocr]"
|
|
40
|
+
# (extras: rapidocr, easyocr, paddleocr, doctr, textract). See `pyocr engines`.
|
|
41
|
+
# EASYOCR_LANGUAGES=en # comma-separated, e.g. en,de
|
|
42
|
+
# PADDLEOCR_LANGUAGE=en # e.g. en, ch, german, japan
|
|
43
|
+
# OCR_GPU=false # EasyOCR / PaddleOCR / docTR on a CUDA GPU
|
|
44
|
+
# OCR_MAX_EDGE_PX=4000 # longest edge of the image given to these engines
|
|
45
|
+
# OCR_TIMEOUT_S=120
|
|
46
|
+
|
|
47
|
+
# Google Cloud Vision (an API key with the Cloud Vision API enabled)
|
|
48
|
+
GOOGLE_VISION_API_KEY=
|
|
49
|
+
# GOOGLE_VISION_LANGUAGE_HINTS= # e.g. en,de; empty = auto-detect
|
|
50
|
+
|
|
51
|
+
# Azure AI Document Intelligence (prebuilt-read)
|
|
52
|
+
AZURE_DOCUMENT_INTELLIGENCE_ENDPOINT=
|
|
53
|
+
AZURE_DOCUMENT_INTELLIGENCE_KEY=
|
|
54
|
+
|
|
55
|
+
# AWS Textract (credentials may also come from ~/.aws or AWS_PROFILE)
|
|
56
|
+
# AWS_REGION=us-east-1
|
|
57
|
+
# AWS_ACCESS_KEY_ID=
|
|
58
|
+
# AWS_SECRET_ACCESS_KEY=
|
|
59
|
+
# AWS_SESSION_TOKEN=
|
|
60
|
+
|
|
61
|
+
# Mistral OCR
|
|
62
|
+
MISTRAL_API_KEY=
|
|
63
|
+
# MISTRAL_OCR_MODEL=mistral-ocr-latest
|
|
64
|
+
|
|
38
65
|
# --- Storage, rendering and OCR ---------------------------------------------------
|
|
39
66
|
# DATA_DIR=data
|
|
40
67
|
# MAX_UPLOAD_MB=200
|
|
@@ -45,4 +72,5 @@ GEMINI_API_KEY=
|
|
|
45
72
|
# TESSERACT_LANGUAGE=eng # e.g. eng+deu (install the language packs first)
|
|
46
73
|
# LLM_CONCURRENCY=4
|
|
47
74
|
# LLM_TIMEOUT_S=300
|
|
75
|
+
# LLM_BATCH_MAX_OUTPUT_TOKENS=32000 # output limit when several pages go in one request
|
|
48
76
|
# USD_INR_RATE=92.5 # rupees per dollar, for showing LLM costs in ₹ (not fetched live)
|
|
@@ -2,6 +2,65 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## 0.5.0 - 2026-11-27
|
|
6
|
+
|
|
7
|
+
- **More OCR engines.** Besides Tesseract: RapidOCR, EasyOCR, PaddleOCR and docTR (local, optional extras such as
|
|
8
|
+
`pip install "pyocr-toolkit[easyocr]"`), and Google Cloud Vision, Azure AI Document Intelligence, AWS Textract
|
|
9
|
+
and Mistral OCR (cloud, configured with environment variables). Each engine is a separate source
|
|
10
|
+
(`ocr:<engine>`; `ocr` stays Tesseract) that can be searched, compared and exported.
|
|
11
|
+
- The page inspector, Overview extract form, background jobs and the CLI (`--engine ocr:<engine>`,
|
|
12
|
+
`--ocr-engine`, `pyocr engines`) can pick the OCR engine. The Providers page lists every engine with its status
|
|
13
|
+
and a Test button, and cloud OCR keys and engine settings can be saved there like LLM provider credentials.
|
|
14
|
+
- New settings: `GOOGLE_VISION_API_KEY`, `GOOGLE_VISION_LANGUAGE_HINTS`, `AZURE_DOCUMENT_INTELLIGENCE_ENDPOINT`,
|
|
15
|
+
`AZURE_DOCUMENT_INTELLIGENCE_KEY`, `AWS_REGION` (plus the usual AWS credentials), `MISTRAL_API_KEY`,
|
|
16
|
+
`MISTRAL_OCR_MODEL`, `EASYOCR_LANGUAGES`, `PADDLEOCR_LANGUAGE`, `OCR_GPU`, `OCR_MAX_EDGE_PX`, `OCR_TIMEOUT_S`.
|
|
17
|
+
- Existing Tesseract results (`ocr/<page>.json`) are read as before; other engines cache under `ocr/<engine>/`.
|
|
18
|
+
- **Other PDF libraries.** Besides PyMuPDF, the text layer can be read with pypdf, pdfplumber, pdfminer.six and
|
|
19
|
+
pypdfium2 (optional: `pip install "pyocr-toolkit[pdf]"`). Each installed library is its own source
|
|
20
|
+
(`native:<library>`; `native` stays PyMuPDF) that can be compared and exported. The page inspector's Native tab
|
|
21
|
+
has a library picker and a **Test all libraries** button that shows which libraries get text out of the page.
|
|
22
|
+
CLI: `--engine native:<library>` and `pyocr libraries`; API: `?library=` on `/text/native`, a new
|
|
23
|
+
`/pages/{page}/text/native/libraries` endpoint, and `text_libraries` in `/api/config`. Results are cached under
|
|
24
|
+
`native/<library>/<page>.json` and re-read when the library version changes.
|
|
25
|
+
- **Export all sources.** Download everything extracted for a document in one file: Overview → *Export all*,
|
|
26
|
+
the Full text *Download* menu, or `GET /api/documents/{id}/export/all?fmt=json|jsonl|csv|md|zip`.
|
|
27
|
+
JSON keeps each page's text per source, CSV puts sources side by side (a column each), and ZIP bundles the JSON
|
|
28
|
+
and CSV with a TXT and Markdown file per source. Like single-source export, it only reads cached results.
|
|
29
|
+
- Logos for LLM providers and OCR engines across the UI (bundled locally, no external requests).
|
|
30
|
+
- The upload file pickers now offer `.txt`, `.cbr` and `.pam` files, which the server already accepted.
|
|
31
|
+
- Fix: running Tesseract on two documents at once (e.g. two OCR jobs) failed with "Attempt to use Leptonica from
|
|
32
|
+
2 threads at once"; Tesseract calls are now serialised across the whole process.
|
|
33
|
+
- LLM prompts and cache keys are unchanged, so existing results stay valid.
|
|
34
|
+
|
|
35
|
+
## 0.4.0 - 2026-11-27
|
|
36
|
+
|
|
37
|
+
- Several pages per LLM request: set **Pages per request** on the Overview page, `--pages-per-request N` on
|
|
38
|
+
`pyocr extract`, or `pages_per_request` in the API's LLM body (1–20, default 1). Pages go out as labelled images
|
|
39
|
+
in one call and the reply is split back into pages at `=== PAGE n ===` markers. A page the reply can't be matched
|
|
40
|
+
to (marker missing or repeated, or cut off by the output limit) is re-sent on its own, with a warning. A batched
|
|
41
|
+
run is its own source (`… · N pages/request`), so you can compare it with one page per request; existing
|
|
42
|
+
single-page results and cache keys are unchanged. Tokens of a shared request are split evenly over its pages, and
|
|
43
|
+
each page's record has a `batch` object with the request totals. New setting `LLM_BATCH_MAX_OUTPUT_TOKENS`
|
|
44
|
+
(default 32000).
|
|
45
|
+
- Easier page selection on the Overview page. The page-range box checks what you type as you type ("9 of 14 pages",
|
|
46
|
+
or what's wrong with the range) and stays in sync with a clickable page map (Shift-click for a range), with
|
|
47
|
+
presets for all pages, the first 5, scans only, and pages with no text from the chosen engine yet. The map marks
|
|
48
|
+
scans and pages that already have text. "Pages per request" has presets (1, 2, 3, 4, 5, 10), a box for any other
|
|
49
|
+
value, and shows how many requests the job will make.
|
|
50
|
+
- **Adjust image** (page inspector, shortcut `e`): preprocess the page image before it is sent to an LLM, then
|
|
51
|
+
check whether that helped. It has a strip of filters, each a thumbnail of the current page (Clean scan, High contrast,
|
|
52
|
+
Black & white with Otsu thresholding, Fix faded, Denoise, Bring out detail, Invert), and fine-tuning for
|
|
53
|
+
brightness, contrast, sharpness, denoise, threshold, resolution, rotation and crop. The viewer shows exactly the
|
|
54
|
+
image the model receives, with its pixel and file size; *Hold to compare* shows the original.
|
|
55
|
+
*A/B: original vs adjusted* transcribes both versions with the same model and diffs them, next to their token
|
|
56
|
+
counts and timings. The settings are remembered per document and also apply to batch extraction from the Overview page.
|
|
57
|
+
- Preprocessing settings are part of the LLM cache key, so each setting is its own source to read, export and
|
|
58
|
+
compare. Runs without preprocessing keep their existing keys, so cached results are unaffected.
|
|
59
|
+
- API: `preprocess` on `POST /api/documents/{id}/pages/{n}/llm` and in job bodies, `?preprocess=` on the page image
|
|
60
|
+
endpoint, `GET /api/documents/{id}/pages/{n}/llm-image` (the exact image a model receives), `GET /api/preprocess`
|
|
61
|
+
(validate / normalise a spec), and `preprocess_presets` in `/api/config`. CLI: `pyocr extract|compare --preprocess`.
|
|
62
|
+
- New dependency: Pillow (image processing).
|
|
63
|
+
|
|
5
64
|
## 0.3.0 - 2026-11-27
|
|
6
65
|
|
|
7
66
|
- Now on PyPI: `pip install pyocr-toolkit`. Releases are built, tested and published from GitHub Actions.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: pyocr-toolkit
|
|
3
|
-
Version: 0.
|
|
4
|
-
Summary: Inspect and compare PDF/image text extraction - native text, Tesseract
|
|
3
|
+
Version: 0.5.0
|
|
4
|
+
Summary: Inspect and compare PDF/image text extraction - native text, OCR engines (Tesseract, EasyOCR, PaddleOCR, docTR, RapidOCR, Google Vision, Azure, Textract, Mistral) and LLMs (Claude, GPT, Gemini, Azure, local) - in your browser.
|
|
5
5
|
Project-URL: Homepage, https://github.com/utkarsh5026/pyocr
|
|
6
6
|
Project-URL: Issues, https://github.com/utkarsh5026/pyocr/issues
|
|
7
7
|
Author: utkarsh5026
|
|
@@ -207,7 +207,7 @@ License: Apache License
|
|
|
207
207
|
See the License for the specific language governing permissions and
|
|
208
208
|
limitations under the License.
|
|
209
209
|
License-File: LICENSE
|
|
210
|
-
Keywords: claude,document-ai,llm,ocr,openai,pdf,pymupdf,rag,tesseract,text-extraction
|
|
210
|
+
Keywords: claude,doctr,document-ai,easyocr,llm,ocr,openai,paddleocr,pdf,pdfplumber,pymupdf,pypdf,rag,tesseract,text-extraction,textract
|
|
211
211
|
Classifier: Development Status :: 4 - Beta
|
|
212
212
|
Classifier: Environment :: Web Environment
|
|
213
213
|
Classifier: Framework :: FastAPI
|
|
@@ -226,8 +226,10 @@ Requires-Python: >=3.10
|
|
|
226
226
|
Requires-Dist: anthropic>=1.0
|
|
227
227
|
Requires-Dist: fastapi>=0.110
|
|
228
228
|
Requires-Dist: google-genai>=1.0
|
|
229
|
+
Requires-Dist: httpx>=0.27
|
|
229
230
|
Requires-Dist: jinja2>=3.1
|
|
230
231
|
Requires-Dist: openai>=1.40
|
|
232
|
+
Requires-Dist: pillow>=10.1
|
|
231
233
|
Requires-Dist: pydantic-settings>=2.2
|
|
232
234
|
Requires-Dist: pymupdf>=1.24
|
|
233
235
|
Requires-Dist: python-multipart>=0.0.9
|
|
@@ -235,9 +237,30 @@ Requires-Dist: rapidfuzz>=3.6
|
|
|
235
237
|
Requires-Dist: uvicorn[standard]>=0.29
|
|
236
238
|
Provides-Extra: dev
|
|
237
239
|
Requires-Dist: httpx>=0.27; extra == 'dev'
|
|
240
|
+
Requires-Dist: pdfminer-six>=20231228; extra == 'dev'
|
|
241
|
+
Requires-Dist: pdfplumber>=0.11; extra == 'dev'
|
|
242
|
+
Requires-Dist: pypdf>=4; extra == 'dev'
|
|
243
|
+
Requires-Dist: pypdfium2>=4; extra == 'dev'
|
|
238
244
|
Requires-Dist: pytest>=8; extra == 'dev'
|
|
239
245
|
Requires-Dist: rich>=13; extra == 'dev'
|
|
240
246
|
Requires-Dist: ruff>=0.5; extra == 'dev'
|
|
247
|
+
Provides-Extra: doctr
|
|
248
|
+
Requires-Dist: python-doctr[torch]>=0.10; extra == 'doctr'
|
|
249
|
+
Provides-Extra: easyocr
|
|
250
|
+
Requires-Dist: easyocr>=1.7; extra == 'easyocr'
|
|
251
|
+
Provides-Extra: paddleocr
|
|
252
|
+
Requires-Dist: paddleocr>=3; extra == 'paddleocr'
|
|
253
|
+
Requires-Dist: paddlepaddle>=3; extra == 'paddleocr'
|
|
254
|
+
Provides-Extra: pdf
|
|
255
|
+
Requires-Dist: pdfminer-six>=20231228; extra == 'pdf'
|
|
256
|
+
Requires-Dist: pdfplumber>=0.11; extra == 'pdf'
|
|
257
|
+
Requires-Dist: pypdf>=4; extra == 'pdf'
|
|
258
|
+
Requires-Dist: pypdfium2>=4; extra == 'pdf'
|
|
259
|
+
Provides-Extra: rapidocr
|
|
260
|
+
Requires-Dist: onnxruntime>=1.17; extra == 'rapidocr'
|
|
261
|
+
Requires-Dist: rapidocr>=2; extra == 'rapidocr'
|
|
262
|
+
Provides-Extra: textract
|
|
263
|
+
Requires-Dist: boto3>=1.34; extra == 'textract'
|
|
241
264
|
Description-Content-Type: text/markdown
|
|
242
265
|
|
|
243
266
|
<div align="center">
|
|
@@ -275,8 +298,8 @@ checking that step. Upload a document and you get three versions of every page:
|
|
|
275
298
|
|
|
276
299
|
| | Source | What it is | Good at | Weak at |
|
|
277
300
|
|---|---|---|---|---|
|
|
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
|
-
| 🔍 | **
|
|
301
|
+
| 📄 | **Native text** | Text already embedded in the file (PyMuPDF, or pypdf / pdfplumber / pdfminer.six / pypdfium2) | Born-digital PDFs. Exact and instant. | Scans have none. Broken font maps produce gibberish. |
|
|
302
|
+
| 🔍 | **OCR** | Tesseract, or any of 8 other OCR engines (below), on the rendered page image | Free/local or cheap cloud, gives word positions | Varies by engine: Tesseract struggles with tables, columns, poor scans, handwriting |
|
|
280
303
|
| ✨ | **LLM transcription** | A vision LLM told to copy the page *verbatim* | Hard pages, layout, context | Costs money. May quietly "fix" or skip text. |
|
|
281
304
|
|
|
282
305
|
Then you can:
|
|
@@ -284,11 +307,16 @@ Then you can:
|
|
|
284
307
|
- **Extract** page by page, a range like `1-5,9`, or the whole document, as background jobs
|
|
285
308
|
- **Compare** any two sources: character and word error rate (CER/WER), word-level diffs, a per-page chart
|
|
286
309
|
- **Search** across every document and every source at once
|
|
287
|
-
- **Export** clean text as TXT, Markdown, JSON or JSONL for your pipeline
|
|
310
|
+
- **Export** clean text as TXT, Markdown, JSON or JSONL for your pipeline, or every source at once as JSON, CSV,
|
|
311
|
+
Markdown, JSONL or a ZIP
|
|
288
312
|
|
|
289
313
|
**LLM providers:** Claude (Anthropic API), OpenAI, Azure OpenAI, Claude on Azure (Microsoft Foundry), Google
|
|
290
314
|
Gemini, and any OpenAI-compatible server (Ollama, vLLM, LM Studio, OpenRouter) for local or private models.
|
|
291
315
|
|
|
316
|
+
**OCR engines:** Tesseract (default), plus RapidOCR, EasyOCR, PaddleOCR and docTR running locally, and Google
|
|
317
|
+
Cloud Vision, Azure AI Document Intelligence, AWS Textract and Mistral OCR in the cloud. Each engine is its own
|
|
318
|
+
source, so you can score engines against each other or against an LLM.
|
|
319
|
+
|
|
292
320
|
**Inputs:** PDF, XPS, EPUB, CBZ, MOBI, FB2, SVG, PNG, JPEG, TIFF (multi-page), BMP, GIF, WebP and anything else
|
|
293
321
|
[PyMuPDF](https://pymupdf.readthedocs.io/) opens.
|
|
294
322
|
|
|
@@ -373,8 +401,8 @@ Everything you upload and extract is stored in `./data` (change it with `DATA_DI
|
|
|
373
401
|
| **Home** `/` | Drop files to upload; see setup status and recent documents. |
|
|
374
402
|
| **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
403
|
| **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 (
|
|
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`. |
|
|
404
|
+
| **Overview** `/documents/{id}` | Start background extraction (any OCR engine or LLM) for all pages or a range such as `1-5,9`, typed or picked on a clickable page map (Shift-click for a range; presets for scans only or pages without text yet); choose pages per LLM request; follow progress; see every *source* (engine + model + prompt) with token usage; export; page thumbnails. |
|
|
405
|
+
| **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; *Adjust* to preprocess the image the LLM receives (filters, fine-tuning, crop/rotate) and A/B it against the original. Keyboard: `←/→`, `/`, `1-5`, `t`, `o`, `e`. |
|
|
378
406
|
| **Full text** `/documents/{id}/text` | Read the whole document from one source, optionally beside the page images; find, copy, download. |
|
|
379
407
|
| **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
408
|
| **Search** `/search` | Search all documents at once. |
|
|
@@ -404,20 +432,79 @@ and the hint under each model box say whether a model suits transcription (custo
|
|
|
404
432
|
images. For a fully local setup, run Ollama with a vision model and set
|
|
405
433
|
`OPENAI_COMPATIBLE_BASE_URL=http://localhost:11434/v1`.
|
|
406
434
|
|
|
435
|
+
## Configure OCR engines
|
|
436
|
+
|
|
437
|
+
Tesseract is the default engine. Every other engine is optional, and the Providers page (and `pyocr engines`) shows
|
|
438
|
+
which are ready, with a **Test** button for each. Cloud keys and engine settings can be set there too, or as
|
|
439
|
+
environment variables. Local engines run on your machine; the first run downloads the
|
|
440
|
+
model weights. Cloud engines send the rendered page image to that service, and nowhere else.
|
|
441
|
+
|
|
442
|
+
| Engine | Kind | Install / required settings | Optional |
|
|
443
|
+
|---|---|---|---|
|
|
444
|
+
| Tesseract | local | system package (`apt install tesseract-ocr`, `brew install tesseract`) | `TESSERACT_LANGUAGE` |
|
|
445
|
+
| RapidOCR | local | `pip install "pyocr-toolkit[rapidocr]"` (ONNX Runtime, no PyTorch) | – |
|
|
446
|
+
| EasyOCR | local | `pip install "pyocr-toolkit[easyocr]"` (PyTorch) | `EASYOCR_LANGUAGES`, `OCR_GPU` |
|
|
447
|
+
| PaddleOCR | local | `pip install "pyocr-toolkit[paddleocr]"` (PaddlePaddle) | `PADDLEOCR_LANGUAGE` |
|
|
448
|
+
| docTR | local | `pip install "pyocr-toolkit[doctr]"` (PyTorch) | `OCR_GPU` |
|
|
449
|
+
| Google Cloud Vision | cloud | `GOOGLE_VISION_API_KEY` | `GOOGLE_VISION_LANGUAGE_HINTS` |
|
|
450
|
+
| Azure AI Document Intelligence | cloud | `AZURE_DOCUMENT_INTELLIGENCE_ENDPOINT`, `AZURE_DOCUMENT_INTELLIGENCE_KEY` | – |
|
|
451
|
+
| AWS Textract | cloud | `pip install "pyocr-toolkit[textract]"`, `AWS_REGION` | `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY` (or `~/.aws`) |
|
|
452
|
+
| Mistral OCR | cloud | `MISTRAL_API_KEY` | `MISTRAL_OCR_MODEL` (default `mistral-ocr-latest`) |
|
|
453
|
+
|
|
454
|
+
Mistral OCR returns Markdown without word positions, so its search hits can't be drawn on the page image. In the
|
|
455
|
+
API, OCR sources are `ocr` (Tesseract) and `ocr:<engine>`, e.g. `ocr:easyocr`.
|
|
456
|
+
|
|
457
|
+
## PDF libraries
|
|
458
|
+
|
|
459
|
+
Native text comes from PyMuPDF, but Python has other PDF libraries, and they don't all read a text layer the same
|
|
460
|
+
way: reading order, spacing, ligatures and odd font encodings come out differently. If your pipeline uses one of
|
|
461
|
+
them, check *that* library on your PDFs. Each installed library is its own source, `native:<library>`:
|
|
462
|
+
|
|
463
|
+
| Library | Source | Notes |
|
|
464
|
+
|---|---|---|
|
|
465
|
+
| PyMuPDF | `native` | always installed; word boxes |
|
|
466
|
+
| pypdf | `native:pypdf` | pure Python; used by many LangChain / LlamaIndex loaders |
|
|
467
|
+
| pdfplumber | `native:pdfplumber` | built on pdfminer.six; word boxes |
|
|
468
|
+
| pdfminer.six | `native:pdfminer` | pure-Python layout analysis |
|
|
469
|
+
| pypdfium2 | `native:pypdfium2` | PDFium, the engine in Chrome |
|
|
470
|
+
|
|
471
|
+
Install them all with `pip install "pyocr-toolkit[pdf]"` (or just the ones you need). In the page inspector, the
|
|
472
|
+
**Native** tab has a library picker and a **Test all libraries** button that reads the page with each one and shows
|
|
473
|
+
whether it got text out, how much, and how fast. The Compare page and exports list every installed library, so you
|
|
474
|
+
can score `native:pypdf` against `native` across a whole document. `pyocr libraries` shows what's installed, and
|
|
475
|
+
`pyocr extract FILE --engine native:pdfplumber` extracts with one of them. They read PDF files only.
|
|
476
|
+
|
|
407
477
|
## Command line
|
|
408
478
|
|
|
409
479
|
```bash
|
|
410
480
|
pyocr extract report.pdf --engine llm -p anthropic --pages 1-5 --format jsonl -o report.jsonl
|
|
481
|
+
pyocr extract report.pdf --engine llm --pages-per-request 5 # 5 pages in each LLM request
|
|
411
482
|
pyocr extract scan.tiff --engine ocr --format md # Tesseract, Markdown to stdout
|
|
483
|
+
pyocr extract scan.pdf --engine ocr:easyocr # any OCR engine (see `pyocr engines`)
|
|
412
484
|
pyocr extract born-digital.pdf --engine native # embedded text only, no network
|
|
485
|
+
pyocr extract born-digital.pdf --engine native:pypdf # the same text layer as pypdf reads it
|
|
413
486
|
pyocr compare scan.pdf -p openai -m gpt-6.2-sol # per-page OCR / native CER vs an LLM
|
|
487
|
+
pyocr extract scan.pdf -p anthropic --preprocess 'gray;auto;contrast=1.5' # adjust the image first (or a preset: clean, bw, ...)
|
|
414
488
|
pyocr import a.pdf b.pdf scans.zip folder/ -w invoices # add many files as one workspace (zips unpacked)
|
|
415
489
|
pyocr providers # which providers are ready
|
|
490
|
+
pyocr engines # which OCR engines are ready
|
|
416
491
|
python -m pyocr_toolkit --help # same CLI without the script on PATH
|
|
417
492
|
```
|
|
418
493
|
|
|
419
494
|
Documents processed on the command line also appear in the web app's library.
|
|
420
495
|
|
|
496
|
+
### Several pages per LLM request
|
|
497
|
+
|
|
498
|
+
If your pipeline sends a few pages in one LLM call, set **Pages per request** on the Overview page (or
|
|
499
|
+
`--pages-per-request N`, up to 20) to measure that setup. Each image goes out right after a label like `Page 5`, and the
|
|
500
|
+
model starts each page with `=== PAGE 5 ===`. The reply is split there, and each page is stored, scored and exported on
|
|
501
|
+
its own. A page whose marker is missing or repeated, or that the output limit cut off, is sent again on its own and
|
|
502
|
+
gets a warning, so text is never assigned to a page by guessing. The batch size is part of the prompt, so a batched
|
|
503
|
+
run is its own source: compare it with one page per request to see what batching costs in accuracy. Tokens of a
|
|
504
|
+
shared request are split evenly over its pages. Batching saves only the repeated system prompt (about 10% of input
|
|
505
|
+
tokens), so its main effect is fewer requests. `LLM_BATCH_MAX_OUTPUT_TOKENS` (default 32000) sets the output limit
|
|
506
|
+
for these requests.
|
|
507
|
+
|
|
421
508
|
### Batch uploads and workspaces
|
|
422
509
|
|
|
423
510
|
Upload several files, or a `.zip`, and they land together in a **workspace** whose name you can edit. pyocr suggests
|
|
@@ -431,11 +518,14 @@ you ask otherwise.
|
|
|
431
518
|
|
|
432
519
|
1. **Native text.** A PDF page is a list of drawing instructions ("glyph 37 at (72, 700)"). Born-digital files map
|
|
433
520
|
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
|
|
435
|
-
reporting a box for each word. That is why search can highlight OCR hits on the page.
|
|
521
|
+
2. **OCR.** The page is rendered to pixels (300 DPI) and an OCR engine (Tesseract by default) recognises characters
|
|
522
|
+
from their shapes, reporting a box for each word (or line, split into words). That is why search can highlight OCR hits on the page.
|
|
436
523
|
3. **LLM.** The page image goes to a vision model with a strict "transcribe, don't correct" prompt
|
|
437
524
|
([`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
525
|
"fix" typos, which the diff view exposes.
|
|
526
|
+
Optionally the image is preprocessed first (grayscale, levels, contrast, denoise, black & white, crop, rotate;
|
|
527
|
+
[`preprocess.py`](src/pyocr_toolkit/preprocess.py)). The settings are part of the cache key, so a run on the
|
|
528
|
+
cleaned-up page is a separate source you can diff against the run on the original.
|
|
439
529
|
4. **Comparison.** *Edit distance* is the minimum number of character insertions, deletions and substitutions
|
|
440
530
|
between two texts. **CER** = edits / reference characters; **WER** is the same count over words. For example,
|
|
441
531
|
"the cat sat" → "the bat sat" has 1 edit, so CER = 1/11 = 9%. Whitespace is normalised first, because line
|
|
@@ -33,8 +33,8 @@ checking that step. Upload a document and you get three versions of every page:
|
|
|
33
33
|
|
|
34
34
|
| | Source | What it is | Good at | Weak at |
|
|
35
35
|
|---|---|---|---|---|
|
|
36
|
-
| 📄 | **Native text** | Text already embedded in the file (PyMuPDF) | Born-digital PDFs. Exact and instant. | Scans have none. Broken font maps produce gibberish. |
|
|
37
|
-
| 🔍 | **
|
|
36
|
+
| 📄 | **Native text** | Text already embedded in the file (PyMuPDF, or pypdf / pdfplumber / pdfminer.six / pypdfium2) | Born-digital PDFs. Exact and instant. | Scans have none. Broken font maps produce gibberish. |
|
|
37
|
+
| 🔍 | **OCR** | Tesseract, or any of 8 other OCR engines (below), on the rendered page image | Free/local or cheap cloud, gives word positions | Varies by engine: Tesseract struggles with tables, columns, poor scans, handwriting |
|
|
38
38
|
| ✨ | **LLM transcription** | A vision LLM told to copy the page *verbatim* | Hard pages, layout, context | Costs money. May quietly "fix" or skip text. |
|
|
39
39
|
|
|
40
40
|
Then you can:
|
|
@@ -42,11 +42,16 @@ Then you can:
|
|
|
42
42
|
- **Extract** page by page, a range like `1-5,9`, or the whole document, as background jobs
|
|
43
43
|
- **Compare** any two sources: character and word error rate (CER/WER), word-level diffs, a per-page chart
|
|
44
44
|
- **Search** across every document and every source at once
|
|
45
|
-
- **Export** clean text as TXT, Markdown, JSON or JSONL for your pipeline
|
|
45
|
+
- **Export** clean text as TXT, Markdown, JSON or JSONL for your pipeline, or every source at once as JSON, CSV,
|
|
46
|
+
Markdown, JSONL or a ZIP
|
|
46
47
|
|
|
47
48
|
**LLM providers:** Claude (Anthropic API), OpenAI, Azure OpenAI, Claude on Azure (Microsoft Foundry), Google
|
|
48
49
|
Gemini, and any OpenAI-compatible server (Ollama, vLLM, LM Studio, OpenRouter) for local or private models.
|
|
49
50
|
|
|
51
|
+
**OCR engines:** Tesseract (default), plus RapidOCR, EasyOCR, PaddleOCR and docTR running locally, and Google
|
|
52
|
+
Cloud Vision, Azure AI Document Intelligence, AWS Textract and Mistral OCR in the cloud. Each engine is its own
|
|
53
|
+
source, so you can score engines against each other or against an LLM.
|
|
54
|
+
|
|
50
55
|
**Inputs:** PDF, XPS, EPUB, CBZ, MOBI, FB2, SVG, PNG, JPEG, TIFF (multi-page), BMP, GIF, WebP and anything else
|
|
51
56
|
[PyMuPDF](https://pymupdf.readthedocs.io/) opens.
|
|
52
57
|
|
|
@@ -131,8 +136,8 @@ Everything you upload and extract is stored in `./data` (change it with `DATA_DI
|
|
|
131
136
|
| **Home** `/` | Drop files to upload; see setup status and recent documents. |
|
|
132
137
|
| **Library** `/documents` | Document cards showing native / OCR / LLM coverage and how many pages still have no text. Filter by status, workspace or name; delete. |
|
|
133
138
|
| **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. |
|
|
134
|
-
| **Overview** `/documents/{id}` | Start background extraction (
|
|
135
|
-
| **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`. |
|
|
139
|
+
| **Overview** `/documents/{id}` | Start background extraction (any OCR engine or LLM) for all pages or a range such as `1-5,9`, typed or picked on a clickable page map (Shift-click for a range; presets for scans only or pages without text yet); choose pages per LLM request; follow progress; see every *source* (engine + model + prompt) with token usage; export; page thumbnails. |
|
|
140
|
+
| **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; *Adjust* to preprocess the image the LLM receives (filters, fine-tuning, crop/rotate) and A/B it against the original. Keyboard: `←/→`, `/`, `1-5`, `t`, `o`, `e`. |
|
|
136
141
|
| **Full text** `/documents/{id}/text` | Read the whole document from one source, optionally beside the page images; find, copy, download. |
|
|
137
142
|
| **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**. |
|
|
138
143
|
| **Search** `/search` | Search all documents at once. |
|
|
@@ -162,20 +167,79 @@ and the hint under each model box say whether a model suits transcription (custo
|
|
|
162
167
|
images. For a fully local setup, run Ollama with a vision model and set
|
|
163
168
|
`OPENAI_COMPATIBLE_BASE_URL=http://localhost:11434/v1`.
|
|
164
169
|
|
|
170
|
+
## Configure OCR engines
|
|
171
|
+
|
|
172
|
+
Tesseract is the default engine. Every other engine is optional, and the Providers page (and `pyocr engines`) shows
|
|
173
|
+
which are ready, with a **Test** button for each. Cloud keys and engine settings can be set there too, or as
|
|
174
|
+
environment variables. Local engines run on your machine; the first run downloads the
|
|
175
|
+
model weights. Cloud engines send the rendered page image to that service, and nowhere else.
|
|
176
|
+
|
|
177
|
+
| Engine | Kind | Install / required settings | Optional |
|
|
178
|
+
|---|---|---|---|
|
|
179
|
+
| Tesseract | local | system package (`apt install tesseract-ocr`, `brew install tesseract`) | `TESSERACT_LANGUAGE` |
|
|
180
|
+
| RapidOCR | local | `pip install "pyocr-toolkit[rapidocr]"` (ONNX Runtime, no PyTorch) | – |
|
|
181
|
+
| EasyOCR | local | `pip install "pyocr-toolkit[easyocr]"` (PyTorch) | `EASYOCR_LANGUAGES`, `OCR_GPU` |
|
|
182
|
+
| PaddleOCR | local | `pip install "pyocr-toolkit[paddleocr]"` (PaddlePaddle) | `PADDLEOCR_LANGUAGE` |
|
|
183
|
+
| docTR | local | `pip install "pyocr-toolkit[doctr]"` (PyTorch) | `OCR_GPU` |
|
|
184
|
+
| Google Cloud Vision | cloud | `GOOGLE_VISION_API_KEY` | `GOOGLE_VISION_LANGUAGE_HINTS` |
|
|
185
|
+
| Azure AI Document Intelligence | cloud | `AZURE_DOCUMENT_INTELLIGENCE_ENDPOINT`, `AZURE_DOCUMENT_INTELLIGENCE_KEY` | – |
|
|
186
|
+
| AWS Textract | cloud | `pip install "pyocr-toolkit[textract]"`, `AWS_REGION` | `AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY` (or `~/.aws`) |
|
|
187
|
+
| Mistral OCR | cloud | `MISTRAL_API_KEY` | `MISTRAL_OCR_MODEL` (default `mistral-ocr-latest`) |
|
|
188
|
+
|
|
189
|
+
Mistral OCR returns Markdown without word positions, so its search hits can't be drawn on the page image. In the
|
|
190
|
+
API, OCR sources are `ocr` (Tesseract) and `ocr:<engine>`, e.g. `ocr:easyocr`.
|
|
191
|
+
|
|
192
|
+
## PDF libraries
|
|
193
|
+
|
|
194
|
+
Native text comes from PyMuPDF, but Python has other PDF libraries, and they don't all read a text layer the same
|
|
195
|
+
way: reading order, spacing, ligatures and odd font encodings come out differently. If your pipeline uses one of
|
|
196
|
+
them, check *that* library on your PDFs. Each installed library is its own source, `native:<library>`:
|
|
197
|
+
|
|
198
|
+
| Library | Source | Notes |
|
|
199
|
+
|---|---|---|
|
|
200
|
+
| PyMuPDF | `native` | always installed; word boxes |
|
|
201
|
+
| pypdf | `native:pypdf` | pure Python; used by many LangChain / LlamaIndex loaders |
|
|
202
|
+
| pdfplumber | `native:pdfplumber` | built on pdfminer.six; word boxes |
|
|
203
|
+
| pdfminer.six | `native:pdfminer` | pure-Python layout analysis |
|
|
204
|
+
| pypdfium2 | `native:pypdfium2` | PDFium, the engine in Chrome |
|
|
205
|
+
|
|
206
|
+
Install them all with `pip install "pyocr-toolkit[pdf]"` (or just the ones you need). In the page inspector, the
|
|
207
|
+
**Native** tab has a library picker and a **Test all libraries** button that reads the page with each one and shows
|
|
208
|
+
whether it got text out, how much, and how fast. The Compare page and exports list every installed library, so you
|
|
209
|
+
can score `native:pypdf` against `native` across a whole document. `pyocr libraries` shows what's installed, and
|
|
210
|
+
`pyocr extract FILE --engine native:pdfplumber` extracts with one of them. They read PDF files only.
|
|
211
|
+
|
|
165
212
|
## Command line
|
|
166
213
|
|
|
167
214
|
```bash
|
|
168
215
|
pyocr extract report.pdf --engine llm -p anthropic --pages 1-5 --format jsonl -o report.jsonl
|
|
216
|
+
pyocr extract report.pdf --engine llm --pages-per-request 5 # 5 pages in each LLM request
|
|
169
217
|
pyocr extract scan.tiff --engine ocr --format md # Tesseract, Markdown to stdout
|
|
218
|
+
pyocr extract scan.pdf --engine ocr:easyocr # any OCR engine (see `pyocr engines`)
|
|
170
219
|
pyocr extract born-digital.pdf --engine native # embedded text only, no network
|
|
220
|
+
pyocr extract born-digital.pdf --engine native:pypdf # the same text layer as pypdf reads it
|
|
171
221
|
pyocr compare scan.pdf -p openai -m gpt-6.2-sol # per-page OCR / native CER vs an LLM
|
|
222
|
+
pyocr extract scan.pdf -p anthropic --preprocess 'gray;auto;contrast=1.5' # adjust the image first (or a preset: clean, bw, ...)
|
|
172
223
|
pyocr import a.pdf b.pdf scans.zip folder/ -w invoices # add many files as one workspace (zips unpacked)
|
|
173
224
|
pyocr providers # which providers are ready
|
|
225
|
+
pyocr engines # which OCR engines are ready
|
|
174
226
|
python -m pyocr_toolkit --help # same CLI without the script on PATH
|
|
175
227
|
```
|
|
176
228
|
|
|
177
229
|
Documents processed on the command line also appear in the web app's library.
|
|
178
230
|
|
|
231
|
+
### Several pages per LLM request
|
|
232
|
+
|
|
233
|
+
If your pipeline sends a few pages in one LLM call, set **Pages per request** on the Overview page (or
|
|
234
|
+
`--pages-per-request N`, up to 20) to measure that setup. Each image goes out right after a label like `Page 5`, and the
|
|
235
|
+
model starts each page with `=== PAGE 5 ===`. The reply is split there, and each page is stored, scored and exported on
|
|
236
|
+
its own. A page whose marker is missing or repeated, or that the output limit cut off, is sent again on its own and
|
|
237
|
+
gets a warning, so text is never assigned to a page by guessing. The batch size is part of the prompt, so a batched
|
|
238
|
+
run is its own source: compare it with one page per request to see what batching costs in accuracy. Tokens of a
|
|
239
|
+
shared request are split evenly over its pages. Batching saves only the repeated system prompt (about 10% of input
|
|
240
|
+
tokens), so its main effect is fewer requests. `LLM_BATCH_MAX_OUTPUT_TOKENS` (default 32000) sets the output limit
|
|
241
|
+
for these requests.
|
|
242
|
+
|
|
179
243
|
### Batch uploads and workspaces
|
|
180
244
|
|
|
181
245
|
Upload several files, or a `.zip`, and they land together in a **workspace** whose name you can edit. pyocr suggests
|
|
@@ -189,11 +253,14 @@ you ask otherwise.
|
|
|
189
253
|
|
|
190
254
|
1. **Native text.** A PDF page is a list of drawing instructions ("glyph 37 at (72, 700)"). Born-digital files map
|
|
191
255
|
each glyph back to a character, so the text can be rebuilt exactly. A scan is only a picture, so it has no text.
|
|
192
|
-
2. **OCR.** The page is rendered to pixels (300 DPI) and Tesseract recognises characters
|
|
193
|
-
reporting a box for each word. That is why search can highlight OCR hits on the page.
|
|
256
|
+
2. **OCR.** The page is rendered to pixels (300 DPI) and an OCR engine (Tesseract by default) recognises characters
|
|
257
|
+
from their shapes, reporting a box for each word (or line, split into words). That is why search can highlight OCR hits on the page.
|
|
194
258
|
3. **LLM.** The page image goes to a vision model with a strict "transcribe, don't correct" prompt
|
|
195
259
|
([`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
|
|
196
260
|
"fix" typos, which the diff view exposes.
|
|
261
|
+
Optionally the image is preprocessed first (grayscale, levels, contrast, denoise, black & white, crop, rotate;
|
|
262
|
+
[`preprocess.py`](src/pyocr_toolkit/preprocess.py)). The settings are part of the cache key, so a run on the
|
|
263
|
+
cleaned-up page is a separate source you can diff against the run on the original.
|
|
197
264
|
4. **Comparison.** *Edit distance* is the minimum number of character insertions, deletions and substitutions
|
|
198
265
|
between two texts. **CER** = edits / reference characters; **WER** is the same count over words. For example,
|
|
199
266
|
"the cat sat" → "the bat sat" has 1 edit, so CER = 1/11 = 9%. Whitespace is normalised first, because line
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "pyocr-toolkit"
|
|
3
|
-
version = "0.
|
|
4
|
-
description = "Inspect and compare PDF/image text extraction - native text, Tesseract
|
|
3
|
+
version = "0.5.0"
|
|
4
|
+
description = "Inspect and compare PDF/image text extraction - native text, OCR engines (Tesseract, EasyOCR, PaddleOCR, docTR, RapidOCR, Google Vision, Azure, Textract, Mistral) and LLMs (Claude, GPT, Gemini, Azure, local) - in your browser."
|
|
5
5
|
readme = "README.md"
|
|
6
6
|
requires-python = ">=3.10"
|
|
7
7
|
license = { file = "LICENSE" }
|
|
8
8
|
authors = [{ name = "utkarsh5026" }]
|
|
9
|
-
keywords = ["ocr", "pdf", "tesseract", "llm", "document-ai", "text-extraction", "rag", "pymupdf", "claude", "openai"]
|
|
9
|
+
keywords = ["ocr", "pdf", "tesseract", "easyocr", "paddleocr", "doctr", "textract", "llm", "document-ai", "text-extraction", "rag", "pymupdf", "pypdf", "pdfplumber", "claude", "openai"]
|
|
10
10
|
classifiers = [
|
|
11
11
|
"Development Status :: 4 - Beta",
|
|
12
12
|
"Environment :: Web Environment",
|
|
@@ -25,6 +25,7 @@ classifiers = [
|
|
|
25
25
|
]
|
|
26
26
|
dependencies = [
|
|
27
27
|
"pymupdf>=1.24",
|
|
28
|
+
"pillow>=10.1",
|
|
28
29
|
"fastapi>=0.110",
|
|
29
30
|
"uvicorn[standard]>=0.29",
|
|
30
31
|
"jinja2>=3.1",
|
|
@@ -34,10 +35,21 @@ dependencies = [
|
|
|
34
35
|
"anthropic>=1.0",
|
|
35
36
|
"openai>=1.40",
|
|
36
37
|
"google-genai>=1.0",
|
|
38
|
+
"httpx>=0.27",
|
|
37
39
|
]
|
|
38
40
|
|
|
39
41
|
[project.optional-dependencies]
|
|
40
|
-
dev = ["pytest>=8", "httpx>=0.27", "ruff>=0.5", "rich>=13"
|
|
42
|
+
dev = ["pytest>=8", "httpx>=0.27", "ruff>=0.5", "rich>=13",
|
|
43
|
+
"pypdf>=4", "pdfplumber>=0.11", "pdfminer.six>=20231228", "pypdfium2>=4"]
|
|
44
|
+
# Other PDF libraries to read the text layer with, next to PyMuPDF (native:<library> sources).
|
|
45
|
+
pdf = ["pypdf>=4", "pdfplumber>=0.11", "pdfminer.six>=20231228", "pypdfium2>=4"]
|
|
46
|
+
# Optional OCR engines (Tesseract needs only the system binary). Google Vision,
|
|
47
|
+
# Azure Document Intelligence and Mistral OCR need no extra packages.
|
|
48
|
+
rapidocr = ["rapidocr>=2", "onnxruntime>=1.17"]
|
|
49
|
+
easyocr = ["easyocr>=1.7"]
|
|
50
|
+
paddleocr = ["paddleocr>=3", "paddlepaddle>=3"]
|
|
51
|
+
doctr = ["python-doctr[torch]>=0.10"]
|
|
52
|
+
textract = ["boto3>=1.34"]
|
|
41
53
|
|
|
42
54
|
[project.urls]
|
|
43
55
|
Homepage = "https://github.com/utkarsh5026/pyocr"
|