docling-pp-ocrv6 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.
- docling_pp_ocrv6-0.1.0/.agent/rules/python.mdc +17 -0
- docling_pp_ocrv6-0.1.0/.github/workflows/main.yml +62 -0
- docling_pp_ocrv6-0.1.0/.github/workflows/publish.yml +45 -0
- docling_pp_ocrv6-0.1.0/.gitignore +57 -0
- docling_pp_ocrv6-0.1.0/.pre-commit-config.yaml +21 -0
- docling_pp_ocrv6-0.1.0/.python-version +1 -0
- docling_pp_ocrv6-0.1.0/LICENSE +21 -0
- docling_pp_ocrv6-0.1.0/Makefile +56 -0
- docling_pp_ocrv6-0.1.0/PKG-INFO +114 -0
- docling_pp_ocrv6-0.1.0/README.md +84 -0
- docling_pp_ocrv6-0.1.0/codecov.yml +15 -0
- docling_pp_ocrv6-0.1.0/pyproject.toml +166 -0
- docling_pp_ocrv6-0.1.0/renovate.json +105 -0
- docling_pp_ocrv6-0.1.0/src/docling_pp_ocrv6/__init__.py +8 -0
- docling_pp_ocrv6-0.1.0/src/docling_pp_ocrv6/model.py +275 -0
- docling_pp_ocrv6-0.1.0/src/docling_pp_ocrv6/options.py +91 -0
- docling_pp_ocrv6-0.1.0/src/docling_pp_ocrv6/plugin.py +8 -0
- docling_pp_ocrv6-0.1.0/src/docling_pp_ocrv6/py.typed +0 -0
- docling_pp_ocrv6-0.1.0/tests/__init__.py +0 -0
- docling_pp_ocrv6-0.1.0/tests/conftest.py +77 -0
- docling_pp_ocrv6-0.1.0/tests/test_e2e.py +104 -0
- docling_pp_ocrv6-0.1.0/tests/test_model.py +267 -0
- docling_pp_ocrv6-0.1.0/tests/test_options.py +107 -0
- docling_pp_ocrv6-0.1.0/tests/test_plugin.py +24 -0
- docling_pp_ocrv6-0.1.0/uv.lock +2809 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
---
|
|
2
|
+
description: Python
|
|
3
|
+
globs: **/*.py
|
|
4
|
+
alwaysApply: false
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
You have access to context7 to fetch up to date documentation on libraries and frameworks.
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
Execute python code, tests, ruff or linter:
|
|
11
|
+
- Always use uv or make to execute commands.
|
|
12
|
+
- To run python files: `uv run script.py`
|
|
13
|
+
- To run tests: `make test`
|
|
14
|
+
- To run pre-commit: `make check`
|
|
15
|
+
|
|
16
|
+
Development Guidelines:
|
|
17
|
+
Check the development guidelines here: https://dcc-bs.github.io/documentation/coding/python.html
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
name: Main
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
push:
|
|
5
|
+
branches:
|
|
6
|
+
- main
|
|
7
|
+
pull_request:
|
|
8
|
+
branches:
|
|
9
|
+
- main
|
|
10
|
+
|
|
11
|
+
jobs:
|
|
12
|
+
# ---------------------------------------------------------------------------
|
|
13
|
+
# Quality checks via DCC-BS reusable workflow (ruff lint + format + ty)
|
|
14
|
+
# ---------------------------------------------------------------------------
|
|
15
|
+
quality:
|
|
16
|
+
uses: DCC-BS/ci-workflows/.github/workflows/python-backend-ci.yml@814649735835a84a3d0d6c8d6e6db87dfeb8b348 # v8
|
|
17
|
+
with:
|
|
18
|
+
python_versions: '["3.13"]'
|
|
19
|
+
quality_python_version: "3.13"
|
|
20
|
+
check_command: "make check"
|
|
21
|
+
|
|
22
|
+
# ---------------------------------------------------------------------------
|
|
23
|
+
# Tests + coverage
|
|
24
|
+
# ---------------------------------------------------------------------------
|
|
25
|
+
tests:
|
|
26
|
+
name: Tests (Python ${{ matrix.python-version }})
|
|
27
|
+
runs-on: ubuntu-latest
|
|
28
|
+
needs: [quality]
|
|
29
|
+
strategy:
|
|
30
|
+
fail-fast: false
|
|
31
|
+
matrix:
|
|
32
|
+
python-version: ["3.13"]
|
|
33
|
+
|
|
34
|
+
steps:
|
|
35
|
+
- uses: actions/checkout@0c366fd6a839edf440554fa01a7085ccba70ac98 # v6
|
|
36
|
+
|
|
37
|
+
- name: Install uv
|
|
38
|
+
uses: astral-sh/setup-uv@447e6d02b15d65b3247cce2d6019f11957285d11 # v6
|
|
39
|
+
with:
|
|
40
|
+
enable-cache: true
|
|
41
|
+
cache-dependency-glob: "uv.lock"
|
|
42
|
+
|
|
43
|
+
- name: Set up Python ${{ matrix.python-version }}
|
|
44
|
+
run: uv python install ${{ matrix.python-version }}
|
|
45
|
+
|
|
46
|
+
- name: Install dependencies
|
|
47
|
+
run: uv sync --all-extras --dev
|
|
48
|
+
|
|
49
|
+
- name: Run tests with coverage
|
|
50
|
+
run: uv run pytest --cov --cov-report=xml --junitxml=junit.xml
|
|
51
|
+
|
|
52
|
+
- name: Upload coverage to Codecov
|
|
53
|
+
uses: codecov/codecov-action@57e3a136b779b570ffcdbf80b3bdc90e7fab3de2 # v5
|
|
54
|
+
with:
|
|
55
|
+
token: ${{ secrets.CODECOV_TOKEN }}
|
|
56
|
+
files: ./coverage.xml
|
|
57
|
+
- name: Upload test results to Codecov
|
|
58
|
+
if: ${{ !cancelled() }}
|
|
59
|
+
uses: codecov/test-results-action@0fa95f0e1eeaafde2c782583b36b28ad0d8c77d3 # v1
|
|
60
|
+
with:
|
|
61
|
+
token: ${{ secrets.CODECOV_TOKEN }}
|
|
62
|
+
files: ./junit.xml
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
name: Publish to PyPI
|
|
2
|
+
|
|
3
|
+
on:
|
|
4
|
+
workflow_dispatch:
|
|
5
|
+
|
|
6
|
+
permissions:
|
|
7
|
+
id-token: write # required for PyPI trusted publishing
|
|
8
|
+
contents: write # required to push git tags
|
|
9
|
+
|
|
10
|
+
jobs:
|
|
11
|
+
publish:
|
|
12
|
+
runs-on: ubuntu-latest
|
|
13
|
+
|
|
14
|
+
steps:
|
|
15
|
+
- uses: actions/checkout@0c366fd6a839edf440554fa01a7085ccba70ac98 # v6
|
|
16
|
+
with:
|
|
17
|
+
fetch-depth: 0
|
|
18
|
+
|
|
19
|
+
- name: Install uv
|
|
20
|
+
uses: astral-sh/setup-uv@447e6d02b15d65b3247cce2d6019f11957285d11 # v6
|
|
21
|
+
with:
|
|
22
|
+
enable-cache: true
|
|
23
|
+
|
|
24
|
+
- name: Set up Python
|
|
25
|
+
run: uv python install 3.13
|
|
26
|
+
|
|
27
|
+
- name: Create and push git tag
|
|
28
|
+
run: |
|
|
29
|
+
VERSION=$(uv version --short)
|
|
30
|
+
TAG="v${VERSION}"
|
|
31
|
+
git config --global user.name "github-actions[bot]"
|
|
32
|
+
git config --global user.email "github-actions[bot]@users.noreply.github.com"
|
|
33
|
+
if git rev-parse "$TAG" >/dev/null 2>&1 || git ls-remote --tags origin | grep -q "refs/tags/$TAG"; then
|
|
34
|
+
echo "Tag $TAG already exists – skipping"
|
|
35
|
+
else
|
|
36
|
+
git tag "$TAG"
|
|
37
|
+
git push origin "$TAG"
|
|
38
|
+
echo "Created and pushed tag $TAG"
|
|
39
|
+
fi
|
|
40
|
+
|
|
41
|
+
- name: Build package
|
|
42
|
+
run: uv build
|
|
43
|
+
|
|
44
|
+
- name: Publish to PyPI
|
|
45
|
+
run: uv publish
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
*.so
|
|
6
|
+
*.egg
|
|
7
|
+
*.egg-info/
|
|
8
|
+
dist/
|
|
9
|
+
build/
|
|
10
|
+
.eggs/
|
|
11
|
+
.installed.cfg
|
|
12
|
+
lib/
|
|
13
|
+
lib64/
|
|
14
|
+
parts/
|
|
15
|
+
sdist/
|
|
16
|
+
var/
|
|
17
|
+
wheels/
|
|
18
|
+
share/python-wheels/
|
|
19
|
+
MANIFEST
|
|
20
|
+
|
|
21
|
+
# Virtual environments
|
|
22
|
+
.venv/
|
|
23
|
+
env/
|
|
24
|
+
venv/
|
|
25
|
+
ENV/
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
# Testing & coverage
|
|
29
|
+
.pytest_cache/
|
|
30
|
+
.coverage
|
|
31
|
+
coverage.xml
|
|
32
|
+
htmlcov/
|
|
33
|
+
.tox/
|
|
34
|
+
|
|
35
|
+
# Type checkers
|
|
36
|
+
.mypy_cache/
|
|
37
|
+
.ruff_cache/
|
|
38
|
+
.ty_cache/
|
|
39
|
+
|
|
40
|
+
# IDEs
|
|
41
|
+
.idea/
|
|
42
|
+
.vscode/
|
|
43
|
+
*.swp
|
|
44
|
+
*.swo
|
|
45
|
+
*~
|
|
46
|
+
|
|
47
|
+
# OS
|
|
48
|
+
.DS_Store
|
|
49
|
+
Thumbs.db
|
|
50
|
+
|
|
51
|
+
# Distribution
|
|
52
|
+
*.tar.gz
|
|
53
|
+
*.whl
|
|
54
|
+
|
|
55
|
+
# Environment variables
|
|
56
|
+
.env
|
|
57
|
+
.env.local
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
repos:
|
|
2
|
+
- repo: https://github.com/pre-commit/pre-commit-hooks
|
|
3
|
+
rev: "v5.0.0"
|
|
4
|
+
hooks:
|
|
5
|
+
- id: check-case-conflict
|
|
6
|
+
- id: check-merge-conflict
|
|
7
|
+
- id: check-toml
|
|
8
|
+
- id: check-yaml
|
|
9
|
+
- id: check-json
|
|
10
|
+
- id: end-of-file-fixer
|
|
11
|
+
- id: trailing-whitespace
|
|
12
|
+
- id: detect-private-key
|
|
13
|
+
|
|
14
|
+
- repo: https://github.com/astral-sh/ruff-pre-commit
|
|
15
|
+
rev: "v0.9.9"
|
|
16
|
+
hooks:
|
|
17
|
+
- id: ruff
|
|
18
|
+
args: [--fix, --exit-non-zero-on-fix]
|
|
19
|
+
types_or: [python, pyi]
|
|
20
|
+
- id: ruff-format
|
|
21
|
+
types_or: [python, pyi]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
3.12
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Data Competence Center Basel-Stadt
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
.DEFAULT_GOAL := help
|
|
2
|
+
|
|
3
|
+
.PHONY: help install check lint format type-check test test-xml build clean-build publish
|
|
4
|
+
|
|
5
|
+
help: ## Display available commands
|
|
6
|
+
@awk 'BEGIN {FS = ":.*##"; printf "\nUsage:\n make \033[36m<target>\033[0m\n\nTargets:\n"} \
|
|
7
|
+
/^[a-zA-Z_0-9-]+:.*?##/ { printf " \033[36m%-15s\033[0m %s\n", $$1, $$2 }' $(MAKEFILE_LIST)
|
|
8
|
+
|
|
9
|
+
# ---------------------------------------------------------------------------
|
|
10
|
+
# Setup
|
|
11
|
+
# ---------------------------------------------------------------------------
|
|
12
|
+
|
|
13
|
+
install: ## Install dependencies and pre-commit hooks (CPU onnxruntime)
|
|
14
|
+
uv sync --extra cpu --dev
|
|
15
|
+
uv run pre-commit install
|
|
16
|
+
|
|
17
|
+
# ---------------------------------------------------------------------------
|
|
18
|
+
# Quality checks
|
|
19
|
+
# ---------------------------------------------------------------------------
|
|
20
|
+
|
|
21
|
+
lint: ## Run ruff linter (with auto-fix)
|
|
22
|
+
uv run ruff check . --fix
|
|
23
|
+
|
|
24
|
+
format: ## Run ruff formatter
|
|
25
|
+
uv run ruff format .
|
|
26
|
+
|
|
27
|
+
type-check: ## Run ty type checker
|
|
28
|
+
uv run ty check src/
|
|
29
|
+
|
|
30
|
+
check: ## Run all quality checks (lint, format check, type check)
|
|
31
|
+
uv run ruff check .
|
|
32
|
+
uv run ruff format --check .
|
|
33
|
+
uv run ty check src/
|
|
34
|
+
|
|
35
|
+
# ---------------------------------------------------------------------------
|
|
36
|
+
# Tests
|
|
37
|
+
# ---------------------------------------------------------------------------
|
|
38
|
+
|
|
39
|
+
test: ## Run tests with terminal coverage report
|
|
40
|
+
uv run pytest
|
|
41
|
+
|
|
42
|
+
test-xml: ## Run tests and produce XML coverage report only
|
|
43
|
+
uv run pytest --cov-report=xml --cov-report=
|
|
44
|
+
|
|
45
|
+
# ---------------------------------------------------------------------------
|
|
46
|
+
# Build & publish
|
|
47
|
+
# ---------------------------------------------------------------------------
|
|
48
|
+
|
|
49
|
+
build: clean-build ## Build distribution packages
|
|
50
|
+
uv build
|
|
51
|
+
|
|
52
|
+
clean-build: ## Remove build artefacts
|
|
53
|
+
rm -rf dist/ build/ *.egg-info
|
|
54
|
+
|
|
55
|
+
publish: build ## Publish package to PyPI
|
|
56
|
+
uv publish
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: docling-pp-ocrv6
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A docling OCR plugin for PaddlePaddle PP-OCRv6 (ONNX via RapidOCR)
|
|
5
|
+
Project-URL: Homepage, https://github.com/DCC-BS/docling-pp-ocrv6
|
|
6
|
+
Project-URL: Repository, https://github.com/DCC-BS/docling-pp-ocrv6
|
|
7
|
+
Project-URL: Issues, https://github.com/DCC-BS/docling-pp-ocrv6/issues
|
|
8
|
+
Project-URL: Changelog, https://github.com/DCC-BS/docling-pp-ocrv6/releases
|
|
9
|
+
Author-email: Yanick Schraner <yanick.schraner@bs.ch>, Tobias Bollinger <tobias.bollinger@bs.ch>
|
|
10
|
+
License: MIT
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3 :: Only
|
|
17
|
+
Classifier: Typing :: Typed
|
|
18
|
+
Requires-Python: >=3.12
|
|
19
|
+
Requires-Dist: docling>=2.73
|
|
20
|
+
Requires-Dist: huggingface-hub>=1.3.0
|
|
21
|
+
Requires-Dist: numpy
|
|
22
|
+
Requires-Dist: pillow>=10.0
|
|
23
|
+
Requires-Dist: pyyaml>=6.0
|
|
24
|
+
Requires-Dist: rapidocr>=3.0
|
|
25
|
+
Provides-Extra: cpu
|
|
26
|
+
Requires-Dist: onnxruntime>=1.17; extra == 'cpu'
|
|
27
|
+
Provides-Extra: gpu
|
|
28
|
+
Requires-Dist: onnxruntime-gpu>=1.17; extra == 'gpu'
|
|
29
|
+
Description-Content-Type: text/markdown
|
|
30
|
+
|
|
31
|
+
# docling-pp-ocrv6
|
|
32
|
+
|
|
33
|
+
A [Docling](https://github.com/docling-project/docling) OCR plugin for
|
|
34
|
+
PaddlePaddle's **PP-OCRv6** models. It runs the PP-OCRv6 detection and
|
|
35
|
+
recognition **ONNX** checkpoints locally through
|
|
36
|
+
[RapidOCR](https://github.com/RapidAI/RapidOCR) (onnxruntime), so OCR happens
|
|
37
|
+
inside the docling worker — no external service required.
|
|
38
|
+
|
|
39
|
+
GPU acceleration is automatic when the docling accelerator device resolves to
|
|
40
|
+
CUDA and `onnxruntime-gpu` is installed.
|
|
41
|
+
|
|
42
|
+
## Installation
|
|
43
|
+
|
|
44
|
+
Pick exactly one onnxruntime extra — installing both the CPU and GPU wheels at
|
|
45
|
+
once is unsupported and prevents the CUDA provider from registering:
|
|
46
|
+
|
|
47
|
+
```bash
|
|
48
|
+
pip install "docling-pp-ocrv6[cpu]" # CPU (onnxruntime)
|
|
49
|
+
pip install "docling-pp-ocrv6[gpu]" # CUDA (onnxruntime-gpu)
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
The detection and recognition ONNX models are downloaded from HuggingFace on
|
|
53
|
+
first use and cached under docling's model cache. To pre-fetch them (e.g. at
|
|
54
|
+
container build time):
|
|
55
|
+
|
|
56
|
+
```python
|
|
57
|
+
from docling_pp_ocrv6 import PPOCRv6Model
|
|
58
|
+
PPOCRv6Model.download_models()
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Usage
|
|
62
|
+
|
|
63
|
+
```python
|
|
64
|
+
from docling.document_converter import DocumentConverter, PdfFormatOption
|
|
65
|
+
from docling.datamodel.base_models import InputFormat
|
|
66
|
+
from docling.datamodel.pipeline_options import PdfPipelineOptions
|
|
67
|
+
from docling_pp_ocrv6 import PPOCRv6Options
|
|
68
|
+
|
|
69
|
+
pipeline_options = PdfPipelineOptions(do_ocr=True)
|
|
70
|
+
pipeline_options.ocr_options = PPOCRv6Options()
|
|
71
|
+
|
|
72
|
+
converter = DocumentConverter(
|
|
73
|
+
format_options={InputFormat.PDF: PdfFormatOption(pipeline_options=pipeline_options)}
|
|
74
|
+
)
|
|
75
|
+
result = converter.convert("scanned.pdf")
|
|
76
|
+
print(result.document.export_to_markdown())
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
With **docling-serve**, request the engine by its `kind`:
|
|
80
|
+
|
|
81
|
+
```json
|
|
82
|
+
{ "options": { "ocr": true, "ocr_engine": "pp-ocrv6" } }
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
(`DOCLING_SERVE_ALLOW_EXTERNAL_PLUGINS=true` must be set for the plugin to load.)
|
|
86
|
+
|
|
87
|
+
## Configuration
|
|
88
|
+
|
|
89
|
+
All options are settable via `PPOCRv6Options(...)` or environment variables:
|
|
90
|
+
|
|
91
|
+
| Option | Env var | Default |
|
|
92
|
+
| --- | --- | --- |
|
|
93
|
+
| `lang` | `PPOCRV6_LANG` | `de,en,fr,it,es,nl,pt,...` (German-led European set) |
|
|
94
|
+
| `text_score` | `PPOCRV6_TEXT_SCORE` | `0.5` |
|
|
95
|
+
| `use_det` / `use_cls` / `use_rec` | `PPOCRV6_USE_DET` / `_CLS` / `_REC` | `true` |
|
|
96
|
+
| `det_repo` | `PPOCRV6_DET_REPO` | `PaddlePaddle/PP-OCRv6_medium_det_onnx` |
|
|
97
|
+
| `rec_repo` | `PPOCRV6_REC_REPO` | `PaddlePaddle/PP-OCRv6_medium_rec_onnx` |
|
|
98
|
+
| `det_model_path` / `rec_model_path` / `rec_keys_path` / `cls_model_path` | `PPOCRV6_*_MODEL_PATH` / `_KEYS_PATH` | auto |
|
|
99
|
+
|
|
100
|
+
The recognition character dictionary is extracted automatically from the
|
|
101
|
+
recognition model's `inference.yml`. Angle classification uses RapidOCR's
|
|
102
|
+
bundled cls model unless `cls_model_path` is set.
|
|
103
|
+
|
|
104
|
+
## Development
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
make install # uv sync + pre-commit
|
|
108
|
+
make check # ruff lint + format check + ty type check
|
|
109
|
+
make test # pytest with coverage
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## License
|
|
113
|
+
|
|
114
|
+
MIT
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# docling-pp-ocrv6
|
|
2
|
+
|
|
3
|
+
A [Docling](https://github.com/docling-project/docling) OCR plugin for
|
|
4
|
+
PaddlePaddle's **PP-OCRv6** models. It runs the PP-OCRv6 detection and
|
|
5
|
+
recognition **ONNX** checkpoints locally through
|
|
6
|
+
[RapidOCR](https://github.com/RapidAI/RapidOCR) (onnxruntime), so OCR happens
|
|
7
|
+
inside the docling worker — no external service required.
|
|
8
|
+
|
|
9
|
+
GPU acceleration is automatic when the docling accelerator device resolves to
|
|
10
|
+
CUDA and `onnxruntime-gpu` is installed.
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
Pick exactly one onnxruntime extra — installing both the CPU and GPU wheels at
|
|
15
|
+
once is unsupported and prevents the CUDA provider from registering:
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
pip install "docling-pp-ocrv6[cpu]" # CPU (onnxruntime)
|
|
19
|
+
pip install "docling-pp-ocrv6[gpu]" # CUDA (onnxruntime-gpu)
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
The detection and recognition ONNX models are downloaded from HuggingFace on
|
|
23
|
+
first use and cached under docling's model cache. To pre-fetch them (e.g. at
|
|
24
|
+
container build time):
|
|
25
|
+
|
|
26
|
+
```python
|
|
27
|
+
from docling_pp_ocrv6 import PPOCRv6Model
|
|
28
|
+
PPOCRv6Model.download_models()
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Usage
|
|
32
|
+
|
|
33
|
+
```python
|
|
34
|
+
from docling.document_converter import DocumentConverter, PdfFormatOption
|
|
35
|
+
from docling.datamodel.base_models import InputFormat
|
|
36
|
+
from docling.datamodel.pipeline_options import PdfPipelineOptions
|
|
37
|
+
from docling_pp_ocrv6 import PPOCRv6Options
|
|
38
|
+
|
|
39
|
+
pipeline_options = PdfPipelineOptions(do_ocr=True)
|
|
40
|
+
pipeline_options.ocr_options = PPOCRv6Options()
|
|
41
|
+
|
|
42
|
+
converter = DocumentConverter(
|
|
43
|
+
format_options={InputFormat.PDF: PdfFormatOption(pipeline_options=pipeline_options)}
|
|
44
|
+
)
|
|
45
|
+
result = converter.convert("scanned.pdf")
|
|
46
|
+
print(result.document.export_to_markdown())
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
With **docling-serve**, request the engine by its `kind`:
|
|
50
|
+
|
|
51
|
+
```json
|
|
52
|
+
{ "options": { "ocr": true, "ocr_engine": "pp-ocrv6" } }
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
(`DOCLING_SERVE_ALLOW_EXTERNAL_PLUGINS=true` must be set for the plugin to load.)
|
|
56
|
+
|
|
57
|
+
## Configuration
|
|
58
|
+
|
|
59
|
+
All options are settable via `PPOCRv6Options(...)` or environment variables:
|
|
60
|
+
|
|
61
|
+
| Option | Env var | Default |
|
|
62
|
+
| --- | --- | --- |
|
|
63
|
+
| `lang` | `PPOCRV6_LANG` | `de,en,fr,it,es,nl,pt,...` (German-led European set) |
|
|
64
|
+
| `text_score` | `PPOCRV6_TEXT_SCORE` | `0.5` |
|
|
65
|
+
| `use_det` / `use_cls` / `use_rec` | `PPOCRV6_USE_DET` / `_CLS` / `_REC` | `true` |
|
|
66
|
+
| `det_repo` | `PPOCRV6_DET_REPO` | `PaddlePaddle/PP-OCRv6_medium_det_onnx` |
|
|
67
|
+
| `rec_repo` | `PPOCRV6_REC_REPO` | `PaddlePaddle/PP-OCRv6_medium_rec_onnx` |
|
|
68
|
+
| `det_model_path` / `rec_model_path` / `rec_keys_path` / `cls_model_path` | `PPOCRV6_*_MODEL_PATH` / `_KEYS_PATH` | auto |
|
|
69
|
+
|
|
70
|
+
The recognition character dictionary is extracted automatically from the
|
|
71
|
+
recognition model's `inference.yml`. Angle classification uses RapidOCR's
|
|
72
|
+
bundled cls model unless `cls_model_path` is set.
|
|
73
|
+
|
|
74
|
+
## Development
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
make install # uv sync + pre-commit
|
|
78
|
+
make check # ruff lint + format check + ty type check
|
|
79
|
+
make test # pytest with coverage
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## License
|
|
83
|
+
|
|
84
|
+
MIT
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "docling-pp-ocrv6"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "A docling OCR plugin for PaddlePaddle PP-OCRv6 (ONNX via RapidOCR)"
|
|
5
|
+
authors = [
|
|
6
|
+
{name = "Yanick Schraner", email = "yanick.schraner@bs.ch"},
|
|
7
|
+
{name = "Tobias Bollinger", email = "tobias.bollinger@bs.ch"},
|
|
8
|
+
]
|
|
9
|
+
requires-python = ">=3.12"
|
|
10
|
+
license = {text = "MIT"}
|
|
11
|
+
readme = "README.md"
|
|
12
|
+
keywords = []
|
|
13
|
+
classifiers = [
|
|
14
|
+
"Programming Language :: Python :: 3",
|
|
15
|
+
"Programming Language :: Python :: 3 :: Only",
|
|
16
|
+
|
|
17
|
+
"License :: OSI Approved :: MIT License",
|
|
18
|
+
|
|
19
|
+
"Operating System :: OS Independent",
|
|
20
|
+
"Intended Audience :: Developers",
|
|
21
|
+
"Typing :: Typed",
|
|
22
|
+
]
|
|
23
|
+
dependencies = [
|
|
24
|
+
"docling>=2.73",
|
|
25
|
+
"rapidocr>=3.0",
|
|
26
|
+
"huggingface-hub>=1.3.0",
|
|
27
|
+
"pyyaml>=6.0",
|
|
28
|
+
"numpy",
|
|
29
|
+
"pillow>=10.0",
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
[project.optional-dependencies]
|
|
33
|
+
# onnxruntime is intentionally NOT a base dependency: installing both the CPU
|
|
34
|
+
# and GPU wheels at once is unsupported and makes the CUDA provider fail to
|
|
35
|
+
# register. Pick exactly one extra.
|
|
36
|
+
cpu = ["onnxruntime>=1.17"]
|
|
37
|
+
gpu = ["onnxruntime-gpu>=1.17"]
|
|
38
|
+
|
|
39
|
+
[project.entry-points."docling"]
|
|
40
|
+
docling_pp_ocrv6 = "docling_pp_ocrv6.plugin"
|
|
41
|
+
|
|
42
|
+
[project.urls]
|
|
43
|
+
Homepage = "https://github.com/DCC-BS/docling-pp-ocrv6"
|
|
44
|
+
Repository = "https://github.com/DCC-BS/docling-pp-ocrv6"
|
|
45
|
+
Issues = "https://github.com/DCC-BS/docling-pp-ocrv6/issues"
|
|
46
|
+
Changelog = "https://github.com/DCC-BS/docling-pp-ocrv6/releases"
|
|
47
|
+
|
|
48
|
+
[dependency-groups]
|
|
49
|
+
dev = [
|
|
50
|
+
"pytest>=8.0.0",
|
|
51
|
+
"pytest-cov>=6.0.0",
|
|
52
|
+
"ruff>=0.9.0",
|
|
53
|
+
"ty>=0.0.9",
|
|
54
|
+
"pre-commit>=4.5.1",
|
|
55
|
+
]
|
|
56
|
+
|
|
57
|
+
[build-system]
|
|
58
|
+
requires = ["hatchling"]
|
|
59
|
+
build-backend = "hatchling.build"
|
|
60
|
+
|
|
61
|
+
[tool.hatch.build.targets.wheel]
|
|
62
|
+
packages = ["src/docling_pp_ocrv6"]
|
|
63
|
+
|
|
64
|
+
[tool.ruff]
|
|
65
|
+
target-version = "py313"
|
|
66
|
+
line-length = 120
|
|
67
|
+
|
|
68
|
+
[tool.ruff.lint]
|
|
69
|
+
select = [
|
|
70
|
+
"A", # flake8-builtins
|
|
71
|
+
"ANN", # flake8-annotations
|
|
72
|
+
"ARG", # flake8-unused-arguments
|
|
73
|
+
"B", # flake8-bugbear
|
|
74
|
+
"BLE", # flake8-blind-except
|
|
75
|
+
"C4", # flake8-comprehensions
|
|
76
|
+
"C90", # mccabe complexity
|
|
77
|
+
"COM", # flake8-commas
|
|
78
|
+
"D", # pydocstyle
|
|
79
|
+
"DTZ", # flake8-datetimez
|
|
80
|
+
"E", # pycodestyle errors
|
|
81
|
+
"EM", # flake8-errmsg
|
|
82
|
+
"ERA", # eradicate
|
|
83
|
+
"F", # pyflakes
|
|
84
|
+
"FBT", # flake8-boolean-trap
|
|
85
|
+
"I", # isort
|
|
86
|
+
"ICN", # flake8-import-conventions
|
|
87
|
+
"ISC", # flake8-implicit-str-concat
|
|
88
|
+
"N", # pep8-naming
|
|
89
|
+
"PD", # pandas-vet
|
|
90
|
+
"PGH", # pygrep-hooks
|
|
91
|
+
"PIE", # flake8-pie
|
|
92
|
+
"PL", # pylint
|
|
93
|
+
"PT", # flake8-pytest-style
|
|
94
|
+
"PTH", # flake8-use-pathlib
|
|
95
|
+
"PYI", # flake8-pyi
|
|
96
|
+
"Q", # flake8-quotes
|
|
97
|
+
"RET", # flake8-return
|
|
98
|
+
"RSE", # flake8-raise
|
|
99
|
+
"RUF", # ruff-specific
|
|
100
|
+
"S", # flake8-bandit
|
|
101
|
+
"SIM", # flake8-simplify
|
|
102
|
+
"SLF", # flake8-self
|
|
103
|
+
"T20", # flake8-print
|
|
104
|
+
"TCH", # flake8-type-checking
|
|
105
|
+
"TID", # flake8-tidy-imports
|
|
106
|
+
"TRY", # tryceratops
|
|
107
|
+
"UP", # pyupgrade
|
|
108
|
+
"W", # pycodestyle warnings
|
|
109
|
+
"YTT", # flake8-2020
|
|
110
|
+
]
|
|
111
|
+
ignore = [
|
|
112
|
+
"COM812", # trailing comma – conflicts with formatter
|
|
113
|
+
"D100", # missing docstring in public module
|
|
114
|
+
"D104", # missing docstring in public package
|
|
115
|
+
"D107", # missing docstring in __init__
|
|
116
|
+
"D203", # one-blank-line-before-class (conflicts with D211)
|
|
117
|
+
"D213", # multi-line-summary-second-line (conflicts with D212)
|
|
118
|
+
"ISC001", # implicit string concat – conflicts with formatter
|
|
119
|
+
]
|
|
120
|
+
|
|
121
|
+
[tool.ruff.lint.per-file-ignores]
|
|
122
|
+
"tests/*" = ["S101", "D", "ANN", "ARG", "SLF", "PLC0415", "PLR2004"]
|
|
123
|
+
|
|
124
|
+
[tool.ruff.lint.pydocstyle]
|
|
125
|
+
convention = "google"
|
|
126
|
+
|
|
127
|
+
[tool.ruff.format]
|
|
128
|
+
preview = true
|
|
129
|
+
indent-style = "space"
|
|
130
|
+
quote-style = "double"
|
|
131
|
+
skip-magic-trailing-comma = false
|
|
132
|
+
line-ending = "auto"
|
|
133
|
+
|
|
134
|
+
[tool.ty.environment]
|
|
135
|
+
python-version = "3.13"
|
|
136
|
+
|
|
137
|
+
[tool.pytest.ini_options]
|
|
138
|
+
testpaths = ["tests"]
|
|
139
|
+
addopts = [
|
|
140
|
+
"--cov=src/docling_pp_ocrv6",
|
|
141
|
+
"--cov-report=term-missing",
|
|
142
|
+
"--cov-report=xml",
|
|
143
|
+
"-v",
|
|
144
|
+
]
|
|
145
|
+
markers = [
|
|
146
|
+
"e2e: end-to-end tests requiring the PP-OCRv6 ONNX models (downloads from HuggingFace)",
|
|
147
|
+
]
|
|
148
|
+
|
|
149
|
+
[tool.coverage.run]
|
|
150
|
+
source = ["src/docling_pp_ocrv6"]
|
|
151
|
+
branch = true
|
|
152
|
+
omit = ["tests/*", ".venv/*"]
|
|
153
|
+
|
|
154
|
+
[tool.coverage.report]
|
|
155
|
+
show_missing = true
|
|
156
|
+
fail_under = 80
|
|
157
|
+
exclude_lines = [
|
|
158
|
+
"pragma: no cover",
|
|
159
|
+
"if TYPE_CHECKING:",
|
|
160
|
+
"raise NotImplementedError",
|
|
161
|
+
"@(abc\\.)?abstractmethod",
|
|
162
|
+
]
|
|
163
|
+
|
|
164
|
+
[tool.uv]
|
|
165
|
+
exclude-newer = "1 week"
|
|
166
|
+
exclude-newer-package = { dcc-backend-common = "P1D" }
|