Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -8,8 +8,8 @@ openai.api_key = "sk-proj-5dz7SFb-o3321NRgrOHA-dGoPxcuQ_fbSLtEm4GCak5x3PU-zC_QQi
|
|
8 |
def generate_caption(image):
|
9 |
"""Generate a caption for the uploaded image using OpenAI's GPT-4 Vision API."""
|
10 |
with open(image, "rb") as img_file:
|
11 |
-
response = openai.
|
12 |
-
model="gpt-4-
|
13 |
messages=[
|
14 |
{
|
15 |
"role": "system",
|
@@ -19,14 +19,14 @@ def generate_caption(image):
|
|
19 |
"role": "user",
|
20 |
"content": [
|
21 |
{"type": "text", "text": "Describe the contents of this image in detail."},
|
22 |
-
{"type": "
|
23 |
],
|
24 |
},
|
25 |
],
|
26 |
max_tokens=100
|
27 |
)
|
28 |
-
|
29 |
-
caption = response
|
30 |
return caption
|
31 |
|
32 |
# Gradio UI
|
|
|
8 |
def generate_caption(image):
|
9 |
"""Generate a caption for the uploaded image using OpenAI's GPT-4 Vision API."""
|
10 |
with open(image, "rb") as img_file:
|
11 |
+
response = openai.chat.completions.create(
|
12 |
+
model="gpt-4-turbo",
|
13 |
messages=[
|
14 |
{
|
15 |
"role": "system",
|
|
|
19 |
"role": "user",
|
20 |
"content": [
|
21 |
{"type": "text", "text": "Describe the contents of this image in detail."},
|
22 |
+
{"type": "image_url", "image_url": {"url": "data:image/jpeg;base64," + img_file.read().decode()}},
|
23 |
],
|
24 |
},
|
25 |
],
|
26 |
max_tokens=100
|
27 |
)
|
28 |
+
|
29 |
+
caption = response.choices[0].message.content
|
30 |
return caption
|
31 |
|
32 |
# Gradio UI
|