| import requests
|
| import base64
|
| import json
|
| import os
|
|
|
| def test_ppocr():
|
|
|
| url = "http://127.0.0.1:8889/ppocr"
|
| image_path = r"e:\huggingface_echodict\t\PPOCRLLM\data\0022.jpg"
|
|
|
|
|
| if not os.path.exists(image_path):
|
| print(f"Error: Image file not found at {image_path}")
|
| return
|
|
|
| try:
|
|
|
| with open(image_path, "rb") as image_file:
|
| base64_str = base64.b64encode(image_file.read()).decode('utf-8')
|
|
|
|
|
| payload = {
|
| "img": base64_str
|
| }
|
| headers = {
|
| "Content-Type": "application/json"
|
| }
|
|
|
|
|
| print(f"Sending POST request to {url}...")
|
| response = requests.post(url, json=payload, headers=headers)
|
|
|
|
|
| print(f"Status Code: {response.status_code}")
|
| try:
|
| print("Response JSON:")
|
| print(json.dumps(response.json(), indent=4, ensure_ascii=False))
|
| except json.JSONDecodeError:
|
| print("Response Text:")
|
| print(response.text)
|
|
|
| except Exception as e:
|
| print(f"An error occurred: {e}")
|
|
|
| if __name__ == "__main__":
|
| test_ppocr()
|
|
|