Ujeshhh commited on
Commit
3c6c0fd
·
verified ·
1 Parent(s): 07fb6d9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
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.ChatCompletion.create(
12
- model="gpt-4-vision-preview",
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": "image", "image": img_file.read()},
23
  ],
24
  },
25
  ],
26
  max_tokens=100
27
  )
28
-
29
- caption = response["choices"][0]["message"]["content"]
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