kaoqinbiao_ocr.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import base64
  2. import os
  3. import requests
  4. API_URL = "https://q8d4u1u6c45dn7pd.aistudio-app.com/layout-parsing"
  5. TOKEN = "16455708d55afac2f074f4ae5a88fc6c7bae7920"
  6. file_path = "E:\\project\\arbitration_system\\evidence_extractor\\test\\F86-ZC1-2023-0001\\证人证言\\F86-ZC1-2023-0001-009_04.png"
  7. with open(file_path, "rb") as file:
  8. file_bytes = file.read()
  9. file_data = base64.b64encode(file_bytes).decode("ascii")
  10. headers = {
  11. "Authorization": f"token {TOKEN}",
  12. "Content-Type": "application/json"
  13. }
  14. payload = {
  15. "file": file_data,
  16. "fileType": 1,
  17. "useDocOrientationClassify": False,
  18. "useDocUnwarping": False,
  19. "useChartRecognition": False,
  20. }
  21. response = requests.post(API_URL, json=payload, headers=headers)
  22. print(f"响应状态码: {response.status_code}")
  23. if response.status_code == 200:
  24. result = response.json()["result"]
  25. # 提取 parsing_res_list
  26. for layout_result in result.get("layoutParsingResults", []):
  27. pruned_result = layout_result.get("prunedResult", {})
  28. parsing_res_list = pruned_result.get("parsing_res_list", [])
  29. if parsing_res_list:
  30. print("\n=== parsing_res_list ===")
  31. print(parsing_res_list)
  32. else:
  33. print(f"请求失败,状态码: {response.status_code}")