Spaces:
Sleeping
Sleeping
Juho Inkinen
commited on
Commit
·
034f47f
1
Parent(s):
bc4258e
Use proper prompt
Browse files
app.py
CHANGED
|
@@ -22,7 +22,7 @@ else:
|
|
| 22 |
annif = AnnifClient()
|
| 23 |
|
| 24 |
|
| 25 |
-
def get_caption(image):
|
| 26 |
# Convert image to base64 JPEG
|
| 27 |
import io
|
| 28 |
import base64
|
|
@@ -38,7 +38,7 @@ def get_caption(image):
|
|
| 38 |
{
|
| 39 |
"role": "user",
|
| 40 |
"content": [
|
| 41 |
-
{"type": "text", "text":
|
| 42 |
{
|
| 43 |
"type": "image_url",
|
| 44 |
"image_url": {"url": f"data:image/jpeg;base64,{img_b64}"},
|
|
@@ -74,7 +74,13 @@ def get_subjects(caption, project_id):
|
|
| 74 |
|
| 75 |
|
| 76 |
def process_image(image, project_id):
|
| 77 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
subjects = get_subjects(caption, project_id)
|
| 79 |
return image, caption, subjects
|
| 80 |
|
|
|
|
| 22 |
annif = AnnifClient()
|
| 23 |
|
| 24 |
|
| 25 |
+
def get_caption(image, prompt):
|
| 26 |
# Convert image to base64 JPEG
|
| 27 |
import io
|
| 28 |
import base64
|
|
|
|
| 38 |
{
|
| 39 |
"role": "user",
|
| 40 |
"content": [
|
| 41 |
+
{"type": "text", "text": prompt},
|
| 42 |
{
|
| 43 |
"type": "image_url",
|
| 44 |
"image_url": {"url": f"data:image/jpeg;base64,{img_b64}"},
|
|
|
|
| 74 |
|
| 75 |
|
| 76 |
def process_image(image, project_id):
|
| 77 |
+
prompt = (
|
| 78 |
+
"Generate an alt-text description, which is a description for people who can't see the image. "
|
| 79 |
+
"Be sure to talk about the actual contents of it, do not interpret anything. "
|
| 80 |
+
"Start with a general description, then focus on details. Answer only with the "
|
| 81 |
+
"alt-text description, do not include 'Here's an alt-text description', explanations or subheadings."
|
| 82 |
+
)
|
| 83 |
+
caption = get_caption(image, prompt)
|
| 84 |
subjects = get_subjects(caption, project_id)
|
| 85 |
return image, caption, subjects
|
| 86 |
|