pipeline_v4.py 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635
  1. # copyright (c) 2024 PaddlePaddle Authors. All Rights Reserve.
  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. from typing import Any, Dict, Optional
  15. import re
  16. import json
  17. import numpy as np
  18. import copy
  19. from .pipeline_base import PP_ChatOCR_Pipeline
  20. from .result import VisualInfoResult
  21. from ...common.reader import ReadImage
  22. from ...common.batch_sampler import ImageBatchSampler
  23. from ....utils import logging
  24. from ...utils.pp_option import PaddlePredictorOption
  25. from ..layout_parsing.result import LayoutParsingResult
  26. class PP_ChatOCRv4_Pipeline(PP_ChatOCR_Pipeline):
  27. """PP-ChatOCRv4 Pipeline"""
  28. entities = ["PP-ChatOCRv4-doc"]
  29. def __init__(
  30. self,
  31. config: Dict,
  32. device: str = None,
  33. pp_option: PaddlePredictorOption = None,
  34. use_hpip: bool = False,
  35. hpi_params: Optional[Dict[str, Any]] = None,
  36. ) -> None:
  37. """Initializes the pp-chatocrv3-doc pipeline.
  38. Args:
  39. config (Dict): Configuration dictionary containing various settings.
  40. device (str, optional): Device to run the predictions on. Defaults to None.
  41. pp_option (PaddlePredictorOption, optional): PaddlePredictor options. Defaults to None.
  42. use_hpip (bool, optional): Whether to use high-performance inference (hpip) for prediction. Defaults to False.
  43. hpi_params (Optional[Dict[str, Any]], optional): HPIP parameters. Defaults to None.
  44. use_layout_parsing (bool, optional): Whether to use layout parsing. Defaults to True.
  45. """
  46. super().__init__(
  47. device=device, pp_option=pp_option, use_hpip=use_hpip, hpi_params=hpi_params
  48. )
  49. self.pipeline_name = config["pipeline_name"]
  50. self.inintial_predictor(config)
  51. self.batch_sampler = ImageBatchSampler(batch_size=1)
  52. self.img_reader = ReadImage(format="BGR")
  53. self.table_structure_len_max = 500
  54. def inintial_predictor(self, config: dict) -> None:
  55. """
  56. Initializes the predictor with the given configuration.
  57. Args:
  58. config (dict): The configuration dictionary containing the necessary
  59. parameters for initializing the predictor.
  60. Returns:
  61. None
  62. """
  63. layout_parsing_config = config["SubPipelines"]["LayoutParser"]
  64. self.layout_parsing_pipeline = self.create_pipeline(layout_parsing_config)
  65. from .. import create_chat_bot
  66. chat_bot_config = config["SubModules"]["LLM_Chat"]
  67. self.chat_bot = create_chat_bot(chat_bot_config)
  68. from .. import create_retriever
  69. retriever_config = config["SubModules"]["LLM_Retriever"]
  70. self.retriever = create_retriever(retriever_config)
  71. from .. import create_prompt_engeering
  72. text_pe_config = config["SubModules"]["PromptEngneering"]["KIE_CommonText"]
  73. self.text_pe = create_prompt_engeering(text_pe_config)
  74. table_pe_config = config["SubModules"]["PromptEngneering"]["KIE_Table"]
  75. self.table_pe = create_prompt_engeering(table_pe_config)
  76. self.use_mllm_predict = False
  77. if "use_mllm_predict" in config:
  78. self.use_mllm_predict = config["use_mllm_predict"]
  79. if self.use_mllm_predict:
  80. ensemble_pe_config = config["SubModules"]["PromptEngneering"]["Ensemble"]
  81. self.ensemble_pe = create_prompt_engeering(ensemble_pe_config)
  82. return
  83. def decode_visual_result(
  84. self, layout_parsing_result: LayoutParsingResult
  85. ) -> VisualInfoResult:
  86. """
  87. Decodes the visual result from the layout parsing result.
  88. Args:
  89. layout_parsing_result (LayoutParsingResult): The result of layout parsing.
  90. Returns:
  91. VisualInfoResult: The decoded visual information.
  92. """
  93. text_paragraphs_ocr_res = layout_parsing_result["text_paragraphs_ocr_res"]
  94. seal_res_list = layout_parsing_result["seal_res_list"]
  95. normal_text_dict = {}
  96. for seal_res in seal_res_list:
  97. for text in seal_res["rec_text"]:
  98. layout_type = "印章"
  99. if layout_type not in normal_text_dict:
  100. normal_text_dict[layout_type] = f"{text}"
  101. else:
  102. normal_text_dict[layout_type] += f"\n {text}"
  103. for text in text_paragraphs_ocr_res["rec_text"]:
  104. layout_type = "words in text block"
  105. if layout_type not in normal_text_dict:
  106. normal_text_dict[layout_type] = text
  107. else:
  108. normal_text_dict[layout_type] += f"\n {text}"
  109. table_res_list = layout_parsing_result["table_res_list"]
  110. table_text_list = []
  111. table_html_list = []
  112. table_nei_text_list = []
  113. for table_res in table_res_list:
  114. table_html_list.append(table_res["pred_html"])
  115. single_table_text = " ".join(table_res["table_ocr_pred"]["rec_text"])
  116. table_text_list.append(single_table_text)
  117. table_nei_text_list.append(table_res["neighbor_text"])
  118. visual_info = {}
  119. visual_info["normal_text_dict"] = normal_text_dict
  120. visual_info["table_text_list"] = table_text_list
  121. visual_info["table_html_list"] = table_html_list
  122. visual_info["table_nei_text_list"] = table_nei_text_list
  123. return VisualInfoResult(visual_info)
  124. # Function to perform visual prediction on input images
  125. def visual_predict(
  126. self,
  127. input: str | list[str] | np.ndarray | list[np.ndarray],
  128. use_doc_orientation_classify: bool = False, # Whether to use document orientation classification
  129. use_doc_unwarping: bool = False, # Whether to use document unwarping
  130. use_general_ocr: bool = True, # Whether to use general OCR
  131. use_seal_recognition: bool = True, # Whether to use seal recognition
  132. use_table_recognition: bool = True, # Whether to use table recognition
  133. **kwargs,
  134. ) -> dict:
  135. """
  136. This function takes an input image or a list of images and performs various visual
  137. prediction tasks such as document orientation classification, document unwarping,
  138. general OCR, seal recognition, and table recognition based on the provided flags.
  139. Args:
  140. input (str | list[str] | np.ndarray | list[np.ndarray]): Input image path, list of image paths,
  141. numpy array of an image, or list of numpy arrays.
  142. use_doc_orientation_classify (bool): Flag to use document orientation classification.
  143. use_doc_unwarping (bool): Flag to use document unwarping.
  144. use_general_ocr (bool): Flag to use general OCR.
  145. use_seal_recognition (bool): Flag to use seal recognition.
  146. use_table_recognition (bool): Flag to use table recognition.
  147. **kwargs: Additional keyword arguments.
  148. Returns:
  149. dict: A dictionary containing the layout parsing result and visual information.
  150. """
  151. for layout_parsing_result in self.layout_parsing_pipeline.predict(
  152. input,
  153. use_doc_orientation_classify=use_doc_orientation_classify,
  154. use_doc_unwarping=use_doc_unwarping,
  155. use_general_ocr=use_general_ocr,
  156. use_seal_recognition=use_seal_recognition,
  157. use_table_recognition=use_table_recognition,
  158. ):
  159. visual_info = self.decode_visual_result(layout_parsing_result)
  160. visual_predict_res = {
  161. "layout_parsing_result": layout_parsing_result,
  162. "visual_info": visual_info,
  163. }
  164. yield visual_predict_res
  165. def save_visual_info_list(
  166. self, visual_info: VisualInfoResult, save_path: str
  167. ) -> None:
  168. """
  169. Save the visual info list to the specified file path.
  170. Args:
  171. visual_info (VisualInfoResult): The visual info result, which can be a single object or a list of objects.
  172. save_path (str): The file path to save the visual info list.
  173. Returns:
  174. None
  175. """
  176. if not isinstance(visual_info, list):
  177. visual_info_list = [visual_info]
  178. else:
  179. visual_info_list = visual_info
  180. with open(save_path, "w") as fout:
  181. fout.write(json.dumps(visual_info_list, ensure_ascii=False) + "\n")
  182. return
  183. def load_visual_info_list(self, data_path: str) -> list[VisualInfoResult]:
  184. """
  185. Loads visual info list from a JSON file.
  186. Args:
  187. data_path (str): The path to the JSON file containing visual info.
  188. Returns:
  189. list[VisualInfoResult]: A list of VisualInfoResult objects parsed from the JSON file.
  190. """
  191. with open(data_path, "r") as fin:
  192. data = fin.readline()
  193. visual_info_list = json.loads(data)
  194. return visual_info_list
  195. def merge_visual_info_list(
  196. self, visual_info_list: list[VisualInfoResult]
  197. ) -> tuple[list, list, list, list]:
  198. """
  199. Merge visual info lists.
  200. Args:
  201. visual_info_list (list[VisualInfoResult]): A list of visual info results.
  202. Returns:
  203. tuple[list, list, list, list]: A tuple containing four lists, one for normal text dicts,
  204. one for table text lists, one for table HTML lists.
  205. one for table neighbor texts.
  206. """
  207. all_normal_text_list = []
  208. all_table_text_list = []
  209. all_table_html_list = []
  210. all_table_nei_text_list = []
  211. for single_visual_info in visual_info_list:
  212. normal_text_dict = single_visual_info["normal_text_dict"]
  213. for key in normal_text_dict:
  214. normal_text_dict[key] = normal_text_dict[key].replace("\n", "")
  215. table_text_list = single_visual_info["table_text_list"]
  216. table_html_list = single_visual_info["table_html_list"]
  217. table_nei_text_list = single_visual_info["table_nei_text_list"]
  218. all_normal_text_list.append(normal_text_dict)
  219. all_table_text_list.extend(table_text_list)
  220. all_table_html_list.extend(table_html_list)
  221. all_table_nei_text_list.extend(table_nei_text_list)
  222. return (
  223. all_normal_text_list,
  224. all_table_text_list,
  225. all_table_html_list,
  226. all_table_nei_text_list,
  227. )
  228. def build_vector(
  229. self,
  230. visual_info: VisualInfoResult,
  231. min_characters: int = 3500,
  232. llm_request_interval: float = 1.0,
  233. ) -> dict:
  234. """
  235. Build a vector representation from visual information.
  236. Args:
  237. visual_info (VisualInfoResult): The visual information input, can be a single instance or a list of instances.
  238. min_characters (int): The minimum number of characters required for text processing, defaults to 3500.
  239. llm_request_interval (float): The interval between LLM requests, defaults to 1.0.
  240. Returns:
  241. dict: A dictionary containing the vector info and a flag indicating if the text is too short.
  242. """
  243. if not isinstance(visual_info, list):
  244. visual_info_list = [visual_info]
  245. else:
  246. visual_info_list = visual_info
  247. all_visual_info = self.merge_visual_info_list(visual_info_list)
  248. (
  249. all_normal_text_list,
  250. all_table_text_list,
  251. all_table_html_list,
  252. all_table_nei_text_list,
  253. ) = all_visual_info
  254. vector_info = {}
  255. all_items = []
  256. for i, normal_text_dict in enumerate(all_normal_text_list):
  257. for type, text in normal_text_dict.items():
  258. all_items += [f"{type}:{text}\n"]
  259. for table_html, table_text, table_nei_text in zip(
  260. all_table_html_list, all_table_text_list, all_table_nei_text_list
  261. ):
  262. if len(table_html) > min_characters - self.table_structure_len_max:
  263. all_items += [f"table:{table_text}\t{table_nei_text}"]
  264. all_text_str = "".join(all_items)
  265. if len(all_text_str) > min_characters:
  266. vector_info["flag_too_short_text"] = False
  267. vector_info["vector"] = self.retriever.generate_vector_database(all_items)
  268. else:
  269. vector_info["flag_too_short_text"] = True
  270. vector_info["vector"] = all_items
  271. return vector_info
  272. def save_vector(self, vector_info: dict, save_path: str) -> None:
  273. if "flag_too_short_text" not in vector_info or "vector" not in vector_info:
  274. logging.error("Invalid vector info.")
  275. return
  276. save_vector_info = {}
  277. save_vector_info["flag_too_short_text"] = vector_info["flag_too_short_text"]
  278. if not vector_info["flag_too_short_text"]:
  279. save_vector_info["vector"] = self.retriever.encode_vector_store_to_bytes(
  280. vector_info["vector"]
  281. )
  282. else:
  283. save_vector_info["vector"] = vector_info["vector"]
  284. with open(save_path, "w") as fout:
  285. fout.write(json.dumps(save_vector_info, ensure_ascii=False) + "\n")
  286. return
  287. def load_vector(self, data_path: str) -> dict:
  288. vector_info = None
  289. with open(data_path, "r") as fin:
  290. data = fin.readline()
  291. vector_info = json.loads(data)
  292. if "flag_too_short_text" not in vector_info or "vector" not in vector_info:
  293. logging.error("Invalid vector info.")
  294. return
  295. if not vector_info["flag_too_short_text"]:
  296. vector_info["vector"] = self.retriever.decode_vector_store_from_bytes(
  297. vector_info["vector"]
  298. )
  299. return vector_info
  300. def format_key(self, key_list: str | list[str]) -> list[str]:
  301. """
  302. Formats the key list.
  303. Args:
  304. key_list (str|list[str]): A string or a list of strings representing the keys.
  305. Returns:
  306. list[str]: A list of formatted keys.
  307. """
  308. if key_list == "":
  309. return []
  310. if isinstance(key_list, list):
  311. key_list = [key.replace("\xa0", " ") for key in key_list]
  312. return key_list
  313. if isinstance(key_list, str):
  314. key_list = re.sub(r"[\t\n\r\f\v]", "", key_list)
  315. key_list = key_list.replace(",", ",").split(",")
  316. return key_list
  317. return []
  318. def generate_and_merge_chat_results(
  319. self, prompt: str, key_list: list, final_results: dict, failed_results: list
  320. ) -> None:
  321. """
  322. Generate and merge chat results into the final results dictionary.
  323. Args:
  324. prompt (str): The input prompt for the chat bot.
  325. key_list (list): A list of keys to track which results to merge.
  326. final_results (dict): The dictionary to store the final merged results.
  327. failed_results (list): A list of failed results to avoid merging.
  328. Returns:
  329. None
  330. """
  331. llm_result = self.chat_bot.generate_chat_results(prompt)
  332. if llm_result is None:
  333. logging.error(
  334. "chat bot error: \n [prompt:]\n %s\n [result:] %s\n"
  335. % (prompt, self.chat_bot.ERROR_MASSAGE)
  336. )
  337. return
  338. llm_result = self.chat_bot.fix_llm_result_format(llm_result)
  339. for key, value in llm_result.items():
  340. if value not in failed_results and key in key_list:
  341. key_list.remove(key)
  342. final_results[key] = value
  343. return
  344. def get_related_normal_text(
  345. self,
  346. use_vector_retrieval: bool,
  347. vector_info: dict,
  348. key_list: list[str],
  349. all_normal_text_list: list,
  350. min_characters: int,
  351. ) -> str:
  352. """
  353. Retrieve related normal text based on vector retrieval or all normal text list.
  354. Args:
  355. use_vector_retrieval (bool): Whether to use vector retrieval.
  356. vector_info (dict): Dictionary containing vector information.
  357. key_list (list[str]): List of keys to generate question keys.
  358. all_normal_text_list (list): List of normal text.
  359. min_characters (int): The minimum number of characters required for text processing, defaults to 3500.
  360. Returns:
  361. str: Related normal text.
  362. """
  363. if use_vector_retrieval and vector_info is not None:
  364. question_key_list = [f"{key}" for key in key_list]
  365. vector = vector_info["vector"]
  366. if not vector_info["flag_too_short_text"]:
  367. related_text = self.retriever.similarity_retrieval(
  368. question_key_list, vector, topk=5, min_characters=min_characters
  369. )
  370. else:
  371. if len(vector) > 0:
  372. related_text = "".join(vector)
  373. else:
  374. related_text = ""
  375. else:
  376. all_items = []
  377. for i, normal_text_dict in enumerate(all_normal_text_list):
  378. for type, text in normal_text_dict.items():
  379. all_items += [f"{type}:{text}\n"]
  380. related_text = "".join(all_items)
  381. if len(related_text) > min_characters:
  382. logging.warning(
  383. "The input text content is too long, the large language model may truncate it."
  384. )
  385. return related_text
  386. def ensemble_ocr_llm_mllm(
  387. self, key_list: list[str], ocr_llm_predict_dict: dict, mllm_predict_dict: dict
  388. ) -> dict:
  389. """
  390. Ensemble OCR_LLM and LMM predictions based on given key list.
  391. Args:
  392. key_list (list[str]): List of keys to retrieve predictions.
  393. ocr_llm_predict_dict (dict): Dictionary containing OCR LLM predictions.
  394. mllm_predict_dict (dict): Dictionary containing mLLM predictions.
  395. Returns:
  396. dict: A dictionary with final predictions.
  397. """
  398. final_predict_dict = {}
  399. for key in key_list:
  400. predict = ""
  401. ocr_llm_predict = ""
  402. mllm_predict = ""
  403. if key in ocr_llm_predict_dict:
  404. ocr_llm_predict = ocr_llm_predict_dict[key]
  405. if key in mllm_predict_dict:
  406. mllm_predict = mllm_predict_dict[key]
  407. if ocr_llm_predict != "" and mllm_predict != "":
  408. prompt = self.ensemble_pe.generate_prompt(
  409. key, ocr_llm_predict, mllm_predict
  410. )
  411. llm_result = self.chat_bot.generate_chat_results(prompt)
  412. if llm_result is not None:
  413. llm_result = self.chat_bot.fix_llm_result_format(llm_result)
  414. if key in llm_result:
  415. tmp = llm_result[key]
  416. if "B" in tmp:
  417. predict = mllm_predict
  418. else:
  419. predict = ocr_llm_predict
  420. else:
  421. predict = ocr_llm_predict
  422. elif key in ocr_llm_predict_dict:
  423. predict = ocr_llm_predict_dict[key]
  424. elif key in mllm_predict_dict:
  425. predict = mllm_predict_dict[key]
  426. if predict != "":
  427. final_predict_dict[key] = predict
  428. return final_predict_dict
  429. def chat(
  430. self,
  431. key_list: str | list[str],
  432. visual_info: VisualInfoResult,
  433. use_vector_retrieval: bool = True,
  434. vector_info: dict = None,
  435. min_characters: int = 3500,
  436. text_task_description: str = None,
  437. text_output_format: str = None,
  438. text_rules_str: str = None,
  439. text_few_shot_demo_text_content: str = None,
  440. text_few_shot_demo_key_value_list: str = None,
  441. table_task_description: str = None,
  442. table_output_format: str = None,
  443. table_rules_str: str = None,
  444. table_few_shot_demo_text_content: str = None,
  445. table_few_shot_demo_key_value_list: str = None,
  446. mllm_predict_dict: dict = None,
  447. ) -> dict:
  448. """
  449. Generates chat results based on the provided key list and visual information.
  450. Args:
  451. key_list (str | list[str]): A single key or a list of keys to extract information.
  452. visual_info (VisualInfoResult): The visual information result.
  453. use_vector_retrieval (bool): Whether to use vector retrieval.
  454. vector_info (dict): The vector information for retrieval.
  455. min_characters (int): The minimum number of characters required for text processing, defaults to 3500.
  456. text_task_description (str): The description of the text task.
  457. text_output_format (str): The output format for text results.
  458. text_rules_str (str): The rules for generating text results.
  459. text_few_shot_demo_text_content (str): The text content for few-shot demos.
  460. text_few_shot_demo_key_value_list (str): The key-value list for few-shot demos.
  461. table_task_description (str): The description of the table task.
  462. table_output_format (str): The output format for table results.
  463. table_rules_str (str): The rules for generating table results.
  464. table_few_shot_demo_text_content (str): The text content for table few-shot demos.
  465. table_few_shot_demo_key_value_list (str): The key-value list for table few-shot demos.
  466. mllm_predict_dict (dict): The dictionary of mLLM predicts.
  467. Returns:
  468. dict: A dictionary containing the chat results.
  469. """
  470. key_list = self.format_key(key_list)
  471. key_list_ori = key_list.copy()
  472. if len(key_list) == 0:
  473. return {"error": "输入的key_list无效!"}
  474. if not isinstance(visual_info, list):
  475. visual_info_list = [visual_info]
  476. else:
  477. visual_info_list = visual_info
  478. all_visual_info = self.merge_visual_info_list(visual_info_list)
  479. (
  480. all_normal_text_list,
  481. all_table_text_list,
  482. all_table_html_list,
  483. all_table_nei_text_list,
  484. ) = all_visual_info
  485. final_results = {}
  486. failed_results = ["大模型调用失败", "未知", "未找到关键信息", "None", ""]
  487. if len(key_list) > 0:
  488. related_text = self.get_related_normal_text(
  489. use_vector_retrieval,
  490. vector_info,
  491. key_list,
  492. all_normal_text_list,
  493. min_characters,
  494. )
  495. if len(related_text) > 0:
  496. prompt = self.text_pe.generate_prompt(
  497. related_text,
  498. key_list,
  499. task_description=text_task_description,
  500. output_format=text_output_format,
  501. rules_str=text_rules_str,
  502. few_shot_demo_text_content=text_few_shot_demo_text_content,
  503. few_shot_demo_key_value_list=text_few_shot_demo_key_value_list,
  504. )
  505. self.generate_and_merge_chat_results(
  506. prompt, key_list, final_results, failed_results
  507. )
  508. if len(key_list) > 0:
  509. for table_html, table_text, table_nei_text in zip(
  510. all_table_html_list, all_table_text_list, all_table_nei_text_list
  511. ):
  512. if len(table_html) <= min_characters - self.table_structure_len_max:
  513. for table_info in [table_html]:
  514. if len(key_list) > 0:
  515. if len(table_nei_text) > 0:
  516. table_info = (
  517. table_info + "\n 表格周围文字:" + table_nei_text
  518. )
  519. prompt = self.table_pe.generate_prompt(
  520. table_info,
  521. key_list,
  522. task_description=table_task_description,
  523. output_format=table_output_format,
  524. rules_str=table_rules_str,
  525. few_shot_demo_text_content=table_few_shot_demo_text_content,
  526. few_shot_demo_key_value_list=table_few_shot_demo_key_value_list,
  527. )
  528. self.generate_and_merge_chat_results(
  529. prompt, key_list, final_results, failed_results
  530. )
  531. if self.use_mllm_predict:
  532. final_predict_dict = self.ensemble_ocr_llm_mllm(
  533. key_list_ori, final_results, mllm_predict_dict
  534. )
  535. else:
  536. final_predict_dict = final_results
  537. return {"chat_res": final_predict_dict}
  538. def predict(self, *args, **kwargs) -> None:
  539. logging.error(
  540. "PP-ChatOCRv4-doc Pipeline do not support to call `predict()` directly! Please invoke `visual_predict`, `build_vector`, `chat` sequentially to obtain the result."
  541. )
  542. return