#!/usr/bin/env bash set -o errexit set -o pipefail set -o nounset # Check dependencies if ! command -v ollama &> /dev/null; then echo "Error: 'ollama' is not installed or not in PATH." exit 1 fi if [[ "$#" -ne 1 && "$#" -ne 2 ]]; then echo "Usage: $0 [target_language]" echo "Example: $0 screenshot.png de" exit 1 fi IMAGE_FILE=$(realpath "$1") if [[ ! -f "$IMAGE_FILE" ]]; then echo "Error: File '$IMAGE_FILE' not found." exit 1 fi # Default configuration # pass variables to override parameters, e.g.: WORDS=200 MODE=extended describe-image.sh image.jpg MODEL=${MODEL:-qwen3-vl:8b} MODE=${MODE:-simple} WORDS=${WORDS:-100} TRANSLATION_MODEL=${TRANSLATION_MODEL:-llama3.2} if ! [[ "$WORDS" =~ ^[0-9]+$ ]]; then echo "Error: WORDS must be numeric." >&2 exit 1 fi if [[ "$MODE" != "simple" && "$MODE" != "extended" ]]; then echo "Error: MODE must be either 'simple' or 'extended'." >&2 exit 1 fi PROMPT_SIMPLE="describe image ${IMAGE_FILE}" PROMPT_EXTENDED=$(cat <&2; exit 1; } if [[ "$#" -eq 1 ]]; then echo "$RESULT" exit 0 fi # If a second argument is provided, treat it as the target language TARGET_LANGUAGE="$2" # Map 'de' shortcode to full name for better prompt understanding, optional for others if [[ "$TARGET_LANGUAGE" == "de" || "$TARGET_LANGUAGE" == "DE" ]]; then TARGET_LANGUAGE="German" fi TRANSLATED_RESULT=$(ollama run "$TRANSLATION_MODEL" "Translate the following text to $TARGET_LANGUAGE. Do not add any conversational filler, just provide the translation:\n\n$RESULT") || { echo "Error: ollama failed to translate description." >&2; exit 1; } echo "$TRANSLATED_RESULT"