Spaces:
Running
Running
Stardragon2099
commited on
Commit
·
c7d73b1
1
Parent(s):
641b8ed
ported to chatgpt api
Browse files
app.py
CHANGED
@@ -69,7 +69,14 @@ def predict(img, prompt):
|
|
69 |
# "You are an AI that can process text and images. The user has uploaded an image encoded in base64 "
|
70 |
# "format along with a text prompt. You need to consider both the image and the text while responding."
|
71 |
# )
|
|
|
|
|
|
|
|
|
|
|
72 |
|
|
|
|
|
73 |
messages = [
|
74 |
{"role": "system", "content": prompt},
|
75 |
{"role": "user", "content": f"Image (base64): {image_bytes}"}
|
@@ -80,7 +87,7 @@ def predict(img, prompt):
|
|
80 |
response = openai.ChatCompletion.create(
|
81 |
model="gpt-4-vision",
|
82 |
messages=messages,
|
83 |
-
files=[("file",
|
84 |
)
|
85 |
return response['choices'][0]['message']['content']
|
86 |
except Exception as e:
|
|
|
69 |
# "You are an AI that can process text and images. The user has uploaded an image encoded in base64 "
|
70 |
# "format along with a text prompt. You need to consider both the image and the text while responding."
|
71 |
# )
|
72 |
+
# Upload the image to OpenAI as a file
|
73 |
+
upload_response = openai.File.create(
|
74 |
+
file=image_bytes,
|
75 |
+
purpose='answers' # Purpose can be 'answers' or 'fine-tune', depending on your use case
|
76 |
+
)
|
77 |
|
78 |
+
# Get the file ID from the upload response
|
79 |
+
file_id = upload_response['id']
|
80 |
messages = [
|
81 |
{"role": "system", "content": prompt},
|
82 |
{"role": "user", "content": f"Image (base64): {image_bytes}"}
|
|
|
87 |
response = openai.ChatCompletion.create(
|
88 |
model="gpt-4-vision",
|
89 |
messages=messages,
|
90 |
+
files=[("file", file_id)]
|
91 |
)
|
92 |
return response['choices'][0]['message']['content']
|
93 |
except Exception as e:
|