test_pp_chatocrv3.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. # img_path = "./badcase_images/circle_Aug06850_1.jpg"
  23. # key_list = ['印章名称', '印章编号']
  24. visual_predict_res = pipeline.visual_predict(
  25. img_path,
  26. use_doc_orientation_classify=False,
  27. use_doc_unwarping=False,
  28. use_common_ocr=True,
  29. use_seal_recognition=True,
  30. use_table_recognition=True,
  31. )
  32. # ####[TODO] 增加类别信息
  33. visual_info_list = []
  34. for res in visual_predict_res:
  35. # res['layout_parsing_result'].save_results("./output/")
  36. # print(res["visual_info"])
  37. visual_info_list.append(res["visual_info"])
  38. # pipeline.save_visual_info_list(visual_info_list, "./res_visual_info/tmp_visual_info.json")
  39. # visual_info_list = pipeline.load_visual_info_list("./res_visual_info/tmp_visual_info.json")
  40. vector_info = pipeline.build_vector(visual_info_list)
  41. chat_result = pipeline.chat(key_list, visual_info_list, vector_info=vector_info)
  42. print(chat_result)