add gemini powered clock styling

This commit is contained in:
end-4
2025-10-13 11:24:02 +02:00
parent 78723402ee
commit 5dedbf91e0
6 changed files with 141 additions and 6 deletions
@@ -0,0 +1,48 @@
#!/usr/bin/env bash
if [[ -z "$1" ]]; then
echo "Usage: $0 <image_path>"
exit 1
fi
SOURCE_IMG_PATH="$1"
WALLPAPER_NAME="$(basename "$SOURCE_IMG_PATH")"
RESIZED_IMG_PATH="/tmp/quickshell/ai/wallpaper.jpg"
magick "$SOURCE_IMG_PATH" -resize 200x -quality 50 "$RESIZED_IMG_PATH"
API_KEY=$(secret-tool lookup 'application' 'illogical-impulse' | jq -r '.apiKeys.gemini')
if [[ "$(base64 --version 2>&1)" = *"FreeBSD"* ]]; then
B64FLAGS="--input"
else
B64FLAGS="-w0"
fi
payload='{
"contents": [{
"parts":[
{
"inline_data": {
"mime_type":"image/jpeg",
"data": "'"$(base64 $B64FLAGS $RESIZED_IMG_PATH)"'"
}
},
{"text": "Categorize the wallpaper. Its file name is '"$WALLPAPER_NAME"'"}
]
}],
"generationConfig": {
"responseMimeType": "text/x.enum",
"responseSchema": {
"type": "string",
"enum": [ "abstract", "anime", "city", "minimalist", "landscape", "plants", "person", "space" ]
},
"temperature": 0,
}
}'
# echo "$payload" | jq
response=$(curl "https://generativelanguage.googleapis.com/v1beta/models/gemini-2.0-flash:generateContent" \
-H "x-goog-api-key: $API_KEY" \
-H 'Content-Type: application/json' \
-X POST \
-d "$payload" 2> /dev/null)
echo "$response" | jq -r '.candidates[0].content.parts[0].text'
@@ -171,6 +171,13 @@ switch() {
type_flag="$3"
color_flag="$4"
color="$5"
# Start Gemini auto-categorization if enabled
aiStylingEnabled=$(jq -r '.background.clock.cookie.aiStyling' "$SHELL_CONFIG_FILE")
if [[ "$aiStylingEnabled" == "true" ]]; then
"$SCRIPT_DIR/../ai/gemini-categorize-wallpaper.sh" "$imgpath" > "$STATE_DIR/user/generated/wallpaper/category.txt" &
fi
read scale screenx screeny screensizey < <(hyprctl monitors -j | jq '.[] | select(.focused) | .scale, .x, .y, .height' | xargs)
cursorposx=$(hyprctl cursorpos -j | jq '.x' 2>/dev/null) || cursorposx=960
cursorposx=$(bc <<< "scale=0; ($cursorposx - $screenx) * $scale / 1")