Update app.py
Browse files
app.py
CHANGED
@@ -15,7 +15,7 @@ def image_to_base64(image):
|
|
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",
|
@@ -27,7 +27,7 @@ def caption(image):
|
|
27 |
"type": "image_url",
|
28 |
"image_url": {"url": f"data:image/jpeg;base64,{image}"}
|
29 |
},
|
30 |
-
{"type": "text", "text":
|
31 |
]
|
32 |
}
|
33 |
],
|
@@ -36,6 +36,10 @@ def caption(image):
|
|
36 |
|
37 |
gr.Interface(
|
38 |
caption,
|
39 |
-
inputs=
|
40 |
-
|
|
|
|
|
|
|
|
|
41 |
).launch(debug=True)
|
|
|
15 |
buf.seek(0)
|
16 |
return base64.b64encode(buf.getvalue()).decode("utf-8")
|
17 |
|
18 |
+
def caption(image, prompt):
|
19 |
image = image_to_base64(image)
|
20 |
return client.chat.completions.create(
|
21 |
model="openai-large",
|
|
|
27 |
"type": "image_url",
|
28 |
"image_url": {"url": f"data:image/jpeg;base64,{image}"}
|
29 |
},
|
30 |
+
{"type": "text", "text": prompt}
|
31 |
]
|
32 |
}
|
33 |
],
|
|
|
36 |
|
37 |
gr.Interface(
|
38 |
caption,
|
39 |
+
inputs=[
|
40 |
+
gr.Image(type="pil", label="Image"),
|
41 |
+
gr.Textbox(label="Prompt", value=PROMPT)
|
42 |
+
],
|
43 |
+
outputs=gr.Textbox(label="Caption"),
|
44 |
+
title="Image Captioning"
|
45 |
).launch(debug=True)
|