Spaces:
Sleeping
Sleeping
File size: 1,038 Bytes
fe311a3 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
import base64
import requests
import os
from io import BytesIO
from PIL import Image
def encode_image(img):
buffered = BytesIO()
img.save(buffered, format="PNG")
encoded_string = base64.b64encode(buffered.getvalue()).decode("utf-8")
return encoded_string
img = Image.open("./example.jpg")
base64_img = encode_image(img)
api = "https://api.hyperbolic.xyz/v1/chat/completions"
api_key = os.getenv("HYPERBOLIC_API_KEY")
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {api_key}",
}
payload = {
"messages": [{
"role": "user",
"content": [
{"type": "text", "text": "What is in this image?"},
{
"type": "image_url",
"image_url": {"url": f"data:image/jpeg;base64,{base64_img}"},
},
],
}],
"model": "Qwen/Qwen2.5-VL-7B-Instruct",
"max_tokens": 512,
"temperature": 0.1,
"top_p": 0.001,
}
response = requests.post(api, headers=headers, json=payload)
print(response.json())
|