import requests
import json

PAT = 'a1a09aad41aa43abbe23122fa1996544'
USER_ID = 'deepseek-ai'
APP_ID = 'deepseek-ocr'
MODEL_ID = 'DeepSeek-OCR'
MODEL_VERSION_ID = 'c52cf7da9b1c4095b07e2a1ccb842811'
IMAGE_URL = 'https://files.catbox.moe/yzxg7r.png'

url = f"https://api.clarifai.com/v2/users/{USER_ID}/apps/{APP_ID}/models/{MODEL_ID}/versions/{MODEL_VERSION_ID}/outputs"

headers = {
    "Authorization": f"Key {PAT}",
    "Content-Type": "application/json"
}

data = {
    "inputs": [
        {
            "data": {
                "image": {
                    "url": IMAGE_URL
                }
            }
        }
    ]
}

response = requests.post(url, headers=headers, json=data)
print(response.status_code)
if response.status_code == 200:
    res = response.json()
    try:
        print(res['outputs'][0]['data']['text']['raw'])
    except Exception as e:
        print("Parsing output failed:", e)
        print(json.dumps(res, indent=2))
else:
    print(response.text)
