test_pp_chatocrv4.py 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. from paddlex import create_pipeline
  15. pipeline = create_pipeline(pipeline="PP-ChatOCRv4-doc")
  16. img_path = "./test_samples/研报2_11.jpg"
  17. key_list = ["三位一体养老生态系统包含哪些"]
  18. # img_path = "./test_samples/财报1.pdf"
  19. # key_list = ['公司全称是什么']
  20. visual_predict_res = pipeline.visual_predict(
  21. img_path,
  22. use_doc_orientation_classify=False,
  23. use_doc_unwarping=False,
  24. use_common_ocr=True,
  25. use_seal_recognition=True,
  26. use_table_recognition=True,
  27. )
  28. visual_info_list = []
  29. for res in visual_predict_res:
  30. visual_info_list.append(res["visual_info"])
  31. layout_parsing_result = res["layout_parsing_result"]
  32. print(layout_parsing_result)
  33. layout_parsing_result.print()
  34. layout_parsing_result.save_to_img("./output")
  35. layout_parsing_result.save_to_json("./output")
  36. layout_parsing_result.save_to_xlsx("./output")
  37. layout_parsing_result.save_to_html("./output")
  38. pipeline.save_visual_info_list(
  39. visual_info_list, "./res_visual_info/tmp_visual_info.json"
  40. )
  41. visual_info_list = pipeline.load_visual_info_list(
  42. "./res_visual_info/tmp_visual_info.json"
  43. )
  44. vector_info = pipeline.build_vector(visual_info_list, flag_save_bytes_vector=True)
  45. pipeline.save_vector(vector_info, "./res_visual_info/tmp_vector_info.json")
  46. vector_info = pipeline.load_vector("./res_visual_info/tmp_vector_info.json")
  47. mllm_predict_res = pipeline.mllm_pred(input=img_path, key_list=key_list)
  48. mllm_predict_info = mllm_predict_res["mllm_res"]
  49. chat_result = pipeline.chat(
  50. key_list,
  51. visual_info_list,
  52. vector_info=vector_info,
  53. mllm_predict_info=mllm_predict_info,
  54. )
  55. print(chat_result)