-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgpt_api_img_test.py
More file actions
41 lines (32 loc) · 915 Bytes
/
gpt_api_img_test.py
File metadata and controls
41 lines (32 loc) · 915 Bytes
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
import base64
from openai import OpenAI
client = OpenAI(
api_key="OPEN_AI_KEY",
)
# Function to encode the image
def encode_image(image_path):
with open(image_path, "rb") as image_file:
return base64.b64encode(image_file.read()).decode("utf-8")
# Path to your image
image_path = "./data/test.jpg"
# Getting the Base64 string
base64_image = encode_image(image_path)
prompt="이 사진에 대해 설명해줘"
completion = client.chat.completions.create(
model="gpt-4o",
messages=[
{
"role": "user",
"content": [
{ "type": "text", "text": prompt },
{
"type": "image_url",
"image_url": {
"url": f"data:image/jpeg;base64,{base64_image}",
},
},
],
}
],
)
print(completion.choices[0].message.content)