BabelDOC 0.1.14__tar.gz → 0.1.15__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.
Files changed (77) hide show
  1. {babeldoc-0.1.14 → babeldoc-0.1.15}/PKG-INFO +2 -1
  2. babeldoc-0.1.15/babeldoc/__init__.py +1 -0
  3. {babeldoc-0.1.14 → babeldoc-0.1.15}/babeldoc/const.py +1 -1
  4. {babeldoc-0.1.14 → babeldoc-0.1.15}/babeldoc/docvision/rpc_doclayout.py +56 -45
  5. {babeldoc-0.1.14 → babeldoc-0.1.15}/babeldoc/main.py +1 -1
  6. {babeldoc-0.1.14 → babeldoc-0.1.15}/pyproject.toml +4 -3
  7. {babeldoc-0.1.14 → babeldoc-0.1.15}/uv.lock +12 -1
  8. babeldoc-0.1.14/babeldoc/__init__.py +0 -1
  9. {babeldoc-0.1.14 → babeldoc-0.1.15}/.cursorignore +0 -0
  10. {babeldoc-0.1.14 → babeldoc-0.1.15}/.github/ISSUE_TEMPLATE/bug_report.yaml +0 -0
  11. {babeldoc-0.1.14 → babeldoc-0.1.15}/.github/ISSUE_TEMPLATE/feature_request.yaml +0 -0
  12. {babeldoc-0.1.14 → babeldoc-0.1.15}/.github/dependabot.yml +0 -0
  13. {babeldoc-0.1.14 → babeldoc-0.1.15}/.github/labels.yml +0 -0
  14. {babeldoc-0.1.14 → babeldoc-0.1.15}/.github/release-drafter.yml +0 -0
  15. {babeldoc-0.1.14 → babeldoc-0.1.15}/.github/workflows/codeql.yml +0 -0
  16. {babeldoc-0.1.14 → babeldoc-0.1.15}/.github/workflows/docs.yml +0 -0
  17. {babeldoc-0.1.14 → babeldoc-0.1.15}/.github/workflows/labeler.yml +0 -0
  18. {babeldoc-0.1.14 → babeldoc-0.1.15}/.github/workflows/publish-to-pypi.yml +0 -0
  19. {babeldoc-0.1.14 → babeldoc-0.1.15}/.github/workflows/test.yml +0 -0
  20. {babeldoc-0.1.14 → babeldoc-0.1.15}/.gitignore +0 -0
  21. {babeldoc-0.1.14 → babeldoc-0.1.15}/.pre-commit-config.yaml +0 -0
  22. {babeldoc-0.1.14 → babeldoc-0.1.15}/LICENSE +0 -0
  23. {babeldoc-0.1.14 → babeldoc-0.1.15}/README.md +0 -0
  24. {babeldoc-0.1.14 → babeldoc-0.1.15}/babeldoc/asynchronize/__init__.py +0 -0
  25. {babeldoc-0.1.14 → babeldoc-0.1.15}/babeldoc/converter.py +0 -0
  26. {babeldoc-0.1.14 → babeldoc-0.1.15}/babeldoc/document_il/__init__.py +0 -0
  27. {babeldoc-0.1.14 → babeldoc-0.1.15}/babeldoc/document_il/backend/__init__.py +0 -0
  28. {babeldoc-0.1.14 → babeldoc-0.1.15}/babeldoc/document_il/backend/pdf_creater.py +0 -0
  29. {babeldoc-0.1.14 → babeldoc-0.1.15}/babeldoc/document_il/frontend/__init__.py +0 -0
  30. {babeldoc-0.1.14 → babeldoc-0.1.15}/babeldoc/document_il/frontend/il_creater.py +0 -0
  31. {babeldoc-0.1.14 → babeldoc-0.1.15}/babeldoc/document_il/il_version_1.py +0 -0
  32. {babeldoc-0.1.14 → babeldoc-0.1.15}/babeldoc/document_il/il_version_1.rnc +0 -0
  33. {babeldoc-0.1.14 → babeldoc-0.1.15}/babeldoc/document_il/il_version_1.rng +0 -0
  34. {babeldoc-0.1.14 → babeldoc-0.1.15}/babeldoc/document_il/il_version_1.xsd +0 -0
  35. {babeldoc-0.1.14 → babeldoc-0.1.15}/babeldoc/document_il/midend/__init__.py +0 -0
  36. {babeldoc-0.1.14 → babeldoc-0.1.15}/babeldoc/document_il/midend/add_debug_information.py +0 -0
  37. {babeldoc-0.1.14 → babeldoc-0.1.15}/babeldoc/document_il/midend/il_translator.py +0 -0
  38. {babeldoc-0.1.14 → babeldoc-0.1.15}/babeldoc/document_il/midend/layout_parser.py +0 -0
  39. {babeldoc-0.1.14 → babeldoc-0.1.15}/babeldoc/document_il/midend/paragraph_finder.py +0 -0
  40. {babeldoc-0.1.14 → babeldoc-0.1.15}/babeldoc/document_il/midend/remove_descent.py +0 -0
  41. {babeldoc-0.1.14 → babeldoc-0.1.15}/babeldoc/document_il/midend/styles_and_formulas.py +0 -0
  42. {babeldoc-0.1.14 → babeldoc-0.1.15}/babeldoc/document_il/midend/typesetting.py +0 -0
  43. {babeldoc-0.1.14 → babeldoc-0.1.15}/babeldoc/document_il/translator/__init__.py +0 -0
  44. {babeldoc-0.1.14 → babeldoc-0.1.15}/babeldoc/document_il/translator/cache.py +0 -0
  45. {babeldoc-0.1.14 → babeldoc-0.1.15}/babeldoc/document_il/translator/translator.py +0 -0
  46. {babeldoc-0.1.14 → babeldoc-0.1.15}/babeldoc/document_il/utils/fontmap.py +0 -0
  47. {babeldoc-0.1.14 → babeldoc-0.1.15}/babeldoc/document_il/utils/layout_helper.py +0 -0
  48. {babeldoc-0.1.14 → babeldoc-0.1.15}/babeldoc/document_il/utils/style_helper.py +0 -0
  49. {babeldoc-0.1.14 → babeldoc-0.1.15}/babeldoc/document_il/xml_converter.py +0 -0
  50. {babeldoc-0.1.14 → babeldoc-0.1.15}/babeldoc/docvision/README.md +0 -0
  51. {babeldoc-0.1.14 → babeldoc-0.1.15}/babeldoc/docvision/__init__.py +0 -0
  52. {babeldoc-0.1.14 → babeldoc-0.1.15}/babeldoc/docvision/doclayout.py +0 -0
  53. {babeldoc-0.1.14 → babeldoc-0.1.15}/babeldoc/high_level.py +0 -0
  54. {babeldoc-0.1.14 → babeldoc-0.1.15}/babeldoc/pdfinterp.py +0 -0
  55. {babeldoc-0.1.14 → babeldoc-0.1.15}/babeldoc/progress_monitor.py +0 -0
  56. {babeldoc-0.1.14 → babeldoc-0.1.15}/babeldoc/translation_config.py +0 -0
  57. {babeldoc-0.1.14 → babeldoc-0.1.15}/docs/CODE_OF_CONDUCT.md +0 -0
  58. {babeldoc-0.1.14 → babeldoc-0.1.15}/docs/CONTRIBUTING.md +0 -0
  59. {babeldoc-0.1.14 → babeldoc-0.1.15}/docs/CONTRIBUTOR_REWARD.md +0 -0
  60. {babeldoc-0.1.14 → babeldoc-0.1.15}/docs/ImplementationDetails/AsyncTranslate/AsyncTranslate.md +0 -0
  61. {babeldoc-0.1.14 → babeldoc-0.1.15}/docs/ImplementationDetails/ILTranslator/ILTranslator.md +0 -0
  62. {babeldoc-0.1.14 → babeldoc-0.1.15}/docs/ImplementationDetails/PDFCreation/PDFCreation.md +0 -0
  63. {babeldoc-0.1.14 → babeldoc-0.1.15}/docs/ImplementationDetails/PDFParsing/PDFParsing.md +0 -0
  64. {babeldoc-0.1.14 → babeldoc-0.1.15}/docs/ImplementationDetails/ParagraphFinding/ParagraphFinding.md +0 -0
  65. {babeldoc-0.1.14 → babeldoc-0.1.15}/docs/ImplementationDetails/README.md +0 -0
  66. {babeldoc-0.1.14 → babeldoc-0.1.15}/docs/ImplementationDetails/StylesAndFormulas/StylesAndFormulas.md +0 -0
  67. {babeldoc-0.1.14 → babeldoc-0.1.15}/docs/ImplementationDetails/Typesetting/Typesetting.md +0 -0
  68. {babeldoc-0.1.14 → babeldoc-0.1.15}/docs/README.md +0 -0
  69. {babeldoc-0.1.14 → babeldoc-0.1.15}/docs/deploy.sh +0 -0
  70. {babeldoc-0.1.14 → babeldoc-0.1.15}/docs/images/babeldoc-banner.png +0 -0
  71. {babeldoc-0.1.14 → babeldoc-0.1.15}/docs/images/babeldoc-contributor_reward_example.png +0 -0
  72. {babeldoc-0.1.14 → babeldoc-0.1.15}/docs/images/babeldoc-preview.gif +0 -0
  73. {babeldoc-0.1.14 → babeldoc-0.1.15}/docs/index.md +0 -0
  74. {babeldoc-0.1.14 → babeldoc-0.1.15}/docs/intro-to-pdf-object.md +0 -0
  75. {babeldoc-0.1.14 → babeldoc-0.1.15}/docs/requirements.txt +0 -0
  76. {babeldoc-0.1.14 → babeldoc-0.1.15}/mkdocs.yml +0 -0
  77. {babeldoc-0.1.14 → babeldoc-0.1.15}/tests/test_translation_config.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: BabelDOC
3
- Version: 0.1.14
3
+ Version: 0.1.15
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: peewee>=3.17.8
26
26
  Requires-Dist: pydantic>=2.10.6
27
27
  Requires-Dist: pymupdf>=1.25.1
28
28
  Requires-Dist: rich>=13.9.4
29
+ Requires-Dist: tenacity>=9.0.0
29
30
  Requires-Dist: toml>=0.10.2
30
31
  Requires-Dist: tqdm>=4.67.1
31
32
  Requires-Dist: xsdata[cli,lxml,soap]>=24.12
@@ -0,0 +1 @@
1
+ __version__ = "0.1.15"
@@ -2,7 +2,7 @@ import shutil
2
2
  import subprocess
3
3
  from pathlib import Path
4
4
 
5
- __version__ = "0.1.14"
5
+ __version__ = "0.1.15"
6
6
 
7
7
  CACHE_FOLDER = Path.home() / ".cache" / "babeldoc"
8
8
 
@@ -5,6 +5,10 @@ import cv2
5
5
  import httpx
6
6
  import msgpack
7
7
  import numpy as np
8
+ from tenacity import retry
9
+ from tenacity import retry_if_exception_type
10
+ from tenacity import stop_after_attempt
11
+ from tenacity import wait_exponential
8
12
 
9
13
  from babeldoc.docvision.doclayout import DocLayoutModel
10
14
  from babeldoc.docvision.doclayout import YoloBox
@@ -34,6 +38,17 @@ def encode_image(image) -> bytes:
34
38
  return encoded
35
39
 
36
40
 
41
+ @retry(
42
+ stop=stop_after_attempt(3), # 最多重试3次
43
+ wait=wait_exponential(
44
+ multiplier=1, min=1, max=10
45
+ ), # 指数退避策略,初始1秒,最大10秒
46
+ retry=retry_if_exception_type((httpx.HTTPError, Exception)), # 针对哪些异常重试
47
+ before_sleep=lambda retry_state: logger.warning(
48
+ f"Request failed, retrying in {retry_state.next_action.sleep} seconds... "
49
+ f"(Attempt {retry_state.attempt_number}/3)"
50
+ ),
51
+ )
37
52
  def predict_layout(
38
53
  image,
39
54
  host: str = "http://localhost:8000",
@@ -50,53 +65,49 @@ def predict_layout(
50
65
  Returns:
51
66
  List of predictions containing bounding boxes and classes
52
67
  """
53
- try:
54
- # Prepare request data
55
- if not isinstance(image, list):
56
- image = [image]
57
- image_data = [encode_image(image) for image in image]
58
- data = {
59
- "image": image_data,
60
- "imgsz": imgsz,
61
- }
62
-
63
- # Pack data using msgpack
64
- packed_data = msgpack.packb(data, use_bin_type=True)
65
- logger.debug(f"Packed data size: {len(packed_data)} bytes")
66
-
67
- # Send request
68
- logger.debug(f"Sending request to {host}/inference")
69
- response = httpx.post(
70
- f"{host}/inference",
71
- data=packed_data,
72
- headers={
73
- "Content-Type": "application/msgpack",
74
- "Accept": "application/msgpack",
75
- },
76
- timeout=300,
77
- follow_redirects=True,
68
+ # Prepare request data
69
+ if not isinstance(image, list):
70
+ image = [image]
71
+ image_data = [encode_image(image) for image in image]
72
+ data = {
73
+ "image": image_data,
74
+ "imgsz": imgsz,
75
+ }
76
+
77
+ # Pack data using msgpack
78
+ packed_data = msgpack.packb(data, use_bin_type=True)
79
+ logger.debug(f"Packed data size: {len(packed_data)} bytes")
80
+
81
+ # Send request
82
+ logger.debug(f"Sending request to {host}/inference")
83
+ response = httpx.post(
84
+ f"{host}/inference",
85
+ data=packed_data,
86
+ headers={
87
+ "Content-Type": "application/msgpack",
88
+ "Accept": "application/msgpack",
89
+ },
90
+ timeout=300,
91
+ follow_redirects=True,
92
+ )
93
+
94
+ logger.debug(f"Response status: {response.status_code}")
95
+ logger.debug(f"Response headers: {response.headers}")
96
+
97
+ if response.status_code == 200:
98
+ try:
99
+ result = msgpack.unpackb(response.content, raw=False)
100
+ return result
101
+ except Exception as e:
102
+ logger.exception(f"Failed to unpack response: {e!s}")
103
+ raise
104
+ else:
105
+ logger.error(f"Request failed with status {response.status_code}")
106
+ logger.error(f"Response content: {response.content}")
107
+ raise Exception(
108
+ f"Request failed with status {response.status_code}: {response.text}",
78
109
  )
79
110
 
80
- logger.debug(f"Response status: {response.status_code}")
81
- logger.debug(f"Response headers: {response.headers}")
82
-
83
- if response.status_code == 200:
84
- try:
85
- result = msgpack.unpackb(response.content, raw=False)
86
- return result
87
- except Exception as e:
88
- logger.exception(f"Failed to unpack response: {e!s}")
89
- raise
90
- else:
91
- logger.error(f"Request failed with status {response.status_code}")
92
- logger.error(f"Response content: {response.content}")
93
- raise Exception(
94
- f"Request failed with status {response.status_code}: {response.text}",
95
- )
96
- except Exception as e:
97
- logger.exception(f"Unexpected error: {e!s}")
98
- raise
99
-
100
111
 
101
112
  class RpcDocLayoutModel(DocLayoutModel):
102
113
  """DocLayoutModel implementation that uses RPC service."""
@@ -23,7 +23,7 @@ from babeldoc.docvision.rpc_doclayout import RpcDocLayoutModel
23
23
  from babeldoc.translation_config import TranslationConfig
24
24
 
25
25
  logger = logging.getLogger(__name__)
26
- __version__ = "0.1.14"
26
+ __version__ = "0.1.15"
27
27
 
28
28
 
29
29
  def create_parser():
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "BabelDOC"
3
- version = "0.1.14"
3
+ version = "0.1.15"
4
4
  description = "Yet Another Document Translator"
5
5
  license = "AGPL-3.0"
6
6
  readme = "README.md"
@@ -30,6 +30,7 @@ dependencies = [
30
30
  "xsdata[cli,lxml,soap]>=24.12",
31
31
  "msgpack>=1.1.0",
32
32
  "pydantic>=2.10.6",
33
+ "tenacity>=9.0.0",
33
34
  ]
34
35
 
35
36
  [project.urls]
@@ -131,7 +132,7 @@ pythonpath = [".", "src"]
131
132
  testpaths = ["tests"]
132
133
 
133
134
  [bumpver]
134
- current_version = "0.1.14"
135
+ current_version = "0.1.15"
135
136
  version_pattern = "MAJOR.MINOR.PATCH[.PYTAGNUM]"
136
137
 
137
138
  [bumpver.file_patterns]
@@ -147,4 +148,4 @@ version_pattern = "MAJOR.MINOR.PATCH[.PYTAGNUM]"
147
148
  ]
148
149
  "babeldoc/const.py" = [
149
150
  '__version__ = "{version}"'
150
- ]
151
+ ]
@@ -48,7 +48,7 @@ wheels = [
48
48
 
49
49
  [[package]]
50
50
  name = "babeldoc"
51
- version = "0.1.14"
51
+ version = "0.1.15"
52
52
  source = { editable = "." }
53
53
  dependencies = [
54
54
  { name = "bitstring" },
@@ -67,6 +67,7 @@ dependencies = [
67
67
  { name = "pydantic" },
68
68
  { name = "pymupdf" },
69
69
  { name = "rich" },
70
+ { name = "tenacity" },
70
71
  { name = "toml" },
71
72
  { name = "tqdm" },
72
73
  { name = "xsdata", extra = ["cli", "lxml", "soap"] },
@@ -105,6 +106,7 @@ requires-dist = [
105
106
  { name = "pydantic", specifier = ">=2.10.6" },
106
107
  { name = "pymupdf", specifier = ">=1.25.1" },
107
108
  { name = "rich", specifier = ">=13.9.4" },
109
+ { name = "tenacity", specifier = ">=9.0.0" },
108
110
  { name = "toml", specifier = ">=0.10.2" },
109
111
  { name = "tqdm", specifier = ">=4.67.1" },
110
112
  { name = "xsdata", extras = ["cli", "lxml", "soap"], specifier = ">=24.12" },
@@ -1753,6 +1755,15 @@ wheels = [
1753
1755
  { url = "https://files.pythonhosted.org/packages/99/ff/c87e0622b1dadea79d2fb0b25ade9ed98954c9033722eb707053d310d4f3/sympy-1.13.3-py3-none-any.whl", hash = "sha256:54612cf55a62755ee71824ce692986f23c88ffa77207b30c1368eda4a7060f73", size = 6189483 },
1754
1756
  ]
1755
1757
 
1758
+ [[package]]
1759
+ name = "tenacity"
1760
+ version = "9.0.0"
1761
+ source = { registry = "https://pypi.org/simple" }
1762
+ sdist = { url = "https://files.pythonhosted.org/packages/cd/94/91fccdb4b8110642462e653d5dcb27e7b674742ad68efd146367da7bdb10/tenacity-9.0.0.tar.gz", hash = "sha256:807f37ca97d62aa361264d497b0e31e92b8027044942bfa756160d908320d73b", size = 47421 }
1763
+ wheels = [
1764
+ { url = "https://files.pythonhosted.org/packages/b6/cb/b86984bed139586d01532a587464b5805f12e397594f19f931c4c2fbfa61/tenacity-9.0.0-py3-none-any.whl", hash = "sha256:93de0c98785b27fcf659856aa9f54bfbd399e29969b0621bc7f762bd441b4539", size = 28169 },
1765
+ ]
1766
+
1756
1767
  [[package]]
1757
1768
  name = "toml"
1758
1769
  version = "0.10.2"
@@ -1 +0,0 @@
1
- __version__ = "0.1.14"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes