|
import requests |
|
import base64 |
|
|
|
|
|
HF_TOKEN = "hf_<>" |
|
HF_ENDPOINT = "https://" |
|
|
|
|
|
def encode_image(image_path): |
|
with open(image_path, "rb") as f: |
|
return base64.b64encode(f.read()).decode("utf-8") |
|
|
|
|
|
image_base64 = encode_image("./test.png") |
|
payload = { |
|
"inputs": { |
|
"image": image_base64, |
|
"convs": [ |
|
{"role": "system", "content": "You are agent that can see, talk and act."}, |
|
{"role": "user", "content": "<image_start><image><image_end>\nWhat is in this image?"} |
|
] |
|
} |
|
} |
|
|
|
|
|
headers = { |
|
"Accept" : "application/json", |
|
"Content-Type": "application/json", |
|
"Authorization": f"Bearer {HF_TOKEN}", |
|
} |
|
response = requests.post(HF_ENDPOINT, headers=headers, json=payload) |
|
|
|
|
|
if response.status_code == 200: |
|
print("Response:", response.json()) |
|
else: |
|
print("Error:", response.status_code, response.text) |