Created
May 17, 2026 18:56
-
-
Save kepocnhh/6f7ef814cdcff491934e510abe4b3a50 to your computer and use it in GitHub Desktop.
huggingface image to text url
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/local/bin/bash | |
| HF_TOKEN='foobarbaz' | |
| MODEL='CohereLabs/aya-vision-32b:cohere' | |
| ROLE='user' | |
| CONTENT_TEXT='Describe this image. Keep it to 512 characters.' | |
| IMAGE_URL='https://static.boredpanda.com/blog/wp-content/uploads/2025/10/18-68efabda89790__700.jpg' # wake up | |
| MAX_TOKENS=128 | |
| 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="${ROLE}" | |
| 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="${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}")" | |
| echo 'Request:' | |
| echo "${JSON_BODY}" | yq -P -p=json -o=json | |
| echo 'Response:' | |
| 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}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment