BabelDOC 0.2.8__tar.gz → 0.2.10__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.2.8 → babeldoc-0.2.10}/PKG-INFO +15 -27
- {babeldoc-0.2.8 → babeldoc-0.2.10}/README.md +9 -26
- babeldoc-0.2.10/babeldoc/__init__.py +1 -0
- {babeldoc-0.2.8 → babeldoc-0.2.10}/babeldoc/const.py +1 -1
- {babeldoc-0.2.8 → babeldoc-0.2.10}/babeldoc/document_il/backend/pdf_creater.py +4 -4
- {babeldoc-0.2.8 → babeldoc-0.2.10}/babeldoc/document_il/midend/il_translator_llm_only.py +17 -10
- {babeldoc-0.2.8 → babeldoc-0.2.10}/babeldoc/document_il/midend/styles_and_formulas.py +1 -0
- {babeldoc-0.2.8 → babeldoc-0.2.10}/babeldoc/document_il/utils/fontmap.py +5 -1
- {babeldoc-0.2.8 → babeldoc-0.2.10}/babeldoc/docvision/doclayout.py +9 -22
- babeldoc-0.2.10/babeldoc/high_level.py +760 -0
- {babeldoc-0.2.8 → babeldoc-0.2.10}/babeldoc/main.py +20 -7
- {babeldoc-0.2.8 → babeldoc-0.2.10}/babeldoc/progress_monitor.py +77 -4
- babeldoc-0.2.10/babeldoc/result_merger.py +130 -0
- babeldoc-0.2.10/babeldoc/split_manager.py +67 -0
- {babeldoc-0.2.8 → babeldoc-0.2.10}/babeldoc/translation_config.py +70 -7
- {babeldoc-0.2.8 → babeldoc-0.2.10}/docs/CONTRIBUTOR_REWARD.md +1 -0
- {babeldoc-0.2.8 → babeldoc-0.2.10}/pyproject.toml +7 -2
- {babeldoc-0.2.8 → babeldoc-0.2.10}/uv.lock +233 -169
- babeldoc-0.2.8/babeldoc/__init__.py +0 -1
- babeldoc-0.2.8/babeldoc/high_level.py +0 -557
- {babeldoc-0.2.8 → babeldoc-0.2.10}/.cursorignore +0 -0
- {babeldoc-0.2.8 → babeldoc-0.2.10}/.github/ISSUE_TEMPLATE/bug_report.yaml +0 -0
- {babeldoc-0.2.8 → babeldoc-0.2.10}/.github/ISSUE_TEMPLATE/feature_request.yaml +0 -0
- {babeldoc-0.2.8 → babeldoc-0.2.10}/.github/dependabot.yml +0 -0
- {babeldoc-0.2.8 → babeldoc-0.2.10}/.github/labels.yml +0 -0
- {babeldoc-0.2.8 → babeldoc-0.2.10}/.github/release-drafter.yml +0 -0
- {babeldoc-0.2.8 → babeldoc-0.2.10}/.github/workflows/codeql.yml +0 -0
- {babeldoc-0.2.8 → babeldoc-0.2.10}/.github/workflows/docs.yml +0 -0
- {babeldoc-0.2.8 → babeldoc-0.2.10}/.github/workflows/labeler.yml +0 -0
- {babeldoc-0.2.8 → babeldoc-0.2.10}/.github/workflows/publish-to-pypi.yml +0 -0
- {babeldoc-0.2.8 → babeldoc-0.2.10}/.github/workflows/test.yml +0 -0
- {babeldoc-0.2.8 → babeldoc-0.2.10}/.gitignore +0 -0
- {babeldoc-0.2.8 → babeldoc-0.2.10}/.pre-commit-config.yaml +0 -0
- {babeldoc-0.2.8 → babeldoc-0.2.10}/LICENSE +0 -0
- {babeldoc-0.2.8 → babeldoc-0.2.10}/babeldoc/assets/assets.py +0 -0
- {babeldoc-0.2.8 → babeldoc-0.2.10}/babeldoc/assets/embedding_assets_metadata.py +0 -0
- {babeldoc-0.2.8 → babeldoc-0.2.10}/babeldoc/asynchronize/__init__.py +0 -0
- {babeldoc-0.2.8 → babeldoc-0.2.10}/babeldoc/converter.py +0 -0
- {babeldoc-0.2.8 → babeldoc-0.2.10}/babeldoc/document_il/__init__.py +0 -0
- {babeldoc-0.2.8 → babeldoc-0.2.10}/babeldoc/document_il/babeldoc_exception/BabelDOCException.py +0 -0
- {babeldoc-0.2.8 → babeldoc-0.2.10}/babeldoc/document_il/backend/__init__.py +0 -0
- {babeldoc-0.2.8 → babeldoc-0.2.10}/babeldoc/document_il/frontend/__init__.py +0 -0
- {babeldoc-0.2.8 → babeldoc-0.2.10}/babeldoc/document_il/frontend/il_creater.py +0 -0
- {babeldoc-0.2.8 → babeldoc-0.2.10}/babeldoc/document_il/il_version_1.py +0 -0
- {babeldoc-0.2.8 → babeldoc-0.2.10}/babeldoc/document_il/il_version_1.rnc +0 -0
- {babeldoc-0.2.8 → babeldoc-0.2.10}/babeldoc/document_il/il_version_1.rng +0 -0
- {babeldoc-0.2.8 → babeldoc-0.2.10}/babeldoc/document_il/il_version_1.xsd +0 -0
- {babeldoc-0.2.8 → babeldoc-0.2.10}/babeldoc/document_il/midend/__init__.py +0 -0
- {babeldoc-0.2.8 → babeldoc-0.2.10}/babeldoc/document_il/midend/add_debug_information.py +0 -0
- {babeldoc-0.2.8 → babeldoc-0.2.10}/babeldoc/document_il/midend/detect_scanned_file.py +0 -0
- {babeldoc-0.2.8 → babeldoc-0.2.10}/babeldoc/document_il/midend/il_translator.py +0 -0
- {babeldoc-0.2.8 → babeldoc-0.2.10}/babeldoc/document_il/midend/layout_parser.py +0 -0
- {babeldoc-0.2.8 → babeldoc-0.2.10}/babeldoc/document_il/midend/paragraph_finder.py +0 -0
- {babeldoc-0.2.8 → babeldoc-0.2.10}/babeldoc/document_il/midend/remove_descent.py +0 -0
- {babeldoc-0.2.8 → babeldoc-0.2.10}/babeldoc/document_il/midend/typesetting.py +0 -0
- {babeldoc-0.2.8 → babeldoc-0.2.10}/babeldoc/document_il/translator/__init__.py +0 -0
- {babeldoc-0.2.8 → babeldoc-0.2.10}/babeldoc/document_il/translator/cache.py +0 -0
- {babeldoc-0.2.8 → babeldoc-0.2.10}/babeldoc/document_il/translator/translator.py +0 -0
- {babeldoc-0.2.8 → babeldoc-0.2.10}/babeldoc/document_il/utils/layout_helper.py +0 -0
- {babeldoc-0.2.8 → babeldoc-0.2.10}/babeldoc/document_il/utils/style_helper.py +0 -0
- {babeldoc-0.2.8 → babeldoc-0.2.10}/babeldoc/document_il/xml_converter.py +0 -0
- {babeldoc-0.2.8 → babeldoc-0.2.10}/babeldoc/docvision/README.md +0 -0
- {babeldoc-0.2.8 → babeldoc-0.2.10}/babeldoc/docvision/__init__.py +0 -0
- {babeldoc-0.2.8 → babeldoc-0.2.10}/babeldoc/docvision/rpc_doclayout.py +0 -0
- {babeldoc-0.2.8 → babeldoc-0.2.10}/babeldoc/pdfinterp.py +0 -0
- {babeldoc-0.2.8 → babeldoc-0.2.10}/babeldoc/tools/generate_font_metadata.py +0 -0
- {babeldoc-0.2.8 → babeldoc-0.2.10}/docs/CODE_OF_CONDUCT.md +0 -0
- {babeldoc-0.2.8 → babeldoc-0.2.10}/docs/CONTRIBUTING.md +0 -0
- {babeldoc-0.2.8 → babeldoc-0.2.10}/docs/ImplementationDetails/AsyncTranslate/AsyncTranslate.md +0 -0
- {babeldoc-0.2.8 → babeldoc-0.2.10}/docs/ImplementationDetails/ILTranslator/ILTranslator.md +0 -0
- {babeldoc-0.2.8 → babeldoc-0.2.10}/docs/ImplementationDetails/PDFCreation/PDFCreation.md +0 -0
- {babeldoc-0.2.8 → babeldoc-0.2.10}/docs/ImplementationDetails/PDFParsing/PDFParsing.md +0 -0
- {babeldoc-0.2.8 → babeldoc-0.2.10}/docs/ImplementationDetails/ParagraphFinding/ParagraphFinding.md +0 -0
- {babeldoc-0.2.8 → babeldoc-0.2.10}/docs/ImplementationDetails/README.md +0 -0
- {babeldoc-0.2.8 → babeldoc-0.2.10}/docs/ImplementationDetails/StylesAndFormulas/StylesAndFormulas.md +0 -0
- {babeldoc-0.2.8 → babeldoc-0.2.10}/docs/ImplementationDetails/Typesetting/Typesetting.md +0 -0
- {babeldoc-0.2.8 → babeldoc-0.2.10}/docs/README.md +0 -0
- {babeldoc-0.2.8 → babeldoc-0.2.10}/docs/deploy.sh +0 -0
- {babeldoc-0.2.8 → babeldoc-0.2.10}/docs/images/babeldoc-banner.png +0 -0
- {babeldoc-0.2.8 → babeldoc-0.2.10}/docs/images/babeldoc-big-logo-darkmode-with-transparent-background.png +0 -0
- {babeldoc-0.2.8 → babeldoc-0.2.10}/docs/images/babeldoc-big-logo-darkmode-with-transparent-background.svg +0 -0
- {babeldoc-0.2.8 → babeldoc-0.2.10}/docs/images/babeldoc-big-logo-with-transparent-background.png +0 -0
- {babeldoc-0.2.8 → babeldoc-0.2.10}/docs/images/babeldoc-big-logo-with-transparent-background.svg +0 -0
- {babeldoc-0.2.8 → babeldoc-0.2.10}/docs/images/babeldoc-big-logo.png +0 -0
- {babeldoc-0.2.8 → babeldoc-0.2.10}/docs/images/babeldoc-contributor_reward_example.png +0 -0
- {babeldoc-0.2.8 → babeldoc-0.2.10}/docs/images/babeldoc-preview.gif +0 -0
- {babeldoc-0.2.8 → babeldoc-0.2.10}/docs/images/babeldoc-small-logo-with-transparent-background.png +0 -0
- {babeldoc-0.2.8 → babeldoc-0.2.10}/docs/images/babeldoc-small-logo-with-transparent-background.svg +0 -0
- {babeldoc-0.2.8 → babeldoc-0.2.10}/docs/images/babeldoc-small-logo.png +0 -0
- {babeldoc-0.2.8 → babeldoc-0.2.10}/docs/index.md +0 -0
- {babeldoc-0.2.8 → babeldoc-0.2.10}/docs/intro-to-pdf-object.md +0 -0
- {babeldoc-0.2.8 → babeldoc-0.2.10}/docs/requirements.txt +0 -0
- {babeldoc-0.2.8 → babeldoc-0.2.10}/mkdocs.yml +0 -0
- {babeldoc-0.2.8 → babeldoc-0.2.10}/tests/test_translation_config.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: BabelDOC
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.10
|
|
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
|
|
@@ -26,6 +26,7 @@ Requires-Dist: opencv-python-headless>=4.10.0.84
|
|
|
26
26
|
Requires-Dist: orjson>=3.10.14
|
|
27
27
|
Requires-Dist: pdfminer-six>=20240706
|
|
28
28
|
Requires-Dist: peewee>=3.17.8
|
|
29
|
+
Requires-Dist: psutil>=7.0.0
|
|
29
30
|
Requires-Dist: pydantic>=2.10.6
|
|
30
31
|
Requires-Dist: pymupdf>=1.25.1
|
|
31
32
|
Requires-Dist: python-levenshtein>=0.27.1
|
|
@@ -36,6 +37,10 @@ Requires-Dist: tiktoken>=0.9.0
|
|
|
36
37
|
Requires-Dist: toml>=0.10.2
|
|
37
38
|
Requires-Dist: tqdm>=4.67.1
|
|
38
39
|
Requires-Dist: xsdata[cli,lxml,soap]>=24.12
|
|
40
|
+
Provides-Extra: cuda
|
|
41
|
+
Requires-Dist: onnxruntime-gpu>=1.16.1; extra == 'cuda'
|
|
42
|
+
Provides-Extra: directml
|
|
43
|
+
Requires-Dist: onnxruntime-directml>=1.16.1; extra == 'directml'
|
|
39
44
|
Description-Content-Type: text/markdown
|
|
40
45
|
|
|
41
46
|
<!-- # Yet Another Document Translator -->
|
|
@@ -174,6 +179,7 @@ uv run babeldoc --files example.pdf --files example2.pdf --openai --openai-model
|
|
|
174
179
|
- `--enhance-compatibility`: Enable all compatibility enhancement options (equivalent to --skip-clean --dual-translate-first --disable-rich-text-translate)
|
|
175
180
|
- `--use-alternating-pages-dual`: Use alternating pages mode for dual PDF. When enabled, original and translated pages are arranged in alternate order. When disabled (default), original and translated pages are shown side by side on the same page.
|
|
176
181
|
- `--watermark-output-mode`: Control watermark output mode: 'watermarked' (default) adds watermark to translated PDF, 'no_watermark' doesn't add watermark, 'both' outputs both versions.
|
|
182
|
+
- `--max-pages-per-part`: Maximum number of pages per part for split translation. If not set, no splitting will be performed.
|
|
177
183
|
- `--no-watermark`: [DEPRECATED] Use --watermark-output-mode=no_watermark instead.
|
|
178
184
|
|
|
179
185
|
> [!TIP]
|
|
@@ -181,6 +187,7 @@ uv run babeldoc --files example.pdf --files example2.pdf --openai --openai-model
|
|
|
181
187
|
> - `--disable-rich-text-translate` can also help with compatibility by simplifying translation input
|
|
182
188
|
> - However, using `--skip-clean` will result in larger file sizes
|
|
183
189
|
> - If you encounter any compatibility issues, try using `--enhance-compatibility` first
|
|
190
|
+
> - Use `--max-pages-per-part` for large documents to split them into smaller parts for translation and automatically merge them back.
|
|
184
191
|
|
|
185
192
|
### Translation Service Options
|
|
186
193
|
|
|
@@ -236,26 +243,6 @@ uv run babeldoc --files example.pdf --files example2.pdf --openai --openai-model
|
|
|
236
243
|
|
|
237
244
|
Example Configuration:
|
|
238
245
|
|
|
239
|
-
```toml
|
|
240
|
-
[babeldoc]
|
|
241
|
-
debug = true
|
|
242
|
-
lang-in = "en-US"
|
|
243
|
-
lang-out = "zh-CN"
|
|
244
|
-
qps = 20
|
|
245
|
-
# this is a comment
|
|
246
|
-
# pages = 4
|
|
247
|
-
openai = true
|
|
248
|
-
openai-model = "SOME_ALSOME_MODEL"
|
|
249
|
-
openai-base-url = "https://example.example/v1"
|
|
250
|
-
openai-api-key = "[KEY]"
|
|
251
|
-
# Offline assets management
|
|
252
|
-
# generate-offline-assets = "/path/to/output/dir"
|
|
253
|
-
# restore-offline-assets = "/path/to/offline_assets_package.zip"
|
|
254
|
-
# All other options can also be set in the configuration file.
|
|
255
|
-
```
|
|
256
|
-
|
|
257
|
-
For a more comprehensive configuration example with offline assets management:
|
|
258
|
-
|
|
259
246
|
```toml
|
|
260
247
|
[babeldoc]
|
|
261
248
|
# Basic settings
|
|
@@ -265,12 +252,6 @@ lang-out = "zh-CN"
|
|
|
265
252
|
qps = 10
|
|
266
253
|
output = "/path/to/output/dir"
|
|
267
254
|
|
|
268
|
-
# Translation service
|
|
269
|
-
openai = true
|
|
270
|
-
openai-model = "gpt-4o-mini"
|
|
271
|
-
openai-base-url = "https://api.openai.com/v1"
|
|
272
|
-
openai-api-key = "your-api-key-here"
|
|
273
|
-
|
|
274
255
|
# PDF processing options
|
|
275
256
|
split-short-lines = false
|
|
276
257
|
short-line-split-factor = 0.8
|
|
@@ -279,8 +260,15 @@ dual-translate-first = false
|
|
|
279
260
|
disable-rich-text-translate = false
|
|
280
261
|
use-alternating-pages-dual = false
|
|
281
262
|
watermark-output-mode = "watermarked" # Choices: "watermarked", "no_watermark", "both"
|
|
263
|
+
max-pages-per-part = 50 # Automatically split the document for translation and merge it back.
|
|
282
264
|
# no-watermark = false # DEPRECATED: Use watermark-output-mode instead
|
|
283
265
|
|
|
266
|
+
# Translation service
|
|
267
|
+
openai = true
|
|
268
|
+
openai-model = "gpt-4o-mini"
|
|
269
|
+
openai-base-url = "https://api.openai.com/v1"
|
|
270
|
+
openai-api-key = "your-api-key-here"
|
|
271
|
+
|
|
284
272
|
# Output control
|
|
285
273
|
no-dual = false
|
|
286
274
|
no-mono = false
|
|
@@ -134,6 +134,7 @@ uv run babeldoc --files example.pdf --files example2.pdf --openai --openai-model
|
|
|
134
134
|
- `--enhance-compatibility`: Enable all compatibility enhancement options (equivalent to --skip-clean --dual-translate-first --disable-rich-text-translate)
|
|
135
135
|
- `--use-alternating-pages-dual`: Use alternating pages mode for dual PDF. When enabled, original and translated pages are arranged in alternate order. When disabled (default), original and translated pages are shown side by side on the same page.
|
|
136
136
|
- `--watermark-output-mode`: Control watermark output mode: 'watermarked' (default) adds watermark to translated PDF, 'no_watermark' doesn't add watermark, 'both' outputs both versions.
|
|
137
|
+
- `--max-pages-per-part`: Maximum number of pages per part for split translation. If not set, no splitting will be performed.
|
|
137
138
|
- `--no-watermark`: [DEPRECATED] Use --watermark-output-mode=no_watermark instead.
|
|
138
139
|
|
|
139
140
|
> [!TIP]
|
|
@@ -141,6 +142,7 @@ uv run babeldoc --files example.pdf --files example2.pdf --openai --openai-model
|
|
|
141
142
|
> - `--disable-rich-text-translate` can also help with compatibility by simplifying translation input
|
|
142
143
|
> - However, using `--skip-clean` will result in larger file sizes
|
|
143
144
|
> - If you encounter any compatibility issues, try using `--enhance-compatibility` first
|
|
145
|
+
> - Use `--max-pages-per-part` for large documents to split them into smaller parts for translation and automatically merge them back.
|
|
144
146
|
|
|
145
147
|
### Translation Service Options
|
|
146
148
|
|
|
@@ -196,26 +198,6 @@ uv run babeldoc --files example.pdf --files example2.pdf --openai --openai-model
|
|
|
196
198
|
|
|
197
199
|
Example Configuration:
|
|
198
200
|
|
|
199
|
-
```toml
|
|
200
|
-
[babeldoc]
|
|
201
|
-
debug = true
|
|
202
|
-
lang-in = "en-US"
|
|
203
|
-
lang-out = "zh-CN"
|
|
204
|
-
qps = 20
|
|
205
|
-
# this is a comment
|
|
206
|
-
# pages = 4
|
|
207
|
-
openai = true
|
|
208
|
-
openai-model = "SOME_ALSOME_MODEL"
|
|
209
|
-
openai-base-url = "https://example.example/v1"
|
|
210
|
-
openai-api-key = "[KEY]"
|
|
211
|
-
# Offline assets management
|
|
212
|
-
# generate-offline-assets = "/path/to/output/dir"
|
|
213
|
-
# restore-offline-assets = "/path/to/offline_assets_package.zip"
|
|
214
|
-
# All other options can also be set in the configuration file.
|
|
215
|
-
```
|
|
216
|
-
|
|
217
|
-
For a more comprehensive configuration example with offline assets management:
|
|
218
|
-
|
|
219
201
|
```toml
|
|
220
202
|
[babeldoc]
|
|
221
203
|
# Basic settings
|
|
@@ -225,12 +207,6 @@ lang-out = "zh-CN"
|
|
|
225
207
|
qps = 10
|
|
226
208
|
output = "/path/to/output/dir"
|
|
227
209
|
|
|
228
|
-
# Translation service
|
|
229
|
-
openai = true
|
|
230
|
-
openai-model = "gpt-4o-mini"
|
|
231
|
-
openai-base-url = "https://api.openai.com/v1"
|
|
232
|
-
openai-api-key = "your-api-key-here"
|
|
233
|
-
|
|
234
210
|
# PDF processing options
|
|
235
211
|
split-short-lines = false
|
|
236
212
|
short-line-split-factor = 0.8
|
|
@@ -239,8 +215,15 @@ dual-translate-first = false
|
|
|
239
215
|
disable-rich-text-translate = false
|
|
240
216
|
use-alternating-pages-dual = false
|
|
241
217
|
watermark-output-mode = "watermarked" # Choices: "watermarked", "no_watermark", "both"
|
|
218
|
+
max-pages-per-part = 50 # Automatically split the document for translation and merge it back.
|
|
242
219
|
# no-watermark = false # DEPRECATED: Use watermark-output-mode instead
|
|
243
220
|
|
|
221
|
+
# Translation service
|
|
222
|
+
openai = true
|
|
223
|
+
openai-model = "gpt-4o-mini"
|
|
224
|
+
openai-base-url = "https://api.openai.com/v1"
|
|
225
|
+
openai-api-key = "your-api-key-here"
|
|
226
|
+
|
|
244
227
|
# Output control
|
|
245
228
|
no-dual = false
|
|
246
229
|
no-mono = false
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.2.10"
|
|
@@ -552,7 +552,7 @@ class PDFCreater:
|
|
|
552
552
|
while process.is_alive():
|
|
553
553
|
if time.time() - start_time > timeout:
|
|
554
554
|
logger.warning(
|
|
555
|
-
f"PDF save with clean=
|
|
555
|
+
f"PDF save with clean={clean} timeout after {timeout} seconds, terminating subprocess"
|
|
556
556
|
)
|
|
557
557
|
process.terminate()
|
|
558
558
|
try:
|
|
@@ -569,7 +569,7 @@ class PDFCreater:
|
|
|
569
569
|
logger.error(f"Error terminating PDF save process: {e}")
|
|
570
570
|
|
|
571
571
|
# Fallback to save without clean parameter
|
|
572
|
-
logger.info("Falling back to save
|
|
572
|
+
logger.info("Falling back to save with clean=False")
|
|
573
573
|
try:
|
|
574
574
|
pdf.save(
|
|
575
575
|
output_path,
|
|
@@ -598,7 +598,7 @@ class PDFCreater:
|
|
|
598
598
|
and Path(temp_output).exists()
|
|
599
599
|
and Path(temp_output).stat().st_size > 0
|
|
600
600
|
):
|
|
601
|
-
logger.info("PDF save with clean=
|
|
601
|
+
logger.info(f"PDF save with clean={clean} completed successfully")
|
|
602
602
|
# Copy the successfully created file to the target path
|
|
603
603
|
try:
|
|
604
604
|
import shutil
|
|
@@ -614,7 +614,7 @@ class PDFCreater:
|
|
|
614
614
|
Path(temp_output).unlink()
|
|
615
615
|
else:
|
|
616
616
|
logger.warning(
|
|
617
|
-
f"PDF save with clean=
|
|
617
|
+
f"PDF save with clean={clean} failed with exit code {exit_code} or produced empty file"
|
|
618
618
|
)
|
|
619
619
|
# Fallback to save without clean parameter
|
|
620
620
|
try:
|
|
@@ -43,6 +43,9 @@ class ILTranslatorLLMOnly:
|
|
|
43
43
|
self.translate_engine = translate_engine
|
|
44
44
|
self.translation_config = translation_config
|
|
45
45
|
self.font_mapper = FontMapper(translation_config)
|
|
46
|
+
self.shared_context_cross_split_part = (
|
|
47
|
+
translation_config.shared_context_cross_split_part
|
|
48
|
+
)
|
|
46
49
|
|
|
47
50
|
self.il_translator = ILTranslator(
|
|
48
51
|
translate_engine=translate_engine,
|
|
@@ -73,8 +76,15 @@ class ILTranslatorLLMOnly:
|
|
|
73
76
|
def translate(self, docs: Document) -> None:
|
|
74
77
|
tracker = DocumentTranslateTracker()
|
|
75
78
|
|
|
76
|
-
|
|
77
|
-
|
|
79
|
+
if not self.translation_config.shared_context_cross_split_part.first_paragraph:
|
|
80
|
+
# Try to find the first title paragraph
|
|
81
|
+
title_paragraph = self.find_title_paragraph(docs)
|
|
82
|
+
self.translation_config.shared_context_cross_split_part.first_paragraph = (
|
|
83
|
+
title_paragraph
|
|
84
|
+
)
|
|
85
|
+
self.translation_config.shared_context_cross_split_part.recent_title_paragraph = title_paragraph
|
|
86
|
+
if title_paragraph:
|
|
87
|
+
logger.info(f"Found first title paragraph: {title_paragraph.unicode}")
|
|
78
88
|
|
|
79
89
|
# count total paragraph
|
|
80
90
|
total = sum(
|
|
@@ -105,7 +115,6 @@ class ILTranslatorLLMOnly:
|
|
|
105
115
|
executor,
|
|
106
116
|
pbar,
|
|
107
117
|
tracker.new_page(),
|
|
108
|
-
title_paragraph,
|
|
109
118
|
executor2,
|
|
110
119
|
)
|
|
111
120
|
|
|
@@ -122,7 +131,6 @@ class ILTranslatorLLMOnly:
|
|
|
122
131
|
executor: concurrent.futures.ThreadPoolExecutor,
|
|
123
132
|
pbar: tqdm | None = None,
|
|
124
133
|
tracker: PageTranslateTracker = None,
|
|
125
|
-
title_paragraph: PdfParagraph | None = None,
|
|
126
134
|
executor2: concurrent.futures.ThreadPoolExecutor | None = None,
|
|
127
135
|
):
|
|
128
136
|
self.translation_config.raise_if_cancelled()
|
|
@@ -136,7 +144,6 @@ class ILTranslatorLLMOnly:
|
|
|
136
144
|
page_xobj_font_map[xobj.xobj_id][font.font_id] = font
|
|
137
145
|
|
|
138
146
|
paragraphs = []
|
|
139
|
-
local_title_paragraph = None
|
|
140
147
|
|
|
141
148
|
total_unicode_counts = 0
|
|
142
149
|
for paragraph in page.pdf_paragraph:
|
|
@@ -146,7 +153,7 @@ class ILTranslatorLLMOnly:
|
|
|
146
153
|
total_unicode_counts += len(paragraph.unicode)
|
|
147
154
|
paragraphs.append(paragraph)
|
|
148
155
|
if paragraph.layout_label == "title":
|
|
149
|
-
|
|
156
|
+
self.shared_context_cross_split_part.recent_title_paragraph = paragraph
|
|
150
157
|
|
|
151
158
|
if total_unicode_counts > 1200 or len(paragraphs) > 4:
|
|
152
159
|
executor.submit(
|
|
@@ -155,8 +162,8 @@ class ILTranslatorLLMOnly:
|
|
|
155
162
|
pbar,
|
|
156
163
|
page_font_map,
|
|
157
164
|
page_xobj_font_map,
|
|
158
|
-
|
|
159
|
-
|
|
165
|
+
self.translation_config.shared_context_cross_split_part.first_paragraph,
|
|
166
|
+
self.translation_config.shared_context_cross_split_part.recent_title_paragraph,
|
|
160
167
|
executor2,
|
|
161
168
|
)
|
|
162
169
|
paragraphs = []
|
|
@@ -169,8 +176,8 @@ class ILTranslatorLLMOnly:
|
|
|
169
176
|
pbar,
|
|
170
177
|
page_font_map,
|
|
171
178
|
page_xobj_font_map,
|
|
172
|
-
|
|
173
|
-
|
|
179
|
+
self.translation_config.shared_context_cross_split_part.first_paragraph,
|
|
180
|
+
self.translation_config.shared_context_cross_split_part.recent_title_paragraph,
|
|
174
181
|
executor2,
|
|
175
182
|
)
|
|
176
183
|
|
|
@@ -172,10 +172,14 @@ class FontMapper:
|
|
|
172
172
|
|
|
173
173
|
font_id = {}
|
|
174
174
|
xreflen = doc_zh.xref_length()
|
|
175
|
+
total = xreflen - 1 + len(font_list) + len(il.page) + len(font_list)
|
|
175
176
|
with self.translation_config.progress_monitor.stage_start(
|
|
176
177
|
self.stage_name,
|
|
177
|
-
|
|
178
|
+
total,
|
|
178
179
|
) as pbar:
|
|
180
|
+
if not il.page:
|
|
181
|
+
pbar.advance(total)
|
|
182
|
+
return
|
|
179
183
|
for font in font_list:
|
|
180
184
|
if font[0] in font_id:
|
|
181
185
|
continue
|
|
@@ -2,6 +2,7 @@ import abc
|
|
|
2
2
|
import ast
|
|
3
3
|
import logging
|
|
4
4
|
import platform
|
|
5
|
+
import re
|
|
5
6
|
from collections.abc import Generator
|
|
6
7
|
|
|
7
8
|
import cv2
|
|
@@ -100,26 +101,6 @@ class YoloBox:
|
|
|
100
101
|
# 检测操作系统类型
|
|
101
102
|
os_name = platform.system()
|
|
102
103
|
|
|
103
|
-
providers = []
|
|
104
|
-
|
|
105
|
-
if os_name == "Darwin" and False: # Temporarily disable CoreML due to some issues
|
|
106
|
-
providers.append(
|
|
107
|
-
(
|
|
108
|
-
"CoreMLExecutionProvider",
|
|
109
|
-
{
|
|
110
|
-
"ModelFormat": "MLProgram",
|
|
111
|
-
"MLComputeUnits": "ALL",
|
|
112
|
-
"RequireStaticInputShapes": "0",
|
|
113
|
-
"EnableOnSubgraphs": "0",
|
|
114
|
-
},
|
|
115
|
-
),
|
|
116
|
-
)
|
|
117
|
-
# workaround for CoreML batch inference issues
|
|
118
|
-
max_batch_size = 1
|
|
119
|
-
else:
|
|
120
|
-
max_batch_size = 1
|
|
121
|
-
providers.append("CPUExecutionProvider") # CPU 执行提供者作为通用后备选项
|
|
122
|
-
|
|
123
104
|
|
|
124
105
|
class OnnxModel(DocLayoutModel):
|
|
125
106
|
def __init__(self, model_path: str):
|
|
@@ -129,7 +110,13 @@ class OnnxModel(DocLayoutModel):
|
|
|
129
110
|
metadata = {d.key: d.value for d in model.metadata_props}
|
|
130
111
|
self._stride = ast.literal_eval(metadata["stride"])
|
|
131
112
|
self._names = ast.literal_eval(metadata["names"])
|
|
113
|
+
providers = []
|
|
132
114
|
|
|
115
|
+
available_providers = onnxruntime.get_available_providers()
|
|
116
|
+
for provider in available_providers:
|
|
117
|
+
if re.match(r"dml|cuda|coreml|cpu", provider, re.IGNORECASE):
|
|
118
|
+
logger.info(f"Available Provider: {provider}")
|
|
119
|
+
providers.append(provider)
|
|
133
120
|
self.model = onnxruntime.InferenceSession(
|
|
134
121
|
model.SerializeToString(),
|
|
135
122
|
providers=providers,
|
|
@@ -237,7 +224,7 @@ class OnnxModel(DocLayoutModel):
|
|
|
237
224
|
|
|
238
225
|
total_images = len(image)
|
|
239
226
|
results = []
|
|
240
|
-
batch_size =
|
|
227
|
+
batch_size = 1
|
|
241
228
|
|
|
242
229
|
# Process images in batches
|
|
243
230
|
for i in range(0, total_images, batch_size):
|
|
@@ -246,7 +233,7 @@ class OnnxModel(DocLayoutModel):
|
|
|
246
233
|
|
|
247
234
|
# Calculate target size based on the maximum height in the batch
|
|
248
235
|
max_height = max(img.shape[0] for img in batch_images)
|
|
249
|
-
target_imgsz =
|
|
236
|
+
target_imgsz = 1024
|
|
250
237
|
|
|
251
238
|
# Preprocess batch
|
|
252
239
|
processed_batch = []
|