cutiee82 commited on
Commit
655ad30
·
verified ·
1 Parent(s): db9bbb8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +9 -9
app.py CHANGED
@@ -13,26 +13,26 @@ def image_to_base64(image):
13
  buf = BytesIO()
14
  image.save(buf, "JPEG")
15
  buf.seek(0)
16
- return f"data:image/jpeg;base64,{base64.b64encode(buf.getvalue()).decode()}"
17
 
18
  def caption(image):
19
- out = ""
20
- for chunk in client.chat.completions.create(
21
  model="openai-large",
22
  messages=[
23
  {
24
  "role": "user",
25
  "content": [
26
- {"type": "image", "url": image_to_base64(image)},
 
 
 
27
  {"type": "text", "text": PROMPT}
28
  ]
29
  }
30
  ],
31
- max_tokens=1024,
32
- stream=True
33
- ):
34
- out += chunk.choices[0].delta.content
35
- yield out
36
 
37
  gr.Interface(
38
  caption,
 
13
  buf = BytesIO()
14
  image.save(buf, "JPEG")
15
  buf.seek(0)
16
+ return base64.b64encode(buf.getvalue()).decode("utf-8")
17
 
18
  def caption(image):
19
+ image = image_to_base64(image)
20
+ return client.chat.completions.create(
21
  model="openai-large",
22
  messages=[
23
  {
24
  "role": "user",
25
  "content": [
26
+ {
27
+ "type": "image",
28
+ "image_url": {"url": f"data:image/jpeg;base64,{image}"}
29
+ },
30
  {"type": "text", "text": PROMPT}
31
  ]
32
  }
33
  ],
34
+ max_tokens=1024
35
+ ).choices[0]
 
 
 
36
 
37
  gr.Interface(
38
  caption,