I am using Anvil.works to create a small application to identify furniture. i keep getting an error when I try to save a new image in my UI, save it to the datatable and retrieve the URL from my data table so ChatGPT can use the URL to identify the furniture in the image.
Client Side
def button_save_click(self, **event_args):
"""This method is called when the button is clicked"""
self.image_uploadedFile.source = self.file_loader_Office.file
roomImg = self.file_loader_Office.file
imgID = anvil.server.call('saveFile',roomImg)
self.text_area_chatGPTOutput.text = anvil.server.call('definingPicture',imgID)
pass
Server Side
@anvil.server.callable
def saveFile(roomImg):
row = app_tables.maindata.add_row(usersEmail=anvil.users.get_user()['email'],Office=roomImg)
rowId = row.get_id()
return rowId
@anvil.server.callable
def definingPicture(imgID):
imgRow = app_tables.maindata.get_by_id(imgID)
Img = imgRow['Office']
#ImgUrl= Img.get_url(False)
#modified_url = ImgUrl[:-3]
#print(modified_url)
print(Img.get_url(False))
response = client.chat.completions.create(
model="gpt-4-vision-preview",
messages=[
{
"role": "user",
"content": [
{"type": "text", "text": "identify all the furniture in the room"},
{
"type": "image_url",
"image_url": {
"url": Img.get_url(False),
},
},
],
}
],
max_tokens=700,
)
return response.choices[0].message.content
For some reason ChatGPT is giving me this error message.
BadRequestError: Error code: 400 - {'error': {'message': 'Invalid image.', 'type': 'invalid_request_error', 'param': None, 'code': None}}
at /home/anvil/.env/lib/python3.10/site-packages/openai/_base_client.py:930
called from /home/anvil/.env/lib/python3.10/site-packages/openai/_base_client.py:853
called from /home/anvil/.env/lib/python3.10/site-packages/openai/_base_client.py:1088
called from /home/anvil/.env/lib/python3.10/site-packages/openai/resources/chat/completions.py:645
called from /home/anvil/.env/lib/python3.10/site-packages/openai/_utils/_utils.py:270
called from Main, line 37
called from Form1, line 26
For the life of me I cannot figure out what I am doing wrong… Any help on this is greatly appreciated. I am still relatively new