| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- import os
- import re
- import base64
- import requests
- import config
- API_URL = "https://q2z8becfm967o4y7.aistudio-app.com/layout-parsing"
- TOKEN = "16455708d55afac2f074f4ae5a88fc6c7bae7920"
- file_path = "E:\\project\\arbitration_system\\appplication_extractor\\test\\刘正新\\刘正新-申请书.png"
- input_filename = os.path.splitext(os.path.basename(file_path))[0]
- with open(file_path, "rb") as file:
- file_bytes = file.read()
- file_data = base64.b64encode(file_bytes).decode("ascii")
- headers = {
- "Authorization": f"token {TOKEN}",
- "Content-Type": "application/json"
- }
- required_payload = {
- "file": file_data,
- "fileType": 1,
- }
- optional_payload = {
- "useDocOrientationClassify": False,
- "useDocUnwarping": False,
- "useTextlineOrientation": False,
- }
- payload = {**required_payload, **optional_payload}
- response = requests.post(API_URL, json=payload, headers=headers)
- assert response.status_code == 200
- result = response.json()["result"]
- os.makedirs("../PP-OCRv5/output", exist_ok=True)
- # 如果需要处理多个页面
- for i, res in enumerate(result.get("ocrResults", [])):
- if "prunedResult" in res:
- pruned_result = res["prunedResult"]
- if "rec_texts" in pruned_result:
- print(f"\n=== 页面 {i + 1} 的识别文本 ===")
- result_text = ""
- for j, text in enumerate(pruned_result["rec_texts"]):
- result_text = result_text+"\n"+text
- print(result_text)
|