paddlex 3.0.2__py3-none-any.whl → 3.1.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 (134) hide show
  1. paddlex/.version +1 -1
  2. paddlex/configs/modules/text_recognition/eslav_PP-OCRv5_mobile_rec.yaml +39 -0
  3. paddlex/configs/modules/text_recognition/korean_PP-OCRv5_mobile_rec.yaml +39 -0
  4. paddlex/configs/modules/text_recognition/latin_PP-OCRv5_mobile_rec.yaml +39 -0
  5. paddlex/configs/pipelines/PP-DocTranslation.yaml +261 -0
  6. paddlex/inference/common/batch_sampler/__init__.py +1 -0
  7. paddlex/inference/common/batch_sampler/markdown_batch_sampler.py +116 -0
  8. paddlex/inference/common/result/base_cv_result.py +2 -3
  9. paddlex/inference/common/result/mixin.py +3 -1
  10. paddlex/inference/models/base/predictor/base_predictor.py +2 -0
  11. paddlex/inference/models/common/static_infer.py +2 -0
  12. paddlex/inference/models/common/vlm/generation/utils.py +2 -2
  13. paddlex/inference/models/formula_recognition/result.py +2 -2
  14. paddlex/inference/models/image_classification/result.py +3 -5
  15. paddlex/inference/models/image_multilabel_classification/result.py +2 -2
  16. paddlex/inference/models/object_detection/result.py +2 -2
  17. paddlex/inference/models/open_vocabulary_detection/processors/groundingdino_processors.py +3 -0
  18. paddlex/inference/models/text_recognition/predictor.py +51 -1
  19. paddlex/inference/models/text_recognition/result.py +5 -2
  20. paddlex/inference/models/video_classification/result.py +3 -3
  21. paddlex/inference/models/video_detection/result.py +2 -4
  22. paddlex/inference/pipelines/__init__.py +1 -0
  23. paddlex/inference/pipelines/attribute_recognition/result.py +2 -2
  24. paddlex/inference/pipelines/components/prompt_engineering/__init__.py +1 -0
  25. paddlex/inference/pipelines/components/prompt_engineering/generate_translate_prompt.py +179 -0
  26. paddlex/inference/pipelines/doc_preprocessor/result.py +2 -2
  27. paddlex/inference/pipelines/formula_recognition/result.py +2 -2
  28. paddlex/inference/pipelines/layout_parsing/pipeline_v2.py +2 -0
  29. paddlex/inference/pipelines/layout_parsing/result_v2.py +11 -4
  30. paddlex/inference/pipelines/ocr/pipeline.py +2 -0
  31. paddlex/inference/pipelines/ocr/result.py +11 -7
  32. paddlex/inference/pipelines/pp_doctranslation/__init__.py +15 -0
  33. paddlex/inference/pipelines/pp_doctranslation/pipeline.py +523 -0
  34. paddlex/inference/pipelines/pp_doctranslation/result.py +39 -0
  35. paddlex/inference/pipelines/pp_doctranslation/utils.py +260 -0
  36. paddlex/inference/pipelines/pp_shitu_v2/result.py +2 -2
  37. paddlex/inference/serving/basic_serving/_app.py +1 -0
  38. paddlex/inference/serving/basic_serving/_pipeline_apps/anomaly_detection.py +4 -2
  39. paddlex/inference/serving/basic_serving/_pipeline_apps/doc_preprocessor.py +5 -1
  40. paddlex/inference/serving/basic_serving/_pipeline_apps/face_recognition.py +4 -2
  41. paddlex/inference/serving/basic_serving/_pipeline_apps/formula_recognition.py +4 -2
  42. paddlex/inference/serving/basic_serving/_pipeline_apps/human_keypoint_detection.py +4 -2
  43. paddlex/inference/serving/basic_serving/_pipeline_apps/image_classification.py +4 -2
  44. paddlex/inference/serving/basic_serving/_pipeline_apps/image_multilabel_classification.py +4 -2
  45. paddlex/inference/serving/basic_serving/_pipeline_apps/instance_segmentation.py +4 -2
  46. paddlex/inference/serving/basic_serving/_pipeline_apps/layout_parsing.py +4 -2
  47. paddlex/inference/serving/basic_serving/_pipeline_apps/object_detection.py +4 -2
  48. paddlex/inference/serving/basic_serving/_pipeline_apps/ocr.py +4 -2
  49. paddlex/inference/serving/basic_serving/_pipeline_apps/open_vocabulary_detection.py +4 -2
  50. paddlex/inference/serving/basic_serving/_pipeline_apps/open_vocabulary_segmentation.py +4 -2
  51. paddlex/inference/serving/basic_serving/_pipeline_apps/pedestrian_attribute_recognition.py +4 -2
  52. paddlex/inference/serving/basic_serving/_pipeline_apps/pp_chatocrv3_doc.py +14 -24
  53. paddlex/inference/serving/basic_serving/_pipeline_apps/pp_chatocrv4_doc.py +16 -26
  54. paddlex/inference/serving/basic_serving/_pipeline_apps/pp_doctranslation.py +203 -0
  55. paddlex/inference/serving/basic_serving/_pipeline_apps/pp_shituv2.py +4 -2
  56. paddlex/inference/serving/basic_serving/_pipeline_apps/pp_structurev3.py +4 -2
  57. paddlex/inference/serving/basic_serving/_pipeline_apps/rotated_object_detection.py +4 -2
  58. paddlex/inference/serving/basic_serving/_pipeline_apps/seal_recognition.py +4 -2
  59. paddlex/inference/serving/basic_serving/_pipeline_apps/semantic_segmentation.py +4 -2
  60. paddlex/inference/serving/basic_serving/_pipeline_apps/small_object_detection.py +4 -2
  61. paddlex/inference/serving/basic_serving/_pipeline_apps/table_recognition.py +4 -2
  62. paddlex/inference/serving/basic_serving/_pipeline_apps/table_recognition_v2.py +4 -2
  63. paddlex/inference/serving/basic_serving/_pipeline_apps/ts_anomaly_detection.py +4 -2
  64. paddlex/inference/serving/basic_serving/_pipeline_apps/ts_classification.py +4 -2
  65. paddlex/inference/serving/basic_serving/_pipeline_apps/ts_forecast.py +4 -2
  66. paddlex/inference/serving/basic_serving/_pipeline_apps/vehicle_attribute_recognition.py +4 -2
  67. paddlex/inference/serving/infra/utils.py +22 -17
  68. paddlex/inference/serving/schemas/anomaly_detection.py +1 -0
  69. paddlex/inference/serving/schemas/doc_preprocessor.py +1 -0
  70. paddlex/inference/serving/schemas/face_recognition.py +1 -0
  71. paddlex/inference/serving/schemas/formula_recognition.py +1 -0
  72. paddlex/inference/serving/schemas/human_keypoint_detection.py +1 -0
  73. paddlex/inference/serving/schemas/image_classification.py +1 -0
  74. paddlex/inference/serving/schemas/image_multilabel_classification.py +1 -0
  75. paddlex/inference/serving/schemas/instance_segmentation.py +1 -0
  76. paddlex/inference/serving/schemas/layout_parsing.py +1 -0
  77. paddlex/inference/serving/schemas/object_detection.py +1 -0
  78. paddlex/inference/serving/schemas/ocr.py +1 -0
  79. paddlex/inference/serving/schemas/open_vocabulary_detection.py +1 -0
  80. paddlex/inference/serving/schemas/open_vocabulary_segmentation.py +1 -0
  81. paddlex/inference/serving/schemas/pedestrian_attribute_recognition.py +1 -0
  82. paddlex/inference/serving/schemas/pp_chatocrv3_doc.py +5 -4
  83. paddlex/inference/serving/schemas/pp_chatocrv4_doc.py +6 -5
  84. paddlex/inference/serving/schemas/pp_doctranslation.py +115 -0
  85. paddlex/inference/serving/schemas/pp_shituv2.py +1 -0
  86. paddlex/inference/serving/schemas/pp_structurev3.py +2 -9
  87. paddlex/inference/serving/schemas/rotated_object_detection.py +1 -0
  88. paddlex/inference/serving/schemas/seal_recognition.py +1 -0
  89. paddlex/inference/serving/schemas/semantic_segmentation.py +1 -0
  90. paddlex/inference/serving/schemas/shared/ocr.py +8 -1
  91. paddlex/inference/serving/schemas/small_object_detection.py +1 -0
  92. paddlex/inference/serving/schemas/table_recognition.py +1 -0
  93. paddlex/inference/serving/schemas/table_recognition_v2.py +1 -0
  94. paddlex/inference/serving/schemas/ts_anomaly_detection.py +1 -0
  95. paddlex/inference/serving/schemas/ts_classification.py +1 -0
  96. paddlex/inference/serving/schemas/ts_forecast.py +1 -0
  97. paddlex/inference/serving/schemas/vehicle_attribute_recognition.py +1 -0
  98. paddlex/inference/utils/hpi.py +42 -14
  99. paddlex/inference/utils/hpi_model_info_collection.json +0 -2
  100. paddlex/inference/utils/io/__init__.py +1 -0
  101. paddlex/inference/utils/io/readers.py +46 -0
  102. paddlex/inference/utils/io/writers.py +2 -0
  103. paddlex/inference/utils/official_models.py +7 -0
  104. paddlex/inference/utils/pp_option.py +34 -18
  105. paddlex/modules/anomaly_detection/dataset_checker/dataset_src/convert_dataset.py +2 -2
  106. paddlex/modules/face_recognition/dataset_checker/dataset_src/utils/visualizer.py +3 -3
  107. paddlex/modules/formula_recognition/dataset_checker/dataset_src/analyse_dataset.py +2 -2
  108. paddlex/modules/general_recognition/dataset_checker/dataset_src/analyse_dataset.py +2 -2
  109. paddlex/modules/general_recognition/dataset_checker/dataset_src/utils/visualizer.py +3 -3
  110. paddlex/modules/image_classification/dataset_checker/dataset_src/analyse_dataset.py +2 -2
  111. paddlex/modules/image_classification/dataset_checker/dataset_src/utils/visualizer.py +3 -3
  112. paddlex/modules/instance_segmentation/dataset_checker/dataset_src/analyse_dataset.py +2 -2
  113. paddlex/modules/instance_segmentation/dataset_checker/dataset_src/utils/visualizer.py +2 -2
  114. paddlex/modules/m_3d_bev_detection/dataset_checker/dataset_src/analyse_dataset.py +2 -2
  115. paddlex/modules/multilabel_classification/dataset_checker/dataset_src/analyse_dataset.py +2 -2
  116. paddlex/modules/multilabel_classification/dataset_checker/dataset_src/utils/visualizer.py +2 -2
  117. paddlex/modules/object_detection/dataset_checker/dataset_src/analyse_dataset.py +2 -2
  118. paddlex/modules/object_detection/dataset_checker/dataset_src/utils/visualizer.py +2 -2
  119. paddlex/modules/text_recognition/dataset_checker/dataset_src/analyse_dataset.py +2 -2
  120. paddlex/modules/text_recognition/model_list.py +3 -0
  121. paddlex/modules/ts_classification/dataset_checker/dataset_src/analyse_dataset.py +2 -2
  122. paddlex/modules/video_classification/dataset_checker/dataset_src/analyse_dataset.py +2 -2
  123. paddlex/modules/video_detection/dataset_checker/dataset_src/analyse_dataset.py +2 -2
  124. paddlex/repo_apis/PaddleOCR_api/text_rec/register.py +27 -0
  125. paddlex/repo_manager/meta.py +3 -3
  126. paddlex/utils/device.py +4 -1
  127. paddlex/utils/download.py +10 -7
  128. paddlex/utils/{fonts/__init__.py → fonts.py} +45 -26
  129. {paddlex-3.0.2.dist-info → paddlex-3.1.0.dist-info}/METADATA +25 -1
  130. {paddlex-3.0.2.dist-info → paddlex-3.1.0.dist-info}/RECORD +134 -122
  131. {paddlex-3.0.2.dist-info → paddlex-3.1.0.dist-info}/LICENSE +0 -0
  132. {paddlex-3.0.2.dist-info → paddlex-3.1.0.dist-info}/WHEEL +0 -0
  133. {paddlex-3.0.2.dist-info → paddlex-3.1.0.dist-info}/entry_points.txt +0 -0
  134. {paddlex-3.0.2.dist-info → paddlex-3.1.0.dist-info}/top_level.txt +0 -0
@@ -0,0 +1,260 @@
1
+ # Copyright (c) 2024 PaddlePaddle Authors. All Rights Reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ import re
16
+
17
+
18
+ def _find_split_pos(text, chunk_size):
19
+ """
20
+ Find the position to split the text into two chunks.
21
+
22
+ Args:
23
+ text (str): The original text to be split.
24
+ chunk_size (int): The maximum size of each chunk.
25
+
26
+ Returns:
27
+ int: The index where the text should be split.
28
+ """
29
+ center = len(text) // 2
30
+ # Search forward
31
+ for i in range(center, len(text)):
32
+ if text[i] in ["\n", ".", "。", ";", ";", "!", "!", "?", "?"]:
33
+ if i + 1 < len(text) and len(text[: i + 1]) <= chunk_size:
34
+ return i + 1
35
+ # Search backward
36
+ for i in range(center, 0, -1):
37
+ if text[i] in ["\n", ".", "。", ";", ";", "!", "!", "?", "?"]:
38
+ if len(text[: i + 1]) <= chunk_size:
39
+ return i + 1
40
+ # If no suitable position is found, split directly
41
+ return min(chunk_size, len(text))
42
+
43
+
44
+ def split_text_recursive(text, chunk_size, translate_func, results):
45
+ """
46
+ Split the text recursively and translate each chunk.
47
+
48
+ Args:
49
+ text (str): The original text to be split.
50
+ chunk_size (int): The maximum size of each chunk.
51
+ translate_func (callable): A function that translates a single chunk of text.
52
+ results (list): A list to store the translated chunks.
53
+
54
+ Returns:
55
+ None
56
+ """
57
+ text = text.strip()
58
+ if len(text) <= chunk_size:
59
+ results.append(translate_func(text))
60
+ else:
61
+ split_pos = _find_split_pos(text, chunk_size)
62
+ left = text[:split_pos].strip()
63
+ right = text[split_pos:].strip()
64
+ if left:
65
+ split_text_recursive(left, chunk_size, translate_func, results)
66
+ if right:
67
+ split_text_recursive(right, chunk_size, translate_func, results)
68
+
69
+
70
+ def translate_code_block(code_block, chunk_size, translate_func, results):
71
+ """
72
+ Translate a code block and append the result to the results list.
73
+
74
+ Args:
75
+ code_block (str): The code block to be translated.
76
+ chunk_size (int): The maximum size of each chunk.
77
+ translate_func (callable): A function that translates a single chunk of text.
78
+ results (list): A list to store the translated chunks.
79
+
80
+ Returns:
81
+ None
82
+ """
83
+ lines = code_block.strip().split("\n")
84
+ if lines[0].startswith("```") or lines[0].startswith("~~~"):
85
+ header = lines[0]
86
+ footer = (
87
+ lines[-1]
88
+ if (lines[-1].startswith("```") or lines[-1].startswith("~~~"))
89
+ else ""
90
+ )
91
+ code_content = "\n".join(lines[1:-1]) if footer else "\n".join(lines[1:])
92
+ else:
93
+ header = ""
94
+ footer = ""
95
+ code_content = code_block
96
+
97
+ translated_code_lines = []
98
+ split_text_recursive(
99
+ code_content, chunk_size, translate_func, translated_code_lines
100
+ )
101
+
102
+ # drop ``` or ~~~
103
+ filtered_code_lines = [
104
+ line
105
+ for line in translated_code_lines
106
+ if not (line.strip().startswith("```") or line.strip().startswith("~~~"))
107
+ ]
108
+ translated_code = "\n".join(filtered_code_lines)
109
+
110
+ result = f"{header}\n{translated_code}\n{footer}" if header else translated_code
111
+ results.append(result)
112
+
113
+
114
+ def translate_html_block(html_block, chunk_size, translate_func, results):
115
+ """
116
+ Translate a HTML block and append the result to the results list.
117
+
118
+ Args:
119
+ html_block (str): The HTML block to be translated.
120
+ chunk_size (int): The maximum size of each chunk.
121
+ translate_func (callable): A function that translates a single chunk of text.
122
+ results (list): A list to store the translated chunks.
123
+
124
+ Returns:
125
+ None
126
+ """
127
+ from bs4 import BeautifulSoup
128
+
129
+ soup = BeautifulSoup(html_block, "html.parser")
130
+
131
+ # collect text nodes
132
+ text_nodes = []
133
+ for node in soup.find_all(string=True, recursive=True):
134
+ text = node.strip()
135
+ if text:
136
+ text_nodes.append(node)
137
+
138
+ idx = 0
139
+ total = len(text_nodes)
140
+ while idx < total:
141
+ batch_nodes = []
142
+ li_texts = []
143
+ current_length = len("<ol></ol>")
144
+ while idx < total:
145
+ node_text = text_nodes[idx].strip()
146
+ if len(node_text) > chunk_size:
147
+ # if node_text is too long, split it
148
+ translated_lines = []
149
+ split_text_recursive(
150
+ node_text, chunk_size, translate_func, translated_lines
151
+ )
152
+ # concatenate translated lines with \n
153
+ text_nodes[idx].replace_with("\n".join(translated_lines))
154
+ idx += 1
155
+ continue
156
+ li_str = f"<li>{node_text}</li>"
157
+ if current_length + len(li_str) > chunk_size:
158
+ break
159
+ batch_nodes.append(text_nodes[idx])
160
+ li_texts.append(li_str)
161
+ current_length += len(li_str)
162
+ idx += 1
163
+ if not batch_nodes:
164
+ # if all individual nodes are longer than chunk_size, translate it alone
165
+ node_text = text_nodes[idx - 1].strip()
166
+ li_str = f"<li>{node_text}</li>"
167
+ batch_nodes = [text_nodes[idx - 1]]
168
+ li_texts = [li_str]
169
+
170
+ if batch_nodes:
171
+ batch_text = "<ol>" + "".join(li_texts) + "</ol>"
172
+ translated = translate_func(batch_text)
173
+ trans_soup = BeautifulSoup(translated, "html.parser")
174
+ translated_lis = trans_soup.find_all("li")
175
+ for orig_node, li_tag in zip(batch_nodes, translated_lis):
176
+ orig_node.replace_with(li_tag.decode_contents())
177
+
178
+ results.append(str(soup))
179
+
180
+
181
+ def split_original_texts(text):
182
+ """
183
+ Split the original text into chunks.
184
+ """
185
+ from bs4 import BeautifulSoup
186
+
187
+ # find all html blocks and replace them with placeholders
188
+ soup = BeautifulSoup(text, "html.parser")
189
+ html_blocks = []
190
+ html_placeholders = []
191
+ placeholder_fmt = "<<HTML_BLOCK_{}>>"
192
+ text_after_placeholder = ""
193
+
194
+ index = 0
195
+ for elem in soup.contents:
196
+ if hasattr(elem, "name") and elem.name is not None:
197
+ html_str = str(elem)
198
+ placeholder = placeholder_fmt.format(index)
199
+ html_blocks.append(html_str)
200
+ html_placeholders.append(placeholder)
201
+ text_after_placeholder += placeholder
202
+ index += 1
203
+ else:
204
+ text_after_placeholder += str(elem)
205
+
206
+ # split text into paragraphs
207
+ splited_block = []
208
+ splited_block = split_and_append_text(splited_block, text_after_placeholder)
209
+
210
+ # replace placeholders with html blocks
211
+ current_index = 0
212
+ for idx, block in enumerate(splited_block):
213
+ _, content = block
214
+ while (
215
+ current_index < len(html_placeholders)
216
+ and html_placeholders[current_index] in content
217
+ ):
218
+ content = content.replace(
219
+ html_placeholders[current_index], html_blocks[current_index]
220
+ )
221
+ current_index += 1
222
+ splited_block[idx] = ("html", content)
223
+
224
+ return splited_block
225
+
226
+
227
+ def split_and_append_text(result, text_content):
228
+ """
229
+ Split the text and append the result to the result list.
230
+
231
+ Args:
232
+ result (list): The current result list.
233
+ text_content (str): The text content to be processed.
234
+
235
+ Returns:
236
+ list: The updated result list after processing the text content.
237
+ """
238
+ if text_content.strip():
239
+ # match all code block interval
240
+ code_pattern = re.compile(r"(```.*?\n.*?```|~~~.*?\n.*?~~~)", re.DOTALL)
241
+ last_pos = 0
242
+ for m in code_pattern.finditer(text_content):
243
+ # process text before code block
244
+ if m.start() > last_pos:
245
+ non_code = text_content[last_pos : m.start()]
246
+ paragraphs = re.split(r"\n{2,}", non_code)
247
+ for p in paragraphs:
248
+ if p.strip():
249
+ result.append(("text", p.strip()))
250
+ # process code block
251
+ result.append(("code", m.group()))
252
+ last_pos = m.end()
253
+ # process remaining text
254
+ if last_pos < len(text_content):
255
+ non_code = text_content[last_pos:]
256
+ paragraphs = re.split(r"\n{2,}", non_code)
257
+ for p in paragraphs:
258
+ if p.strip():
259
+ result.append(("text", p.strip()))
260
+ return result
@@ -17,7 +17,7 @@ import copy
17
17
  import PIL
18
18
  from PIL import Image, ImageDraw, ImageFont
19
19
 
20
- from ....utils.fonts import PINGFANG_FONT_FILE_PATH
20
+ from ....utils.fonts import PINGFANG_FONT
21
21
  from ...common.result import BaseCVResult, JsonMixin
22
22
  from ...utils.color_map import font_colormap, get_colormap
23
23
 
@@ -32,7 +32,7 @@ def draw_box(img, boxes):
32
32
  """
33
33
  img = Image.fromarray(img)
34
34
  font_size = int(0.018 * int(img.width)) + 2
35
- font = ImageFont.truetype(PINGFANG_FONT_FILE_PATH, font_size, encoding="utf-8")
35
+ font = ImageFont.truetype(PINGFANG_FONT.path, font_size, encoding="utf-8")
36
36
 
37
37
  draw_thickness = int(max(img.size) * 0.002)
38
38
  draw = ImageDraw.Draw(img)
@@ -114,6 +114,7 @@ class PipelineWrapper(Generic[PipelineT]):
114
114
  if not self._closed:
115
115
  self._queue.put(None)
116
116
  await call_async(self._thread.join)
117
+ self._closed = True
117
118
 
118
119
  def _worker(self):
119
120
  while not self._closed:
@@ -39,7 +39,9 @@ def create_pipeline_app(pipeline: Any, app_config: AppConfig) -> "FastAPI":
39
39
  async def _infer(request: InferRequest) -> AIStudioResultResponse[InferResult]:
40
40
  pipeline = ctx.pipeline
41
41
  aiohttp_session = ctx.aiohttp_session
42
-
42
+ visualize_enabled = (
43
+ request.visualize if request.visualize is not None else ctx.config.visualize
44
+ )
43
45
  file_bytes = await serving_utils.get_raw_bytes_async(
44
46
  request.image, aiohttp_session
45
47
  )
@@ -50,7 +52,7 @@ def create_pipeline_app(pipeline: Any, app_config: AppConfig) -> "FastAPI":
50
52
  pred = result["pred"][0].tolist()
51
53
  size = [len(pred), len(pred[0])]
52
54
  label_map = [item for sublist in pred for item in sublist]
53
- if ctx.config.visualize:
55
+ if visualize_enabled:
54
56
  output_image_base64 = serving_utils.base64_encode(
55
57
  serving_utils.image_to_bytes(result.img["res"].convert("RGB"))
56
58
  )
@@ -45,6 +45,10 @@ def create_pipeline_app(pipeline: Any, app_config: AppConfig) -> "FastAPI":
45
45
 
46
46
  log_id = serving_utils.generate_log_id()
47
47
 
48
+ visualize_enabled = (
49
+ request.visualize if request.visualize is not None else ctx.config.visualize
50
+ )
51
+
48
52
  images, data_info = await ocr_common.get_images(request, ctx)
49
53
 
50
54
  result = await pipeline.infer(
@@ -64,7 +68,7 @@ def create_pipeline_app(pipeline: Any, app_config: AppConfig) -> "FastAPI":
64
68
  return_url=ctx.extra["return_img_urls"],
65
69
  max_img_size=ctx.extra["max_output_img_size"],
66
70
  )
67
- if ctx.config.visualize:
71
+ if visualize_enabled:
68
72
  vis_imgs = {
69
73
  "input_img": img,
70
74
  "doc_preprocessing_img": item.img["preprocessed_img"],
@@ -166,7 +166,9 @@ def create_pipeline_app(pipeline: Any, app_config: AppConfig) -> "FastAPI":
166
166
  ) -> AIStudioResultResponse[schema.InferResult]:
167
167
  pipeline = ctx.pipeline
168
168
  aiohttp_session = ctx.aiohttp_session
169
-
169
+ visualize_enabled = (
170
+ request.visualize if request.visualize is not None else ctx.config.visualize
171
+ )
170
172
  image_bytes = await serving_utils.get_raw_bytes_async(
171
173
  request.image, aiohttp_session
172
174
  )
@@ -211,7 +213,7 @@ def create_pipeline_app(pipeline: Any, app_config: AppConfig) -> "FastAPI":
211
213
  score=obj["det_score"],
212
214
  )
213
215
  )
214
- if ctx.config.visualize:
216
+ if visualize_enabled:
215
217
  output_image_base64 = serving_utils.base64_encode(
216
218
  serving_utils.image_to_bytes(result.img["res"])
217
219
  )
@@ -44,7 +44,9 @@ def create_pipeline_app(pipeline: Any, app_config: AppConfig) -> "FastAPI":
44
44
  pipeline = ctx.pipeline
45
45
 
46
46
  log_id = serving_utils.generate_log_id()
47
-
47
+ visualize_enabled = (
48
+ request.visualize if request.visualize is not None else ctx.config.visualize
49
+ )
48
50
  images, data_info = await ocr_common.get_images(request, ctx)
49
51
 
50
52
  result = await pipeline.infer(
@@ -61,7 +63,7 @@ def create_pipeline_app(pipeline: Any, app_config: AppConfig) -> "FastAPI":
61
63
  formula_rec_results: List[Dict[str, Any]] = []
62
64
  for i, (img, item) in enumerate(zip(images, result)):
63
65
  pruned_res = common.prune_result(item.json["res"])
64
- if ctx.config.visualize:
66
+ if visualize_enabled:
65
67
  imgs = {
66
68
  "input_img": img,
67
69
  **item.img,
@@ -43,7 +43,9 @@ def create_pipeline_app(pipeline: Any, app_config: AppConfig) -> "FastAPI":
43
43
  async def _infer(request: InferRequest) -> AIStudioResultResponse[InferResult]:
44
44
  pipeline = ctx.pipeline
45
45
  aiohttp_session = ctx.aiohttp_session
46
-
46
+ visualize_enabled = (
47
+ request.visualize if request.visualize is not None else ctx.config.visualize
48
+ )
47
49
  file_bytes = await serving_utils.get_raw_bytes_async(
48
50
  request.image, aiohttp_session
49
51
  )
@@ -66,7 +68,7 @@ def create_pipeline_app(pipeline: Any, app_config: AppConfig) -> "FastAPI":
66
68
  kptScore=obj["kpt_score"],
67
69
  )
68
70
  )
69
- if ctx.config.visualize:
71
+ if visualize_enabled:
70
72
  output_image_base64 = serving_utils.base64_encode(
71
73
  serving_utils.image_to_bytes(result.img["res"])
72
74
  )
@@ -39,7 +39,9 @@ def create_pipeline_app(pipeline: Any, app_config: AppConfig) -> "FastAPI":
39
39
  async def _infer(request: InferRequest) -> AIStudioResultResponse[InferResult]:
40
40
  pipeline = ctx.pipeline
41
41
  aiohttp_session = ctx.aiohttp_session
42
-
42
+ visualize_enabled = (
43
+ request.visualize if request.visualize is not None else ctx.config.visualize
44
+ )
43
45
  file_bytes = await serving_utils.get_raw_bytes_async(
44
46
  request.image, aiohttp_session
45
47
  )
@@ -54,7 +56,7 @@ def create_pipeline_app(pipeline: Any, app_config: AppConfig) -> "FastAPI":
54
56
  categories: List[Dict[str, Any]] = []
55
57
  for id_, name, score in zip(result["class_ids"], cat_names, result["scores"]):
56
58
  categories.append(dict(id=id_, name=name, score=score))
57
- if ctx.config.visualize:
59
+ if visualize_enabled:
58
60
  output_image_base64 = serving_utils.base64_encode(
59
61
  serving_utils.image_to_bytes(result.img["res"])
60
62
  )
@@ -43,7 +43,9 @@ def create_pipeline_app(pipeline: Any, app_config: AppConfig) -> "FastAPI":
43
43
  async def _infer(request: InferRequest) -> AIStudioResultResponse[InferResult]:
44
44
  pipeline = ctx.pipeline
45
45
  aiohttp_session = ctx.aiohttp_session
46
-
46
+ visualize_enabled = (
47
+ request.visualize if request.visualize is not None else ctx.config.visualize
48
+ )
47
49
  file_bytes = await serving_utils.get_raw_bytes_async(
48
50
  request.image, aiohttp_session
49
51
  )
@@ -58,7 +60,7 @@ def create_pipeline_app(pipeline: Any, app_config: AppConfig) -> "FastAPI":
58
60
  categories: List[Dict[str, Any]] = []
59
61
  for id_, name, score in zip(result["class_ids"], cat_names, result["scores"]):
60
62
  categories.append(dict(id=id_, name=name, score=score))
61
- if ctx.config.visualize:
63
+ if visualize_enabled:
62
64
  output_image_base64 = serving_utils.base64_encode(
63
65
  serving_utils.image_to_bytes(result.img["res"])
64
66
  )
@@ -51,7 +51,9 @@ def create_pipeline_app(pipeline: Any, app_config: AppConfig) -> "FastAPI":
51
51
  async def _infer(request: InferRequest) -> AIStudioResultResponse[InferResult]:
52
52
  pipeline = ctx.pipeline
53
53
  aiohttp_session = ctx.aiohttp_session
54
-
54
+ visualize_enabled = (
55
+ request.visualize if request.visualize is not None else ctx.config.visualize
56
+ )
55
57
  file_bytes = await serving_utils.get_raw_bytes_async(
56
58
  request.image, aiohttp_session
57
59
  )
@@ -72,7 +74,7 @@ def create_pipeline_app(pipeline: Any, app_config: AppConfig) -> "FastAPI":
72
74
  mask=mask,
73
75
  )
74
76
  )
75
- if ctx.config.visualize:
77
+ if visualize_enabled:
76
78
  output_image_base64 = serving_utils.base64_encode(
77
79
  serving_utils.image_to_bytes(result.img["res"])
78
80
  )
@@ -46,7 +46,9 @@ def create_pipeline_app(pipeline: Any, app_config: AppConfig) -> "FastAPI":
46
46
  pipeline = ctx.pipeline
47
47
 
48
48
  log_id = serving_utils.generate_log_id()
49
-
49
+ visualize_enabled = (
50
+ request.visualize if request.visualize is not None else ctx.config.visualize
51
+ )
50
52
  images, data_info = await ocr_common.get_images(request, ctx)
51
53
 
52
54
  result = await pipeline.infer(
@@ -78,7 +80,7 @@ def create_pipeline_app(pipeline: Any, app_config: AppConfig) -> "FastAPI":
78
80
  layout_parsing_results: List[Dict[str, Any]] = []
79
81
  for i, (img, item) in enumerate(zip(images, result)):
80
82
  pruned_res = common.prune_result(item.json["res"])
81
- if ctx.config.visualize:
83
+ if visualize_enabled:
82
84
  imgs = {
83
85
  "input_img": img,
84
86
  **item.img,
@@ -39,7 +39,9 @@ def create_pipeline_app(pipeline: Any, app_config: AppConfig) -> "FastAPI":
39
39
  async def _infer(request: InferRequest) -> AIStudioResultResponse[InferResult]:
40
40
  pipeline = ctx.pipeline
41
41
  aiohttp_session = ctx.aiohttp_session
42
-
42
+ visualize_enabled = (
43
+ request.visualize if request.visualize is not None else ctx.config.visualize
44
+ )
43
45
  file_bytes = await serving_utils.get_raw_bytes_async(
44
46
  request.image, aiohttp_session
45
47
  )
@@ -62,7 +64,7 @@ def create_pipeline_app(pipeline: Any, app_config: AppConfig) -> "FastAPI":
62
64
  score=obj["score"],
63
65
  )
64
66
  )
65
- if ctx.config.visualize:
67
+ if visualize_enabled:
66
68
  output_image_base64 = serving_utils.base64_encode(
67
69
  serving_utils.image_to_bytes(result.img["res"])
68
70
  )
@@ -44,7 +44,9 @@ def create_pipeline_app(pipeline: Any, app_config: AppConfig) -> "FastAPI":
44
44
  pipeline = ctx.pipeline
45
45
 
46
46
  log_id = serving_utils.generate_log_id()
47
-
47
+ visualize_enabled = (
48
+ request.visualize if request.visualize is not None else ctx.config.visualize
49
+ )
48
50
  images, data_info = await ocr_common.get_images(request, ctx)
49
51
 
50
52
  result = await pipeline.infer(
@@ -63,7 +65,7 @@ def create_pipeline_app(pipeline: Any, app_config: AppConfig) -> "FastAPI":
63
65
  ocr_results: List[Dict[str, Any]] = []
64
66
  for i, (img, item) in enumerate(zip(images, result)):
65
67
  pruned_res = common.prune_result(item.json["res"])
66
- if ctx.config.visualize:
68
+ if visualize_enabled:
67
69
  output_imgs = item.img
68
70
  imgs = {
69
71
  "input_img": img,
@@ -43,7 +43,9 @@ def create_pipeline_app(pipeline: Any, app_config: AppConfig) -> "FastAPI":
43
43
  async def _infer(request: InferRequest) -> AIStudioResultResponse[InferResult]:
44
44
  pipeline = ctx.pipeline
45
45
  aiohttp_session = ctx.aiohttp_session
46
-
46
+ visualize_enabled = (
47
+ request.visualize if request.visualize is not None else ctx.config.visualize
48
+ )
47
49
  file_bytes = await serving_utils.get_raw_bytes_async(
48
50
  request.image, aiohttp_session
49
51
  )
@@ -66,7 +68,7 @@ def create_pipeline_app(pipeline: Any, app_config: AppConfig) -> "FastAPI":
66
68
  score=obj["score"],
67
69
  )
68
70
  )
69
- if ctx.config.visualize:
71
+ if visualize_enabled:
70
72
  output_image_base64 = serving_utils.base64_encode(
71
73
  serving_utils.image_to_bytes(result.img["res"])
72
74
  )
@@ -55,7 +55,9 @@ def create_pipeline_app(pipeline: Any, app_config: AppConfig) -> "FastAPI":
55
55
  async def _infer(request: InferRequest) -> AIStudioResultResponse[InferResult]:
56
56
  pipeline = ctx.pipeline
57
57
  aiohttp_session = ctx.aiohttp_session
58
-
58
+ visualize_enabled = (
59
+ request.visualize if request.visualize is not None else ctx.config.visualize
60
+ )
59
61
  file_bytes = await serving_utils.get_raw_bytes_async(
60
62
  request.image, aiohttp_session
61
63
  )
@@ -74,7 +76,7 @@ def create_pipeline_app(pipeline: Any, app_config: AppConfig) -> "FastAPI":
74
76
  ]
75
77
  mask_infos = result["mask_infos"]
76
78
 
77
- if ctx.config.visualize:
79
+ if visualize_enabled:
78
80
  output_image_base64 = serving_utils.base64_encode(
79
81
  serving_utils.image_to_bytes(result.img["res"])
80
82
  )
@@ -43,7 +43,9 @@ def create_pipeline_app(pipeline: Any, app_config: AppConfig) -> "FastAPI":
43
43
  async def _infer(request: InferRequest) -> AIStudioResultResponse[InferResult]:
44
44
  pipeline = ctx.pipeline
45
45
  aiohttp_session = ctx.aiohttp_session
46
-
46
+ visualize_enabled = (
47
+ request.visualize if request.visualize is not None else ctx.config.visualize
48
+ )
47
49
  file_bytes = await serving_utils.get_raw_bytes_async(
48
50
  request.image, aiohttp_session
49
51
  )
@@ -69,7 +71,7 @@ def create_pipeline_app(pipeline: Any, app_config: AppConfig) -> "FastAPI":
69
71
  score=obj["det_score"],
70
72
  )
71
73
  )
72
- if ctx.config.visualize:
74
+ if visualize_enabled:
73
75
  output_image_base64 = serving_utils.base64_encode(
74
76
  serving_utils.image_to_bytes(result.img["res"])
75
77
  )
@@ -46,7 +46,9 @@ def create_pipeline_app(pipeline: Any, app_config: AppConfig) -> "FastAPI":
46
46
  pipeline = ctx.pipeline
47
47
 
48
48
  log_id = serving_utils.generate_log_id()
49
-
49
+ visualize_enabled = (
50
+ request.visualize if request.visualize is not None else ctx.config.visualize
51
+ )
50
52
  images, data_info = await ocr_common.get_images(request, ctx)
51
53
 
52
54
  result = await pipeline.call(
@@ -78,7 +80,7 @@ def create_pipeline_app(pipeline: Any, app_config: AppConfig) -> "FastAPI":
78
80
  visual_info: List[dict] = []
79
81
  for i, (img, item) in enumerate(zip(images, result)):
80
82
  pruned_res = common.prune_result(item["layout_parsing_result"].json["res"])
81
- if ctx.config.visualize:
83
+ if visualize_enabled:
82
84
  imgs = {
83
85
  "input_img": img,
84
86
  **item["layout_parsing_result"].img,
@@ -126,19 +128,13 @@ def create_pipeline_app(pipeline: Any, app_config: AppConfig) -> "FastAPI":
126
128
  ) -> AIStudioResultResponse[schema.BuildVectorStoreResult]:
127
129
  pipeline = ctx.pipeline
128
130
 
129
- kwargs: Dict[str, Any] = {
130
- "flag_save_bytes_vector": True,
131
- "retriever_config": request.retrieverConfig,
132
- }
133
- if request.minCharacters is not None:
134
- kwargs["min_characters"] = request.minCharacters
135
- if request.blockSize is not None:
136
- kwargs["block_size"] = request.blockSize
137
-
138
131
  vector_info = await serving_utils.call_async(
139
132
  pipeline.pipeline.build_vector,
140
133
  request.visualInfo,
141
- **kwargs,
134
+ min_characters=request.minCharacters,
135
+ block_size=request.blockSize,
136
+ flag_save_bytes_vector=True,
137
+ retriever_config=request.retrieverConfig,
142
138
  )
143
139
 
144
140
  return AIStudioResultResponse[schema.BuildVectorStoreResult](
@@ -156,8 +152,13 @@ def create_pipeline_app(pipeline: Any, app_config: AppConfig) -> "FastAPI":
156
152
  ) -> AIStudioResultResponse[schema.ChatResult]:
157
153
  pipeline = ctx.pipeline
158
154
 
159
- kwargs: Dict[str, Any] = dict(
155
+ result = await serving_utils.call_async(
156
+ pipeline.pipeline.chat,
157
+ request.keyList,
158
+ request.visualInfo,
159
+ use_vector_retrieval=request.useVectorRetrieval,
160
160
  vector_info=request.vectorInfo,
161
+ min_characters=request.minCharacters,
161
162
  text_task_description=request.textTaskDescription,
162
163
  text_output_format=request.textOutputFormat,
163
164
  text_rules_str=request.textRulesStr,
@@ -171,17 +172,6 @@ def create_pipeline_app(pipeline: Any, app_config: AppConfig) -> "FastAPI":
171
172
  chat_bot_config=request.chatBotConfig,
172
173
  retriever_config=request.retrieverConfig,
173
174
  )
174
- if request.useVectorRetrieval is not None:
175
- kwargs["use_vector_retrieval"] = request.useVectorRetrieval
176
- if request.minCharacters is not None:
177
- kwargs["min_characters"] = request.minCharacters
178
-
179
- result = await serving_utils.call_async(
180
- pipeline.pipeline.chat,
181
- request.keyList,
182
- request.visualInfo,
183
- **kwargs,
184
- )
185
175
 
186
176
  return AIStudioResultResponse[schema.ChatResult](
187
177
  logId=serving_utils.generate_log_id(),