test_pp_chatocrv3.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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_demo_imgs/vehicle_certificate-1.png"
  17. # key_list = ['驾驶室准乘人数']
  18. # img_path = "./test_demo_imgs/test_layout_parsing.jpg"
  19. # key_list = ['3.2的标题']
  20. img_path = "./test_demo_imgs/seal_text_det.png"
  21. key_list = ["印章上公司"]
  22. # visual_predict_res = pipeline.visual_predict(img_path,
  23. # use_doc_orientation_classify=True,
  24. # use_doc_unwarping=True,
  25. # use_common_ocr=True,
  26. # use_seal_recognition=True,
  27. # use_table_recognition=True)
  28. # ####[TODO] 增加类别信息
  29. # visual_info_list = []
  30. # for res in visual_predict_res:
  31. # visual_info_list.append(res["visual_info"])
  32. # pipeline.save_visual_info_list(visual_info_list, "./res_visual_info/visual_info3.json")
  33. visual_info_list = pipeline.load_visual_info_list("./res_visual_info/visual_info3.json")
  34. vector_info = pipeline.build_vector(visual_info_list)
  35. print(vector_info)
  36. final_results = pipeline.chat(visual_info_list, key_list, vector_info)
  37. print(final_results)