test_pp_chatocrv3.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. visual_predict_res = pipeline.visual_predict(
  19. img_path,
  20. use_doc_orientation_classify=True,
  21. use_doc_unwarping=True,
  22. use_common_ocr=True,
  23. use_seal_recognition=True,
  24. use_table_recognition=True,
  25. )
  26. # ####[TODO] 增加类别信息
  27. visual_info_list = []
  28. for res in visual_predict_res:
  29. # res['layout_parsing_result'].save_results("./output/")
  30. # print(res["visual_info"])
  31. visual_info_list.append(res["visual_info"])
  32. # pipeline.save_visual_info_list(visual_info_list, "./res_visual_info/tmp_visual_info.json")
  33. # visual_info_list = pipeline.load_visual_info_list("./res_visual_info/tmp_visual_info.json")
  34. vector_info = pipeline.build_vector(visual_info_list)
  35. chat_result = pipeline.chat(key_list, visual_info_list, vector_info=vector_info)
  36. print(chat_result)