File size: 1,293 Bytes
4f3f873 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | import requests
import base64
import json
import os
def test_ppocr():
# Configuration
url = "http://127.0.0.1:8889/ppocr"
image_path = r"e:\huggingface_echodict\t\PPOCRLLM\data\0022.jpg"
# Check if image exists
if not os.path.exists(image_path):
print(f"Error: Image file not found at {image_path}")
return
try:
# Read and encode image
with open(image_path, "rb") as image_file:
base64_str = base64.b64encode(image_file.read()).decode('utf-8')
# Prepare payload
payload = {
"img": base64_str
}
headers = {
"Content-Type": "application/json"
}
# Send request
print(f"Sending POST request to {url}...")
response = requests.post(url, json=payload, headers=headers)
# Print result
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()
|