Update app.py
Browse files
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
|
17 |
|
18 |
def caption(image):
|
19 |
-
|
20 |
-
|
21 |
model="openai-large",
|
22 |
messages=[
|
23 |
{
|
24 |
"role": "user",
|
25 |
"content": [
|
26 |
-
{
|
|
|
|
|
|
|
27 |
{"type": "text", "text": PROMPT}
|
28 |
]
|
29 |
}
|
30 |
],
|
31 |
-
max_tokens=1024
|
32 |
-
|
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,
|