am using gpt-4o model
am trying to ask some ocr questions regarding that image.
When am using api , am getting some spelling mistakes.
But in the playground getting the correct answer.
May be i think this is because of the image resolution after converting to base 64
I need help regarding this problem.
import openai
import base64
import csv
import re
import json
# Set up your OpenAI API key
openai.api_key = 'sk-**************'
# Path to the image file
image_path = '/path_of_the_image.png'
# Function to read image and convert to base64
def image_to_base64(image_path):
with open(image_path, "rb") as image_file:
encoded_string = base64.b64encode(image_file.read()).decode('utf-8')
return encoded_string
# Path to the image
# Convert image to base64
image_base64 = image_to_base64(image_path)
# Define the prompt
prompt = """PCN,Patient ID,Patient Full Name,Claim ID,Paid Amount,Extract the data of all the rows from the image and map with the above columns in json format.
```json
{
"PCN": "",
"Patient ID": "32357",
"Patient Full Name": "xyz",
"Claim ID": "12345678",
"Paid Amount": "0.00",
}
"""
# Make the API call
response = openai.ChatCompletion.create(
model="gpt-4o",
messages=[
{"role": "system", "content": "Act as a Data Entry Agent and extract the data from the image."},
{"role": "user", "content": prompt},
{"role": "user", "content": [{"type": "image_url", "image_url": {"url": f"data:image/jpeg;base64,{image_base64}"}}]}
],
temperature=0,
max_tokens=4095,
top_p=1,
frequency_penalty=0,
presence_penalty=0
)
# Print the response
json_data = response['choices'][0]['message']['content']
# print(response['choices'][0]['message']['content'])
print(json_data)