import base64
import json
import mimetypes
from pathlib import Path

import requests


API_URL = "http://192.168.0.46:59091/split_image"
IMAGE_PATH = r"E:\ZKYNLP\gonwgendoc\gwdoc\c37e4471-9551-4264-8126-f5f07db2e9d9.png"

image_path = Path(IMAGE_PATH)
mime_type = mimetypes.guess_type(image_path.name)[0] or "image/png"

with open(image_path, "rb") as f:
    image_base64 = base64.b64encode(f.read()).decode("utf-8")

payload = {
    "filename": image_path.name,
    "content": "这是测试图片的上下文说明",
    "image_base64": f"data:{mime_type};base64,{image_base64}",
}

response = requests.post(API_URL, json=payload, timeout=120)

print("status:", response.status_code)
try:
    print(json.dumps(response.json(), ensure_ascii=False, indent=2))
except Exception:
    print(response.text)