add alt text generation using ollama llava (local ai)
this might get removed later, if performance on my server is too bad!
This commit is contained in:
@@ -6,7 +6,7 @@ ACCESS_TOKEN="my_bot_token" # Mastodon Access Token
|
||||
SUBREDDIT="memes" # Subreddit (must be Image Only, like r/memes)
|
||||
|
||||
# Fetch the JSON feed
|
||||
json=$(curl -H 'User-Agent: Mozilla/5.0' "https://dhusch.de/rss-bridge/?action=display&bridge=RedditBridge&context=single&r=$SUBREDDIT&f=&score=&d=hot&search=&format=Json" 2>/dev/null)
|
||||
json=$(curl -H 'User-Agent: Mozilla/5.0' "https://bridge.easter.fr/?action=display&bridge=RedditBridge&context=single&r=$SUBREDDIT&f=&score=&d=hot&search=&format=Json" 2>/dev/null)
|
||||
|
||||
# extract the first item
|
||||
item=$(echo "$json" | jq '.items[0]')
|
||||
@@ -15,13 +15,11 @@ item=$(echo "$json" | jq '.items[0]')
|
||||
title=$(echo "$item" | jq -r '.title')
|
||||
url=$(echo "$item" | jq -r '.url')
|
||||
|
||||
# Make sure to stop if the RSS-Bridge is offline or the extraction failed
|
||||
if [ "$url" == "null" ]; then
|
||||
if [ "$url" == "null" ] || [ -z "$url" ]; then # Make sure there is no null posting. Happens when RSS-Bridge gets no Content from Reddit
|
||||
exit 1
|
||||
INSTANCE_URL="https://failed.dhusch.de" # am not sure if the exit actually works. But don't want the Bot to do anything.
|
||||
fi
|
||||
|
||||
|
||||
tags=$(echo "$item" | jq -r '.tags') # Needed for NSFW check
|
||||
|
||||
# extract the image URL from the content_html
|
||||
@@ -33,13 +31,22 @@ wget "$image_url" -N -P /tmp/ # Download the image and save to the output fil
|
||||
|
||||
# Resize Files larger that 8 MB
|
||||
if [ $(du -m /tmp/$filename | awk '{print $1}') -gt 8 ]; then # Check if the file size is greater than 8 MB
|
||||
ffmpeg -i /tmp/$filename -fs 8M /tmp/ff.$filename # Resize the file to 8MB using FFMPEG (needs to be installed)
|
||||
ffmpeg -i /tmp/$filename -fs 8M /tmp/ff.$filename # Resize the file to 8 MB using FFMPEG (needs to be installed)
|
||||
mv /tmp/ff.$filename /tmp/$filename
|
||||
fi
|
||||
|
||||
ffmpeg -i /tmp/$filename /tmp/meme.gen.png
|
||||
|
||||
alt=$(ollama run llava "Describe the meme. do not use more than 1000 characters /tmp/meme.gen.png")
|
||||
ollama stop llava
|
||||
alt=$(echo $alt | sed 's/"//g' | sed 's/^[[:space:]]*//; s/[[:space:]]*$//')
|
||||
echo $alt
|
||||
rm /tmp/meme.gen.png
|
||||
|
||||
# Upload the image and get the media ID
|
||||
MEDIA_ID=$(curl -X POST -H "Authorization: Bearer $ACCESS_TOKEN" \
|
||||
-F "file=@/tmp/$filename" \
|
||||
-F "description=AI generated Alt Text: $alt" \
|
||||
"$INSTANCE_URL/api/v1/media" \
|
||||
| jq -r '.id')
|
||||
|
||||
@@ -56,7 +63,7 @@ else
|
||||
|
||||
# Post the status with the image and make it NSFW
|
||||
curl -X POST -H "Authorization: Bearer $ACCESS_TOKEN" \
|
||||
-F "status=$title
|
||||
-F "status=$title
|
||||
|
||||
($url) #NSFW" \
|
||||
-F "sensitive=true" \
|
||||
|
||||
Reference in New Issue
Block a user