-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfuyu-8b.py
44 lines (35 loc) · 992 Bytes
/
fuyu-8b.py
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
import requests, base64
import os
from dotenv import load_dotenv
load_dotenv()
api_key = os.getenv('API_KEY_FUYU')
invoke_url = "https://ai.api.nvidia.com/v1/vlm/adept/fuyu-8b"
stream = True
with open("assets/images/image.jpg", "rb") as f:
image_b64 = base64.b64encode(f.read()).decode()
assert len(image_b64) < 180_000, \
"To upload larger images, use the assets API (see docs)"
headers = {
"Authorization": "Bearer "+api_key,
"Accept": "text/event-stream" if stream else "application/json"
}
payload = {
"messages": [
{
"role": "user",
"content": f'What do you see in the following image? <img src="data:image/png;base64,{image_b64}" />'
}
],
"max_tokens": 1024,
"temperature": 0.20,
"top_p": 0.70,
"seed": 0,
"stream": stream
}
response = requests.post(invoke_url, headers=headers, json=payload)
if stream:
for line in response.iter_lines():
if line:
print(line.decode("utf-8"))
else:
print(response.json())