Spaces:
Sleeping
Sleeping
Stardragon2099
commited on
Commit
·
45e3fef
1
Parent(s):
886a0b3
ported to chatgpt api
Browse files
app.py
CHANGED
@@ -78,15 +78,16 @@ def predict(img, prompt):
|
|
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"
|
83 |
]
|
84 |
|
85 |
# Make API call
|
86 |
try:
|
87 |
response = openai.ChatCompletion.create(
|
88 |
-
model="gpt-4",
|
89 |
messages=messages,
|
|
|
90 |
)
|
91 |
return response['choices'][0]['message']['content']
|
92 |
except Exception as e:
|
|
|
78 |
# Get the file ID from the upload response
|
79 |
file_id = upload_response['id']
|
80 |
messages = [
|
81 |
+
{"role": "system", "content": prompt + "respond with JSON only"},
|
82 |
+
{"role": "user", "content": f"Image (base64): {image_bytes}"}
|
83 |
]
|
84 |
|
85 |
# Make API call
|
86 |
try:
|
87 |
response = openai.ChatCompletion.create(
|
88 |
+
model="gpt-4-vision-preview",
|
89 |
messages=messages,
|
90 |
+
files=[("file", file_id)]
|
91 |
)
|
92 |
return response['choices'][0]['message']['content']
|
93 |
except Exception as e:
|