import base64 import openai from dotenv import load_dotenv, find_dotenv _ = load_dotenv(find_dotenv()) client = openai.Client() def encode_image(caminho_imagem): with open(caminho_imagem, 'rb' ) as img: return base64.b64encode(img.read()).decode('utf-8') caminho = 'arquivos/vision/celulas.jpg' base_64_img = encode_image(caminho) resposta = client.chat.completions.create( model='gpt-4-vision-preview', messages=[{ 'role': 'user', 'content': [ {'type': 'text', 'text': 'Quantas células aparecem na imagem?'}, {'type': 'image_url', 'image_url': {'url': f'data:image/jpg;base64,{base_64_img}'}} ] }], max_tokens=1000, ) print(resposta.choices[0].message.content)