File size: 876 Bytes
b13e92e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import base64
import io

import requests
from PIL import Image

API_URL = "https://xt41z6d0qly7bg8w.us-east-1.aws.endpoints.huggingface.cloud"
headers = {
    "Accept": "application/json",
    "Authorization": "Bearer hf_###",
    "Content-Type": "application/json"
}


def query(payload):
    response = requests.post(API_URL, headers=headers, json=payload)
    return response.json()


image_path = 'car_clock.jpg'  # Replace with the path to your image file

# Open the image and convert it to bytes
with Image.open(image_path) as img:
    img_bytes = io.BytesIO()
    img.save(img_bytes, format='JPEG')
    image_bytes = img_bytes.getvalue()
    image_base64 = base64.b64encode(image_bytes).decode('utf-8')

output = query({
    "inputs": {
        "text": "",
        "image": image_base64
    },
    "parameters": {
        "max_new_tokens": 150
    }
})

print(output)