import requests

# === 替换成你自己的信息 ===
API_TOKEN = "pat_AiScEX8faBuuwaR1mHSuNmA7UnszdqfR7gbHhy6tC3W1iNLA6x74kkNgNGx5mZha"  # Coze 账户的 Token
WORKFLOW_ID = "75342626800955350939"
TESTSET_ID = "你的测试集ID（可选）"
IMAGE_PATH = "your_image.jpg"  # 本地图片路径

# === 上传图片 ===
upload_url = "https://coze.cn/api/open/workflow/upload"
headers = {
    "Authorization": f"Bearer {API_TOKEN}"
}

files = {
    "file": open(IMAGE_PATH, "rb")
}

upload_response = requests.post(upload_url, headers=headers, files=files)
upload_response.raise_for_status()
image_url = upload_response.json()["data"]["url"]

# === 运行 Workflow ===
run_url = f"https://coze.cn/api/open/workflow/run/{WORKFLOW_ID}"

payload = {
    "input": {
        "image": image_url
    },
    # "testset_id": TESTSET_ID,  # 如果有测试集可以加上
    "mode": "image"
}

response = requests.post(run_url, headers=headers, json=payload)
response.raise_for_status()

# === 输出结果 ===
result = response.json()
print("结果:", result)
