from openai import OpenAI
import base64
import os
client = OpenAI(
api_key="sk-***", # 🔑 AiHubMix 키로 교체하세요
base_url="https://aihubmix.com/v1",
)
image_path = "yourpath/file.png"
def encode_image(image_path):
if not os.path.exists(image_path):
raise FileNotFoundError(f"이미지 파일이 존재하지 않습니다: {image_path}")
with open(image_path, "rb") as image_file:
return base64.b64encode(image_file.read()).decode('utf-8')
# 이미지의 base64 인코딩 가져오기
base64_image = encode_image(image_path)
completion = client.chat.completions.create(
model="qwen2.5-vl-72b-instruct", #qwen2.5-vl-72b-instruct OR Qwen/QVQ-72B-Preview
messages=[
{
"role": "user",
"content": [
{"type": "text", "text": "이 이미지를 자세히 설명해주세요"},
{
"type": "image_url",
"image_url": {
"url": f"data:image/png;base64,{base64_image}"
}
}
]
}
],
stream=True
)
for chunk in completion:
if hasattr(chunk.choices, '__len__') and len(chunk.choices) > 0:
if hasattr(chunk.choices[0].delta, 'content') and chunk.choices[0].delta.content is not None:
print(chunk.choices[0].delta.content, end="")