Make emoji support work again with stable diffusion. - annna - Annna the nice friendly bot. HTML git clone git://bitreich.org/annna/ git://enlrupgkhuxnvlhsf6lc3fziv5h2hhfrinws65d7roiv6bfj7d652fid.onion/annna/ DIR Log DIR Files DIR Refs DIR Tags DIR README --- DIR commit eea3e376d4aca6465997b052660b740bbcea84aa DIR parent fa3ed1c3bff3a60cf31a67dcfadf6e7e88daab8e HTML Author: Annna Robert-Houdin <annna@bitreich.org> Date: Sat, 21 Oct 2023 15:19:48 +0200 Make emoji support work again with stable diffusion. Diffstat: M annna-message-common | 2 +- A stable-diffusion | 18 ++++++++++++++++++ A stable-diffusion-emoji | 36 +++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 1 deletion(-) --- DIR diff --git a/annna-message-common b/annna-message-common @@ -47,7 +47,7 @@ case "${text}" in ;; *::*::*) query=${text#**::} query=${query%%::*} - annna-say -s "${server}" -c "${channel}" "$(dalle-gen-emoji "${query}")" & + annna-say -s "${server}" -c "${channel}" "$(stable-diffusion-emoji "${query}")" & ;; *http*://*|*ytdl://*) case "${text}" in DIR diff --git a/stable-diffusion b/stable-diffusion @@ -0,0 +1,18 @@ +#!/bin/sh + +if [ $# -lt 2 ]; +then + printf "usage: %s output.png some funny cat prompt ...\n" \ + "$(basename "${0}")" >&2 + exit 1 +fi + +sdbase="/br/ai/stable-diffusion.cpp" +sdcmd="${sdbase}/build/bin/sd -t 8" +sdmodel="${sdbase}/v2-1_768-nonema-pruned-ggml-model-f16.bin" +outputf="${1}" +shift 1 + +#${sdcmd} -m ${sdmodel} -o "${outputf}" -p "$@" +${sdcmd} -m ${sdmodel} -o "${outputf}" -p "$@" 2>&1 >/dev/null + DIR diff --git a/stable-diffusion-emoji b/stable-diffusion-emoji @@ -0,0 +1,36 @@ +#!/bin/sh + +if [ $# -lt 1 ]; +then + printf "usage: %s :some:emoji:\n" \ + "$(basename "${0}")" >&2 + exit 1 +fi + +export PATH="$HOME/bin:$PATH" + +emojidb="/br/gopher/emoji" +emojiuribase="gophers://bitreich.org/9/emoji" + +emojistr="$@" +emojiprompt="$(printf "%s\n" "${emojistr}" \ + | sed 's,^::,,' \ + | sed 's,::$,,' \ + | sed 's|,| |g' \ + | sed 's|:| |g' \ + | sed 's|=| |g' \ + | sed 's|/| |g' \ + | sed 's|-| |g' \ + | sed 's|\.| |g')" +emojifile="$(printf "%s\n" "${emojiprompt}" \ + | cut -c -32 \ + | sed 's, ,-,g').png" + +[ -z "${emojiprompt}" ] && exit 1 + +if [ ! -e "${emojidb}/${emojifile}" ]; +then + stable-diffusion "${emojidb}/${emojifile}" "${emojiprompt}" +fi +[ $? -eq 0 ] && printf "gophers://bitreich.org/9/emoji/%s\n" "${emojifile}" +