pdf2zh-next 2.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. pdf2zh_next/__init__.py +69 -0
  2. pdf2zh_next/config/__init__.py +55 -0
  3. pdf2zh_next/config/cli_env_model.py +96 -0
  4. pdf2zh_next/config/main.py +632 -0
  5. pdf2zh_next/config/model.py +306 -0
  6. pdf2zh_next/config/translate_engine_model.py +578 -0
  7. pdf2zh_next/const.py +16 -0
  8. pdf2zh_next/gui.py +1415 -0
  9. pdf2zh_next/high_level.py +621 -0
  10. pdf2zh_next/http_api.py +0 -0
  11. pdf2zh_next/main.py +104 -0
  12. pdf2zh_next/translator/__init__.py +13 -0
  13. pdf2zh_next/translator/base_rate_limiter.py +3 -0
  14. pdf2zh_next/translator/base_translator.py +188 -0
  15. pdf2zh_next/translator/cache.py +152 -0
  16. pdf2zh_next/translator/rate_limiter/qps_rate_limiter.py +38 -0
  17. pdf2zh_next/translator/translator_impl/anythingllm.py +55 -0
  18. pdf2zh_next/translator/translator_impl/azure.py +47 -0
  19. pdf2zh_next/translator/translator_impl/azureopenai.py +85 -0
  20. pdf2zh_next/translator/translator_impl/bing.py +66 -0
  21. pdf2zh_next/translator/translator_impl/deepl.py +41 -0
  22. pdf2zh_next/translator/translator_impl/dify.py +56 -0
  23. pdf2zh_next/translator/translator_impl/google.py +60 -0
  24. pdf2zh_next/translator/translator_impl/ollama.py +92 -0
  25. pdf2zh_next/translator/translator_impl/openai.py +90 -0
  26. pdf2zh_next/translator/translator_impl/qwenmt.py +114 -0
  27. pdf2zh_next/translator/translator_impl/siliconflow.py +89 -0
  28. pdf2zh_next/translator/translator_impl/tmt.py +50 -0
  29. pdf2zh_next/translator/translator_impl/xinference.py +88 -0
  30. pdf2zh_next/translator/utils.py +43 -0
  31. pdf2zh_next/utils/asynchronize/__init__.py +93 -0
  32. pdf2zh_next-2.0.0.dist-info/METADATA +218 -0
  33. pdf2zh_next-2.0.0.dist-info/RECORD +36 -0
  34. pdf2zh_next-2.0.0.dist-info/WHEEL +4 -0
  35. pdf2zh_next-2.0.0.dist-info/entry_points.txt +4 -0
  36. pdf2zh_next-2.0.0.dist-info/licenses/LICENSE +661 -0
@@ -0,0 +1,69 @@
1
+ from pdf2zh_next.config import AnythingLLMSettings
2
+ from pdf2zh_next.config import AzureOpenAISettings
3
+ from pdf2zh_next.config import AzureSettings
4
+ from pdf2zh_next.config import BingSettings
5
+ from pdf2zh_next.config import DeepLSettings
6
+ from pdf2zh_next.config import DeepSeekSettings
7
+ from pdf2zh_next.config import DifySettings
8
+ from pdf2zh_next.config import GeminiSettings
9
+ from pdf2zh_next.config import GoogleSettings
10
+ from pdf2zh_next.config import GrokSettings
11
+ from pdf2zh_next.config import GroqSettings
12
+ from pdf2zh_next.config import ModelScopeSettings
13
+ from pdf2zh_next.config import OllamaSettings
14
+ from pdf2zh_next.config import OpenAISettings
15
+ from pdf2zh_next.config import QwenMtSettings
16
+ from pdf2zh_next.config import SiliconFlowSettings
17
+ from pdf2zh_next.config import TencentSettings
18
+ from pdf2zh_next.config import XinferenceSettings
19
+ from pdf2zh_next.config import ZhipuSettings
20
+ from pdf2zh_next.config.main import ConfigManager
21
+ from pdf2zh_next.config.model import BasicSettings
22
+ from pdf2zh_next.config.model import PDFSettings
23
+ from pdf2zh_next.config.model import SettingsModel
24
+ from pdf2zh_next.config.model import TranslationSettings
25
+ from pdf2zh_next.config.model import WatermarkOutputMode
26
+ from pdf2zh_next.high_level import create_babeldoc_config
27
+ from pdf2zh_next.high_level import do_translate_async_stream
28
+ from pdf2zh_next.high_level import do_translate_file
29
+ from pdf2zh_next.high_level import do_translate_file_async
30
+
31
+ # from pdf2zh_next.high_level import translate, translate_stream
32
+
33
+ __version__ = "2.0.0"
34
+ __author__ = "Byaidu, awwaawwa"
35
+ __license__ = "AGPL-3.0"
36
+ __maintainer__ = "awwaawwa"
37
+ __email__ = "aw@funstory.ai"
38
+
39
+ __all__ = [
40
+ "SettingsModel",
41
+ "BasicSettings",
42
+ "OpenAISettings",
43
+ "BingSettings",
44
+ "GoogleSettings",
45
+ "DeepLSettings",
46
+ "DeepSeekSettings",
47
+ "OllamaSettings",
48
+ "XinferenceSettings",
49
+ "AzureOpenAISettings",
50
+ "ModelScopeSettings",
51
+ "ZhipuSettings",
52
+ "SiliconFlowSettings",
53
+ "TencentSettings",
54
+ "GeminiSettings",
55
+ "AzureSettings",
56
+ "AnythingLLMSettings",
57
+ "DifySettings",
58
+ "GrokSettings",
59
+ "GroqSettings",
60
+ "QwenMtSettings",
61
+ "PDFSettings",
62
+ "TranslationSettings",
63
+ "WatermarkOutputMode",
64
+ "do_translate_file_async",
65
+ "do_translate_file",
66
+ "do_translate_async_stream",
67
+ "create_babeldoc_config",
68
+ "ConfigManager",
69
+ ]
@@ -0,0 +1,55 @@
1
+ from pdf2zh_next.config.main import ConfigManager
2
+ from pdf2zh_next.config.model import BasicSettings
3
+ from pdf2zh_next.config.model import PDFSettings
4
+ from pdf2zh_next.config.model import SettingsModel
5
+ from pdf2zh_next.config.model import TranslationSettings
6
+ from pdf2zh_next.config.model import WatermarkOutputMode
7
+ from pdf2zh_next.config.translate_engine_model import TRANSLATION_ENGINE_METADATA
8
+ from pdf2zh_next.config.translate_engine_model import AnythingLLMSettings
9
+ from pdf2zh_next.config.translate_engine_model import AzureOpenAISettings
10
+ from pdf2zh_next.config.translate_engine_model import AzureSettings
11
+ from pdf2zh_next.config.translate_engine_model import BingSettings
12
+ from pdf2zh_next.config.translate_engine_model import DeepLSettings
13
+ from pdf2zh_next.config.translate_engine_model import DeepSeekSettings
14
+ from pdf2zh_next.config.translate_engine_model import DifySettings
15
+ from pdf2zh_next.config.translate_engine_model import GeminiSettings
16
+ from pdf2zh_next.config.translate_engine_model import GoogleSettings
17
+ from pdf2zh_next.config.translate_engine_model import GrokSettings
18
+ from pdf2zh_next.config.translate_engine_model import GroqSettings
19
+ from pdf2zh_next.config.translate_engine_model import ModelScopeSettings
20
+ from pdf2zh_next.config.translate_engine_model import OllamaSettings
21
+ from pdf2zh_next.config.translate_engine_model import OpenAISettings
22
+ from pdf2zh_next.config.translate_engine_model import QwenMtSettings
23
+ from pdf2zh_next.config.translate_engine_model import SiliconFlowSettings
24
+ from pdf2zh_next.config.translate_engine_model import TencentSettings
25
+ from pdf2zh_next.config.translate_engine_model import XinferenceSettings
26
+ from pdf2zh_next.config.translate_engine_model import ZhipuSettings
27
+
28
+ __all__ = [
29
+ "ConfigManager",
30
+ "SettingsModel",
31
+ "BasicSettings",
32
+ "TranslationSettings",
33
+ "PDFSettings",
34
+ "WatermarkOutputMode",
35
+ "BingSettings",
36
+ "GoogleSettings",
37
+ "OpenAISettings",
38
+ "DeepLSettings",
39
+ "OllamaSettings",
40
+ "XinferenceSettings",
41
+ "AzureOpenAISettings",
42
+ "ModelScopeSettings",
43
+ "ZhipuSettings",
44
+ "SiliconFlowSettings",
45
+ "TencentSettings",
46
+ "GeminiSettings",
47
+ "AzureSettings",
48
+ "AnythingLLMSettings",
49
+ "DifySettings",
50
+ "GrokSettings",
51
+ "GroqSettings",
52
+ "QwenMtSettings",
53
+ "DeepSeekSettings",
54
+ "TRANSLATION_ENGINE_METADATA",
55
+ ]
@@ -0,0 +1,96 @@
1
+ from __future__ import annotations
2
+
3
+ import logging
4
+
5
+ from pydantic import Field
6
+ from pydantic import create_model
7
+
8
+ from pdf2zh_next.config.model import SettingsModel
9
+ from pdf2zh_next.config.translate_engine_model import _DEFAULT_TRANSLATION_ENGINE
10
+ from pdf2zh_next.config.translate_engine_model import TRANSLATION_ENGINE_METADATA
11
+
12
+ logger = logging.getLogger(__name__)
13
+
14
+ # The following is magic code,
15
+ # if you need to modify it,
16
+ # please contact the maintainer!
17
+
18
+ __translation_flag_fields = {
19
+ x.cli_flag_name: (
20
+ bool,
21
+ Field(
22
+ default=False, description=f"Use {x.translate_engine_type} for translation"
23
+ ),
24
+ )
25
+ for x in TRANSLATION_ENGINE_METADATA
26
+ }
27
+
28
+ __translation_flag_fields.update(
29
+ {
30
+ x.cli_detail_field_name: (
31
+ x.setting_model_type,
32
+ Field(default_factory=x.setting_model_type),
33
+ )
34
+ for x in TRANSLATION_ENGINE_METADATA
35
+ if x.cli_detail_field_name
36
+ }
37
+ )
38
+
39
+ __exclude_fields = list(__translation_flag_fields.keys())
40
+
41
+ # If you want to use more field parameters in `pdf2zh_next/config/model.py`
42
+ # please add the corresponding forwarding here!
43
+
44
+ __cli_env_settings_model_fields = {
45
+ k: (
46
+ v.annotation,
47
+ Field(
48
+ default=v.default,
49
+ description=v.description,
50
+ default_factory=v.default_factory,
51
+ alias=v.alias,
52
+ discriminator=v.discriminator,
53
+ ),
54
+ )
55
+ for k, v in SettingsModel.model_fields.items()
56
+ if k != "translate_engine_settings"
57
+ }
58
+ __cli_env_settings_model_fields.update(__translation_flag_fields)
59
+
60
+ CLIEnvSettingsModel = create_model(
61
+ "CLIEnvSettingsModel",
62
+ **__cli_env_settings_model_fields,
63
+ )
64
+
65
+
66
+ def to_settings_model(self) -> SettingsModel:
67
+ for metadata in TRANSLATION_ENGINE_METADATA:
68
+ if getattr(self, metadata.cli_flag_name):
69
+ if metadata.cli_detail_field_name:
70
+ translate_engine_settings = metadata.setting_model_type(
71
+ **getattr(self, metadata.cli_detail_field_name).model_dump()
72
+ )
73
+ else:
74
+ translate_engine_settings = metadata.setting_model_type()
75
+ break
76
+ else:
77
+ logger.warning("No translation engine selected, using Bing")
78
+ translate_engine_settings = _DEFAULT_TRANSLATION_ENGINE()
79
+
80
+ return SettingsModel(
81
+ **self.model_dump(exclude=__exclude_fields),
82
+ translate_engine_settings=translate_engine_settings,
83
+ )
84
+
85
+
86
+ def validate_settings(self) -> None:
87
+ self.to_settings_model().validate_settings()
88
+
89
+
90
+ def clone(self):
91
+ return self.model_copy(deep=True)
92
+
93
+
94
+ CLIEnvSettingsModel.to_settings_model = to_settings_model
95
+ CLIEnvSettingsModel.validate_settings = validate_settings
96
+ CLIEnvSettingsModel.clone = clone