BabelDOC 0.4.20__tar.gz → 0.4.22__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.
- {babeldoc-0.4.20 → babeldoc-0.4.22}/PKG-INFO +2 -1
- babeldoc-0.4.22/babeldoc/__init__.py +1 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/const.py +1 -1
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/docvision/base_doclayout.py +0 -11
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/docvision/rpc_doclayout.py +2 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/docvision/rpc_doclayout2.py +1 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/docvision/rpc_doclayout3.py +1 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/docvision/rpc_doclayout4.py +1 -0
- babeldoc-0.4.22/babeldoc/docvision/rpc_doclayout5.py +328 -0
- babeldoc-0.4.22/babeldoc/docvision/rpc_doclayout6.py +504 -0
- babeldoc-0.4.22/babeldoc/docvision/rpc_doclayout7.py +353 -0
- babeldoc-0.4.22/babeldoc/format/pdf/babelpdf/utils.py +14 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/format/pdf/document_il/frontend/il_creater.py +20 -23
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/format/pdf/document_il/midend/add_debug_information.py +3 -1
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/format/pdf/document_il/midend/il_translator_llm_only.py +1 -1
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/format/pdf/document_il/midend/layout_parser.py +40 -2
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/format/pdf/document_il/midend/typesetting.py +6 -1
- babeldoc-0.4.22/babeldoc/format/pdf/document_il/utils/extract_char.py +749 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/format/pdf/document_il/utils/layout_helper.py +64 -7
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/format/pdf/pdfinterp.py +2 -1
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/format/pdf/translation_config.py +3 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/main.py +25 -1
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/layout.py +2 -1
- {babeldoc-0.4.20 → babeldoc-0.4.22}/pyproject.toml +3 -2
- babeldoc-0.4.20/babeldoc/__init__.py +0 -1
- {babeldoc-0.4.20 → babeldoc-0.4.22}/.cursorignore +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/.github/ISSUE_TEMPLATE/bug_report.yaml +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/.github/ISSUE_TEMPLATE/feature_request.yaml +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/.github/PULL_REQUEST_TEMPLATE/pr_form.yml +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/.github/PULL_REQUEST_TEMPLATE.md +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/.github/dependabot.yml +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/.github/labels.yml +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/.github/release-drafter.yml +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/.github/workflows/codeql.yml +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/.github/workflows/docs.yml +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/.github/workflows/labeler.yml +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/.github/workflows/lint.yml +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/.github/workflows/pr-lint.yml +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/.github/workflows/publish-to-pypi.yml +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/.github/workflows/test.yml +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/.gitignore +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/.pre-commit-config.yaml +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/LICENSE +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/README.md +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/assets/assets.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/assets/embedding_assets_metadata.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/asynchronize/__init__.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/babeldoc_exception/BabelDOCException.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/babeldoc_exception/__init__.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/docvision/README.md +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/docvision/__init__.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/docvision/doclayout.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/docvision/table_detection/rapidocr.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/format/__init__.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/format/pdf/__init__.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/format/pdf/babelpdf/base14.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/format/pdf/babelpdf/encoding.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/format/pdf/converter.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/format/pdf/document_il/__init__.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/format/pdf/document_il/backend/__init__.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/format/pdf/document_il/backend/pdf_creater.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/format/pdf/document_il/frontend/__init__.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/format/pdf/document_il/il_version_1.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/format/pdf/document_il/il_version_1.rnc +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/format/pdf/document_il/il_version_1.rng +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/format/pdf/document_il/il_version_1.xsd +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/format/pdf/document_il/midend/__init__.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/format/pdf/document_il/midend/automatic_term_extractor.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/format/pdf/document_il/midend/detect_scanned_file.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/format/pdf/document_il/midend/il_translator.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/format/pdf/document_il/midend/paragraph_finder.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/format/pdf/document_il/midend/remove_descent.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/format/pdf/document_il/midend/styles_and_formulas.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/format/pdf/document_il/midend/table_parser.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/format/pdf/document_il/utils/__init__.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/format/pdf/document_il/utils/fontmap.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/format/pdf/document_il/utils/formular_helper.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/format/pdf/document_il/utils/mupdf_helper.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/format/pdf/document_il/utils/paragraph_helper.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/format/pdf/document_il/utils/style_helper.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/format/pdf/document_il/utils/zstd_helper.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/format/pdf/document_il/xml_converter.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/format/pdf/high_level.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/format/pdf/result_merger.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/format/pdf/split_manager.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/glossary.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/LICENSE +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/__init__.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/_saslprep.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/arcfour.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/ascii85.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/casting.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/ccitt.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/78-EUC-H.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/78-EUC-V.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/78-H.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/78-RKSJ-H.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/78-RKSJ-V.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/78-V.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/78ms-RKSJ-H.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/78ms-RKSJ-V.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/83pv-RKSJ-H.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/83pv-RKSJ-V.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/90ms-RKSJ-H.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/90ms-RKSJ-V.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/90msp-RKSJ-H.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/90msp-RKSJ-V.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/90pv-RKSJ-H.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/90pv-RKSJ-V.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/Add-H.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/Add-RKSJ-H.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/Add-RKSJ-V.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/Add-V.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/B5-H.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/B5-V.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/B5pc-H.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/B5pc-V.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/CNS-EUC-H.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/CNS-EUC-V.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/CNS1-H.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/CNS1-V.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/CNS2-H.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/CNS2-V.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/ETHK-B5-H.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/ETHK-B5-V.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/ETen-B5-H.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/ETen-B5-V.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/ETenms-B5-H.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/ETenms-B5-V.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/EUC-H.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/EUC-V.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/Ext-H.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/Ext-RKSJ-H.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/Ext-RKSJ-V.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/Ext-V.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/GB-EUC-H.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/GB-EUC-V.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/GB-H.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/GB-V.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/GBK-EUC-H.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/GBK-EUC-V.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/GBK2K-H.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/GBK2K-V.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/GBKp-EUC-H.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/GBKp-EUC-V.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/GBT-EUC-H.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/GBT-EUC-V.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/GBT-H.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/GBT-V.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/GBTpc-EUC-H.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/GBTpc-EUC-V.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/GBpc-EUC-H.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/GBpc-EUC-V.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/H.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/HKdla-B5-H.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/HKdla-B5-V.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/HKdlb-B5-H.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/HKdlb-B5-V.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/HKgccs-B5-H.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/HKgccs-B5-V.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/HKm314-B5-H.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/HKm314-B5-V.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/HKm471-B5-H.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/HKm471-B5-V.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/HKscs-B5-H.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/HKscs-B5-V.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/Hankaku-H.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/Hankaku-V.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/Hiragana-H.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/Hiragana-V.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/KSC-EUC-H.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/KSC-EUC-V.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/KSC-H.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/KSC-Johab-H.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/KSC-Johab-V.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/KSC-V.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/KSCms-UHC-H.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/KSCms-UHC-HW-H.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/KSCms-UHC-HW-V.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/KSCms-UHC-V.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/KSCpc-EUC-H.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/KSCpc-EUC-V.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/Katakana-H.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/Katakana-V.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/NWP-H.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/NWP-V.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/README.txt +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/RKSJ-H.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/RKSJ-V.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/Roman-H.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/Roman-V.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/UniCNS-UCS2-H.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/UniCNS-UCS2-V.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/UniCNS-UTF16-H.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/UniCNS-UTF16-V.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/UniCNS-UTF32-H.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/UniCNS-UTF32-V.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/UniCNS-UTF8-H.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/UniCNS-UTF8-V.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/UniGB-UCS2-H.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/UniGB-UCS2-V.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/UniGB-UTF16-H.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/UniGB-UTF16-V.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/UniGB-UTF32-H.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/UniGB-UTF32-V.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/UniGB-UTF8-H.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/UniGB-UTF8-V.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/UniJIS-UCS2-H.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/UniJIS-UCS2-HW-H.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/UniJIS-UCS2-HW-V.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/UniJIS-UCS2-V.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/UniJIS-UTF16-H.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/UniJIS-UTF16-V.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/UniJIS-UTF32-H.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/UniJIS-UTF32-V.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/UniJIS-UTF8-H.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/UniJIS-UTF8-V.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/UniJIS2004-UTF16-H.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/UniJIS2004-UTF16-V.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/UniJIS2004-UTF32-H.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/UniJIS2004-UTF32-V.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/UniJIS2004-UTF8-H.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/UniJIS2004-UTF8-V.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/UniJISX0213-UTF32-H.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/UniJISX0213-UTF32-V.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/UniJISX02132004-UTF32-H.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/UniJISX02132004-UTF32-V.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/UniKS-UCS2-H.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/UniKS-UCS2-V.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/UniKS-UTF16-H.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/UniKS-UTF16-V.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/UniKS-UTF32-H.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/UniKS-UTF32-V.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/UniKS-UTF8-H.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/UniKS-UTF8-V.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/V.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/WP-Symbol-H.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/WP-Symbol-V.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/to-unicode-Adobe-CNS1.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/to-unicode-Adobe-GB1.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/to-unicode-Adobe-Japan1.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmap/to-unicode-Adobe-Korea1.pickle.gz +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/cmapdb.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/converter.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/data_structures.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/encodingdb.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/fontmetrics.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/glyphlist.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/high_level.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/image.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/jbig2.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/latin_enc.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/lzw.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/pdfcolor.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/pdfdevice.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/pdfdocument.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/pdfexceptions.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/pdffont.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/pdfinterp.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/pdfpage.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/pdfparser.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/pdftypes.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/psexceptions.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/psparser.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/py.typed +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/runlength.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/settings.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/pdfminer/utils.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/progress_monitor.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/tools/generate_font_metadata.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/tools/italic_assistance.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/tools/italic_recognize_tool.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/translator/__init__.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/translator/cache.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/translator/translator.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/utils/__init__.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/utils/atomic_integer.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/babeldoc/utils/priority_thread_pool_executor.py +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/docs/CODE_OF_CONDUCT.md +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/docs/CONTRIBUTING.md +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/docs/CONTRIBUTOR_REWARD.md +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/docs/ImplementationDetails/AsyncTranslate/AsyncTranslate.md +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/docs/ImplementationDetails/ILTranslator/ILTranslator.md +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/docs/ImplementationDetails/PDFCreation/PDFCreation.md +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/docs/ImplementationDetails/PDFParsing/PDFParsing.md +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/docs/ImplementationDetails/ParagraphFinding/ParagraphFinding.md +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/docs/ImplementationDetails/README.md +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/docs/ImplementationDetails/StylesAndFormulas/StylesAndFormulas.md +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/docs/ImplementationDetails/Typesetting/Typesetting.md +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/docs/README.md +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/docs/deploy.sh +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/docs/example/demo_glossary.csv +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/docs/images/babeldoc-banner.png +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/docs/images/babeldoc-big-logo-darkmode-with-transparent-background.png +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/docs/images/babeldoc-big-logo-darkmode-with-transparent-background.svg +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/docs/images/babeldoc-big-logo-with-transparent-background.png +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/docs/images/babeldoc-big-logo-with-transparent-background.svg +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/docs/images/babeldoc-big-logo.png +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/docs/images/babeldoc-contributor_reward_example.png +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/docs/images/babeldoc-preview.gif +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/docs/images/babeldoc-small-logo-with-transparent-background.png +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/docs/images/babeldoc-small-logo-with-transparent-background.svg +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/docs/images/babeldoc-small-logo.png +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/docs/index.md +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/docs/intro-to-pdf-object.md +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/docs/requirements.txt +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/docs/supported_languages.md +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/mkdocs.yml +0 -0
- {babeldoc-0.4.20 → babeldoc-0.4.22}/tests/test_translation_cache_cleanup.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: BabelDOC
|
|
3
|
-
Version: 0.4.
|
|
3
|
+
Version: 0.4.22
|
|
4
4
|
Summary: Yet Another Document Translator
|
|
5
5
|
Project-URL: Homepage, https://github.com/funstory-ai/BabelDOC
|
|
6
6
|
Project-URL: Issues, https://github.com/funstory-ai/BabelDOC/issues
|
|
@@ -38,6 +38,7 @@ Requires-Dist: rapidocr-onnxruntime>=1.4.4
|
|
|
38
38
|
Requires-Dist: rich>=13.9.4
|
|
39
39
|
Requires-Dist: rtree>=1.4.0
|
|
40
40
|
Requires-Dist: scikit-image>=0.25.2
|
|
41
|
+
Requires-Dist: scikit-learn>=1.7.1
|
|
41
42
|
Requires-Dist: scipy>=1.15.3
|
|
42
43
|
Requires-Dist: tenacity>=9.0.0
|
|
43
44
|
Requires-Dist: tiktoken>=0.9.0
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.4.22"
|
|
@@ -55,17 +55,6 @@ class DocLayoutModel(abc.ABC):
|
|
|
55
55
|
def stride(self) -> int:
|
|
56
56
|
"""Stride of the model input."""
|
|
57
57
|
|
|
58
|
-
@abc.abstractmethod
|
|
59
|
-
def predict(self, image: bytes, imgsz: int = 1024, **kwargs) -> list[int]:
|
|
60
|
-
"""
|
|
61
|
-
Predict the layout of a document page.
|
|
62
|
-
|
|
63
|
-
Args:
|
|
64
|
-
image: The image of the document page.
|
|
65
|
-
imgsz: Resize the image to this size. Must be a multiple of the stride.
|
|
66
|
-
**kwargs: Additional arguments.
|
|
67
|
-
"""
|
|
68
|
-
|
|
69
58
|
@abc.abstractmethod
|
|
70
59
|
def handle_document(
|
|
71
60
|
self,
|
|
@@ -38,6 +38,8 @@ def encode_image(image) -> bytes:
|
|
|
38
38
|
img = image
|
|
39
39
|
|
|
40
40
|
# logger.debug(f"Image shape: {img.shape}")
|
|
41
|
+
img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
|
|
42
|
+
|
|
41
43
|
encoded = cv2.imencode(".jpg", img)[1].tobytes()
|
|
42
44
|
# logger.debug(f"Encoded image size: {len(encoded)} bytes")
|
|
43
45
|
return encoded
|
|
@@ -38,6 +38,7 @@ def encode_image(image) -> bytes:
|
|
|
38
38
|
else:
|
|
39
39
|
img = image
|
|
40
40
|
|
|
41
|
+
img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
|
|
41
42
|
# logger.debug(f"Image shape: {img.shape}")
|
|
42
43
|
encoded = cv2.imencode(".jpg", img)[1].tobytes()
|
|
43
44
|
# logger.debug(f"Encoded image size: {len(encoded)} bytes")
|
|
@@ -38,6 +38,7 @@ def encode_image(image) -> bytes:
|
|
|
38
38
|
else:
|
|
39
39
|
img = image
|
|
40
40
|
|
|
41
|
+
img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
|
|
41
42
|
# logger.debug(f"Image shape: {img.shape}")
|
|
42
43
|
encoded = cv2.imencode(".jpg", img)[1].tobytes()
|
|
43
44
|
# logger.debug(f"Encoded image size: {len(encoded)} bytes")
|
|
@@ -38,6 +38,7 @@ def encode_image(image) -> bytes:
|
|
|
38
38
|
else:
|
|
39
39
|
img = image
|
|
40
40
|
|
|
41
|
+
img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
|
|
41
42
|
# logger.debug(f"Image shape: {img.shape}")
|
|
42
43
|
encoded = cv2.imencode(".jpg", img)[1].tobytes()
|
|
43
44
|
# logger.debug(f"Encoded image size: {len(encoded)} bytes")
|
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import logging
|
|
3
|
+
import threading
|
|
4
|
+
from concurrent.futures import ThreadPoolExecutor
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
|
|
7
|
+
import cv2
|
|
8
|
+
import httpx
|
|
9
|
+
import numpy as np
|
|
10
|
+
import pymupdf
|
|
11
|
+
from tenacity import retry
|
|
12
|
+
from tenacity import retry_if_exception_type
|
|
13
|
+
from tenacity import stop_after_attempt
|
|
14
|
+
from tenacity import wait_exponential
|
|
15
|
+
|
|
16
|
+
import babeldoc
|
|
17
|
+
from babeldoc.docvision.base_doclayout import DocLayoutModel
|
|
18
|
+
from babeldoc.docvision.base_doclayout import YoloBox
|
|
19
|
+
from babeldoc.docvision.base_doclayout import YoloResult
|
|
20
|
+
from babeldoc.format.pdf.document_il.utils.mupdf_helper import get_no_rotation_img
|
|
21
|
+
|
|
22
|
+
logger = logging.getLogger(__name__)
|
|
23
|
+
DPI = 150
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def encode_image(image) -> bytes:
|
|
27
|
+
"""Read and encode image to bytes
|
|
28
|
+
|
|
29
|
+
Args:
|
|
30
|
+
image: Can be either a file path (str) or numpy array
|
|
31
|
+
"""
|
|
32
|
+
if isinstance(image, str):
|
|
33
|
+
if not Path(image).exists():
|
|
34
|
+
raise FileNotFoundError(f"Image file not found: {image}")
|
|
35
|
+
img = cv2.imread(image)
|
|
36
|
+
if img is None:
|
|
37
|
+
raise ValueError(f"Failed to read image: {image}")
|
|
38
|
+
else:
|
|
39
|
+
img = image
|
|
40
|
+
|
|
41
|
+
img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
|
|
42
|
+
# logger.debug(f"Image shape: {img.shape}")
|
|
43
|
+
encoded = cv2.imencode(".jpg", img)[1].tobytes()
|
|
44
|
+
# logger.debug(f"Encoded image size: {len(encoded)} bytes")
|
|
45
|
+
return encoded
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
@retry(
|
|
49
|
+
stop=stop_after_attempt(3), # 最多重试 3 次
|
|
50
|
+
wait=wait_exponential(
|
|
51
|
+
multiplier=1, min=1, max=10
|
|
52
|
+
), # 指数退避策略,初始 1 秒,最大 10 秒
|
|
53
|
+
retry=retry_if_exception_type((httpx.HTTPError, Exception)), # 针对哪些异常重试
|
|
54
|
+
before_sleep=lambda retry_state: logger.warning(
|
|
55
|
+
f"Request failed, retrying in {getattr(retry_state.next_action, 'sleep', 'unknown')} seconds... "
|
|
56
|
+
f"(Attempt {retry_state.attempt_number}/3)"
|
|
57
|
+
),
|
|
58
|
+
)
|
|
59
|
+
def predict_layout(
|
|
60
|
+
image,
|
|
61
|
+
host: str = "http://localhost:8000",
|
|
62
|
+
_imgsz: int = 1024,
|
|
63
|
+
):
|
|
64
|
+
"""
|
|
65
|
+
Predict document layout using the MOSEC service
|
|
66
|
+
|
|
67
|
+
Args:
|
|
68
|
+
image: Can be either a file path (str) or numpy array
|
|
69
|
+
host: Service host URL
|
|
70
|
+
imgsz: Image size for model input
|
|
71
|
+
|
|
72
|
+
Returns:
|
|
73
|
+
List of predictions containing bounding boxes and classes
|
|
74
|
+
"""
|
|
75
|
+
# Prepare request data
|
|
76
|
+
|
|
77
|
+
image_data = encode_image(image)
|
|
78
|
+
|
|
79
|
+
# Pack data using msgpack
|
|
80
|
+
# packed_data = msgpack.packb(data, use_bin_type=True)
|
|
81
|
+
# logger.debug(f"Packed data size: {len(packed_data)} bytes")
|
|
82
|
+
|
|
83
|
+
# Send request
|
|
84
|
+
# logger.debug(f"Sending request to {host}/inference")
|
|
85
|
+
response = httpx.post(
|
|
86
|
+
f"{host}/analyze_hybrid?min_sim=0.7&early_stop=0.99&timeout=1800",
|
|
87
|
+
files={"file": ("image.jpg", image_data, "image/jpeg")},
|
|
88
|
+
headers={
|
|
89
|
+
"Accept": "application/json",
|
|
90
|
+
},
|
|
91
|
+
timeout=1800,
|
|
92
|
+
follow_redirects=True,
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
# logger.debug(f"Response status: {response.status_code}")
|
|
96
|
+
# logger.debug(f"Response headers: {response.headers}")
|
|
97
|
+
idx = 0
|
|
98
|
+
id_lookup = {}
|
|
99
|
+
if response.status_code == 200:
|
|
100
|
+
try:
|
|
101
|
+
result = json.loads(response.text)
|
|
102
|
+
useful_result = []
|
|
103
|
+
if isinstance(result, dict):
|
|
104
|
+
names = {}
|
|
105
|
+
clusters = result["clusters"]
|
|
106
|
+
for box in clusters:
|
|
107
|
+
box["xyxy"] = box["box"]
|
|
108
|
+
box["conf"] = 1
|
|
109
|
+
if box["label"] not in names:
|
|
110
|
+
idx += 1
|
|
111
|
+
names[idx] = box["label"]
|
|
112
|
+
box["cls_id"] = idx
|
|
113
|
+
id_lookup[box["label"]] = idx
|
|
114
|
+
else:
|
|
115
|
+
box["cls_id"] = id_lookup[box["label"]]
|
|
116
|
+
names[box["cls_id"]] = box["label"]
|
|
117
|
+
box["cls"] = box["cls_id"]
|
|
118
|
+
useful_result.append(box)
|
|
119
|
+
if "names" not in result:
|
|
120
|
+
result["names"] = names
|
|
121
|
+
result["boxes"] = useful_result
|
|
122
|
+
result = [result]
|
|
123
|
+
return result
|
|
124
|
+
except Exception as e:
|
|
125
|
+
logger.exception(f"Failed to unpack response: {e!s}")
|
|
126
|
+
raise
|
|
127
|
+
else:
|
|
128
|
+
logger.error(f"Request failed with status {response.status_code}")
|
|
129
|
+
logger.error(f"Response content: {response.text}")
|
|
130
|
+
raise Exception(
|
|
131
|
+
f"Request failed with status {response.status_code}: {response.text}",
|
|
132
|
+
)
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
class ResultContainer:
|
|
136
|
+
def __init__(self):
|
|
137
|
+
self.result = YoloResult(boxes_data=np.array([]), names=[])
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
class RpcDocLayoutModel(DocLayoutModel):
|
|
141
|
+
"""DocLayoutModel implementation that uses RPC service."""
|
|
142
|
+
|
|
143
|
+
def __init__(self, host: str = "http://localhost:8000"):
|
|
144
|
+
"""Initialize RPC model with host address."""
|
|
145
|
+
self.host = host
|
|
146
|
+
self._stride = 32 # Default stride value
|
|
147
|
+
self._names = ["text", "title", "list", "table", "figure"]
|
|
148
|
+
self.lock = threading.Lock()
|
|
149
|
+
|
|
150
|
+
@property
|
|
151
|
+
def stride(self) -> int:
|
|
152
|
+
"""Stride of the model input."""
|
|
153
|
+
return self._stride
|
|
154
|
+
|
|
155
|
+
def resize_and_pad_image(self, image, new_shape):
|
|
156
|
+
"""
|
|
157
|
+
Resize and pad the image to the specified size,
|
|
158
|
+
ensuring dimensions are multiples of stride.
|
|
159
|
+
|
|
160
|
+
Parameters:
|
|
161
|
+
- image: Input image
|
|
162
|
+
- new_shape: Target size (integer or (height, width) tuple)
|
|
163
|
+
- stride: Padding alignment stride, default 32
|
|
164
|
+
|
|
165
|
+
Returns:
|
|
166
|
+
- Processed image
|
|
167
|
+
"""
|
|
168
|
+
if isinstance(new_shape, int):
|
|
169
|
+
new_shape = (new_shape, new_shape)
|
|
170
|
+
|
|
171
|
+
h, w = image.shape[:2]
|
|
172
|
+
new_h, new_w = new_shape
|
|
173
|
+
|
|
174
|
+
# Calculate scaling ratio
|
|
175
|
+
r = min(new_h / h, new_w / w)
|
|
176
|
+
resized_h, resized_w = int(round(h * r)), int(round(w * r))
|
|
177
|
+
|
|
178
|
+
# Resize image
|
|
179
|
+
image = cv2.resize(
|
|
180
|
+
image, (resized_w, resized_h), interpolation=cv2.INTER_LINEAR
|
|
181
|
+
)
|
|
182
|
+
|
|
183
|
+
# Calculate padding size
|
|
184
|
+
pad_h = new_h - resized_h
|
|
185
|
+
pad_w = new_w - resized_w
|
|
186
|
+
top, bottom = pad_h // 2, pad_h - pad_h // 2
|
|
187
|
+
left, right = pad_w // 2, pad_w - pad_w // 2
|
|
188
|
+
|
|
189
|
+
# Add padding
|
|
190
|
+
image = cv2.copyMakeBorder(
|
|
191
|
+
image, top, bottom, left, right, cv2.BORDER_CONSTANT, value=(114, 114, 114)
|
|
192
|
+
)
|
|
193
|
+
|
|
194
|
+
return image
|
|
195
|
+
|
|
196
|
+
def scale_boxes(self, img1_shape, boxes, img0_shape):
|
|
197
|
+
"""
|
|
198
|
+
Rescales bounding boxes (in the format of xyxy by default) from the shape of the image they were originally
|
|
199
|
+
specified in (img1_shape) to the shape of a different image (img0_shape).
|
|
200
|
+
|
|
201
|
+
Args:
|
|
202
|
+
img1_shape (tuple): The shape of the image that the bounding boxes are for,
|
|
203
|
+
in the format of (height, width).
|
|
204
|
+
boxes (torch.Tensor): the bounding boxes of the objects in the image, in the format of (x1, y1, x2, y2)
|
|
205
|
+
img0_shape (tuple): the shape of the target image, in the format of (height, width).
|
|
206
|
+
|
|
207
|
+
Returns:
|
|
208
|
+
boxes (torch.Tensor): The scaled bounding boxes, in the format of (x1, y1, x2, y2)
|
|
209
|
+
"""
|
|
210
|
+
|
|
211
|
+
# Calculate scaling ratio
|
|
212
|
+
gain = min(img1_shape[0] / img0_shape[0], img1_shape[1] / img0_shape[1])
|
|
213
|
+
|
|
214
|
+
# Calculate padding size
|
|
215
|
+
pad_x = round((img1_shape[1] - img0_shape[1] * gain) / 2 - 0.1)
|
|
216
|
+
pad_y = round((img1_shape[0] - img0_shape[0] * gain) / 2 - 0.1)
|
|
217
|
+
|
|
218
|
+
# Remove padding and scale boxes
|
|
219
|
+
boxes = (boxes - [pad_x, pad_y, pad_x, pad_y]) / gain
|
|
220
|
+
return boxes
|
|
221
|
+
|
|
222
|
+
def predict_image(
|
|
223
|
+
self,
|
|
224
|
+
image,
|
|
225
|
+
host: str | None = None,
|
|
226
|
+
result_container: ResultContainer | None = None,
|
|
227
|
+
imgsz: int = 1024,
|
|
228
|
+
) -> ResultContainer:
|
|
229
|
+
"""Predict the layout of document pages using RPC service."""
|
|
230
|
+
if result_container is None:
|
|
231
|
+
result_container = ResultContainer()
|
|
232
|
+
target_imgsz = (800, 800)
|
|
233
|
+
orig_h, orig_w = image.shape[:2]
|
|
234
|
+
target_imgsz = (orig_h, orig_w)
|
|
235
|
+
if image.shape[0] != target_imgsz[0] or image.shape[1] != target_imgsz[1]:
|
|
236
|
+
image = self.resize_and_pad_image(image, new_shape=target_imgsz)
|
|
237
|
+
preds = predict_layout(image, host=self.host)
|
|
238
|
+
orig_h, orig_w = orig_h / DPI * 72, orig_w / DPI * 72
|
|
239
|
+
if len(preds) > 0:
|
|
240
|
+
for pred in preds:
|
|
241
|
+
boxes = [
|
|
242
|
+
YoloBox(
|
|
243
|
+
None,
|
|
244
|
+
self.scale_boxes(
|
|
245
|
+
target_imgsz, np.array(x["xyxy"]), (orig_h, orig_w)
|
|
246
|
+
),
|
|
247
|
+
np.array(x["conf"]),
|
|
248
|
+
x["cls"],
|
|
249
|
+
)
|
|
250
|
+
for x in pred["boxes"]
|
|
251
|
+
]
|
|
252
|
+
result_container.result = YoloResult(
|
|
253
|
+
boxes=boxes,
|
|
254
|
+
names={int(k): v for k, v in pred["names"].items()},
|
|
255
|
+
)
|
|
256
|
+
return result_container.result
|
|
257
|
+
|
|
258
|
+
def predict(self, image, imgsz=1024, **kwargs) -> list[YoloResult]:
|
|
259
|
+
"""Predict the layout of document pages using RPC service."""
|
|
260
|
+
# Handle single image input
|
|
261
|
+
if isinstance(image, np.ndarray) and len(image.shape) == 3:
|
|
262
|
+
image = [image]
|
|
263
|
+
|
|
264
|
+
result_containers = [ResultContainer() for _ in image]
|
|
265
|
+
predict_thread = ThreadPoolExecutor(max_workers=len(image))
|
|
266
|
+
for img, result_container in zip(image, result_containers, strict=True):
|
|
267
|
+
predict_thread.submit(
|
|
268
|
+
self.predict_image, img, self.host, result_container, 800
|
|
269
|
+
)
|
|
270
|
+
predict_thread.shutdown(wait=True)
|
|
271
|
+
result = [result_container.result for result_container in result_containers]
|
|
272
|
+
return result
|
|
273
|
+
|
|
274
|
+
def predict_page(
|
|
275
|
+
self, page, mupdf_doc: pymupdf.Document, translate_config, save_debug_image
|
|
276
|
+
):
|
|
277
|
+
translate_config.raise_if_cancelled()
|
|
278
|
+
with self.lock:
|
|
279
|
+
# pix = mupdf_doc[page.page_number].get_pixmap(dpi=72)
|
|
280
|
+
pix = get_no_rotation_img(mupdf_doc[page.page_number], dpi=DPI)
|
|
281
|
+
image = np.frombuffer(pix.samples, np.uint8).reshape(
|
|
282
|
+
pix.height,
|
|
283
|
+
pix.width,
|
|
284
|
+
3,
|
|
285
|
+
)[:, :, ::-1]
|
|
286
|
+
predict_result = self.predict_image(image, self.host, None, 800)
|
|
287
|
+
save_debug_image(image, predict_result, page.page_number + 1)
|
|
288
|
+
return page, predict_result
|
|
289
|
+
|
|
290
|
+
def handle_document(
|
|
291
|
+
self,
|
|
292
|
+
pages: list[babeldoc.format.pdf.document_il.il_version_1.Page],
|
|
293
|
+
mupdf_doc: pymupdf.Document,
|
|
294
|
+
translate_config,
|
|
295
|
+
save_debug_image,
|
|
296
|
+
):
|
|
297
|
+
with ThreadPoolExecutor(max_workers=1) as executor:
|
|
298
|
+
yield from executor.map(
|
|
299
|
+
self.predict_page,
|
|
300
|
+
pages,
|
|
301
|
+
(mupdf_doc for _ in range(len(pages))),
|
|
302
|
+
(translate_config for _ in range(len(pages))),
|
|
303
|
+
(save_debug_image for _ in range(len(pages))),
|
|
304
|
+
)
|
|
305
|
+
|
|
306
|
+
@staticmethod
|
|
307
|
+
def from_host(host: str) -> "RpcDocLayoutModel":
|
|
308
|
+
"""Create RpcDocLayoutModel from host address."""
|
|
309
|
+
return RpcDocLayoutModel(host=host)
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
if __name__ == "__main__":
|
|
313
|
+
logging.basicConfig(level=logging.DEBUG)
|
|
314
|
+
# Test the service
|
|
315
|
+
try:
|
|
316
|
+
# Use a default test image if example/1.png doesn't exist
|
|
317
|
+
image_path = "example/1.png"
|
|
318
|
+
if not Path(image_path).exists():
|
|
319
|
+
print(f"Warning: {image_path} not found.")
|
|
320
|
+
print("Please provide the path to a test image:")
|
|
321
|
+
image_path = input("> ")
|
|
322
|
+
|
|
323
|
+
logger.info(f"Processing image: {image_path}")
|
|
324
|
+
result = predict_layout(image_path)
|
|
325
|
+
print("Prediction results:")
|
|
326
|
+
print(result)
|
|
327
|
+
except Exception as e:
|
|
328
|
+
print(f"Error: {e!s}")
|