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()