test_pp_chatocrv3.py 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 paddlex import create_pipeline
  15. pipeline = create_pipeline(pipeline="PP-ChatOCRv3-doc")
  16. img_path = "./test_samples/vehicle_certificate-1.png"
  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. # ####[TODO] 增加类别信息
  29. visual_info_list = []
  30. for res in visual_predict_res:
  31. # res['layout_parsing_result'].save_results("./output/")
  32. # print(res["visual_info"])
  33. visual_info_list.append(res["visual_info"])
  34. pipeline.save_visual_info_list(
  35. visual_info_list, "./res_visual_info/tmp_visual_info.json"
  36. )
  37. visual_info_list = pipeline.load_visual_info_list(
  38. "./res_visual_info/tmp_visual_info.json"
  39. )
  40. vector_info = pipeline.build_vector(visual_info_list)
  41. pipeline.save_vector(vector_info, "./res_visual_info/tmp_vector_info.json")
  42. vector_info = pipeline.load_vector("./res_visual_info/tmp_vector_info.json")
  43. chat_result = pipeline.chat(key_list, visual_info_list, vector_info=vector_info)
  44. print(chat_result)