|
#!/usr/local/bin/bash |
|
|
|
HF_TOKEN='foobarbaz' |
|
|
|
MODEL='Qwen/Qwen2.5-VL-72B-Instruct' |
|
|
|
USER_CONTENT_TEXT=' |
|
You are a keyword extraction engine. |
|
Your entire response must contain only lowercase English keywords separated by single spaces. |
|
Never explain, never greet, never describe your reasoning. |
|
|
|
Look at the image, including visible text, signs, logos, captions, visual context. |
|
Do not copy text from the image unless it is a generic object/category. |
|
Convert text meaning into concepts. |
|
If the text contains cultural references, include keywords that match the reference. |
|
Return only 1-6 lowercase English semantic keywords |
|
|
|
Examples: |
|
- image: a cat riding a bicycle -> cat bike |
|
- image: a poster saying "May the Force be with you" -> movie |
|
- image: cafe sign with "espresso" -> coffee |
|
' |
|
|
|
IMAGE_URL='https://static.boredpanda.com/blog/wp-content/uploads/2025/10/13-68f22702c7d5e-png__700.jpg' # problem |
|
MAX_TOKENS=48 |
|
|
|
JSON_BODY='{}' |
|
|
|
STR_VALUE="${MODEL}" |
|
JSON_BODY="$(printf '%s' "${JSON_BODY}" | STR_VALUE="${STR_VALUE}" yq -M -p=json -o=json '.model=strenv(STR_VALUE)')" |
|
|
|
STR_VALUE='user' |
|
JSON_BODY="$(printf '%s' "${JSON_BODY}" | STR_VALUE="${STR_VALUE}" yq -M -p=json -o=json '.messages[0].role=strenv(STR_VALUE)')" |
|
|
|
STR_VALUE='text' |
|
JSON_BODY="$(printf '%s' "${JSON_BODY}" | STR_VALUE="${STR_VALUE}" yq -M -p=json -o=json '.messages[0].content[0].type=strenv(STR_VALUE)')" |
|
|
|
STR_VALUE="${USER_CONTENT_TEXT}" |
|
JSON_BODY="$(printf '%s' "${JSON_BODY}" | STR_VALUE="${STR_VALUE}" yq -M -p=json -o=json '.messages[0].content[0].text=strenv(STR_VALUE)')" |
|
|
|
STR_VALUE='image_url' |
|
JSON_BODY="$(printf '%s' "${JSON_BODY}" | STR_VALUE="${STR_VALUE}" yq -M -p=json -o=json '.messages[0].content[1].type=strenv(STR_VALUE)')" |
|
|
|
STR_VALUE="${IMAGE_URL}" |
|
JSON_BODY="$(printf '%s' "${JSON_BODY}" | STR_VALUE="${STR_VALUE}" yq -M -p=json -o=json '.messages[0].content[1].image_url.url=strenv(STR_VALUE)')" |
|
|
|
JSON_BODY="$(printf '%s' "${JSON_BODY}" | yq -M -p=json -o=json ".max_tokens=${MAX_TOKENS}")" |
|
|
|
HF_OUTPUT='.excluded/json/response.json' |
|
rm "${HF_OUTPUT}" |
|
|
|
curl 'https://router.huggingface.co/v1/chat/completions' \ |
|
-H "Authorization: Bearer ${HF_TOKEN}" \ |
|
-H "Content-Type: application/json" \ |
|
-d "${JSON_BODY}" \ |
|
-o "${HF_OUTPUT}" |
|
|
|
yq -P -p=json -o=json "${HF_OUTPUT}" |