#i have an error in analysing a picture and it's not working idk why

3 messages · Page 1 of 1 (latest)

sharp tiger
#

im using the openai api for analysing an image and it's not working

#

import openai
import requests
import json

OpenAI API endpoint for image analysis

url = "https://api.openai.com/v1/images/analyze"
api_key = "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"

The image you want to analyze

image_path = "C:/Users/rouso/OneDrive/Pictures/Screenshot 2023-02-11 131927.png"

Read the image into memory

with open(image_path, "rb") as image:
image_bytes = image.read()

Define the parameters for the image analysis request

model = "image-alpha-001"

Define the headers for the request

headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {api_key}"
}

Define the request body

data = json.dumps({
"model": model,
"image": image_bytes.hex()
})

Make the request to the OpenAI API

response = requests.post(url, headers=headers, data=data)

Check the status code of the response

if response.status_code != 200:
raise ValueError("Failed to analyze image")

Get the generated image analysis

image_analysis = response.json()["data"][0]["features"]

Print the image analysis

print(image_analysis)

loud mauve
#

there is no such functionality on OpenAI API