stockholm/krebs/5pkgs/simple/stable-generate/default.nix

33 lines
601 B
Nix
Raw Normal View History

2022-11-21 14:07:31 +00:00
{ pkgs, lib, ... }:
2022-11-21 13:28:25 +00:00
2022-12-13 13:44:22 +00:00
pkgs.writers.writeBashBin "stable-generate" ''
2022-11-21 13:28:25 +00:00
set -efu
2022-11-21 14:07:31 +00:00
export PATH=${lib.makeBinPath [
2022-12-13 13:44:22 +00:00
pkgs.coreutils
2022-11-21 14:07:31 +00:00
pkgs.curl
pkgs.jq
]}
2022-11-21 13:28:25 +00:00
STABLE_URL=''${STABLE_URL:-http://stable-confusion.r}
2022-12-13 13:44:22 +00:00
PAYLOAD=$(jq -cn --arg prompt "$*" '{
prompt: $prompt
}')
2022-11-21 13:28:25 +00:00
2022-12-13 13:44:22 +00:00
filename=$(mktemp)
curl -Ssf "$STABLE_URL/sdapi/v1/txt2img" \
2022-11-21 13:28:25 +00:00
-X POST \
--Header 'Content-Type: application/json' \
2022-12-13 13:44:22 +00:00
--data "$PAYLOAD" |
jq -r '.images[0]' |
base64 --decode > "$filename"
2022-11-21 13:28:25 +00:00
2022-12-13 13:44:22 +00:00
if test -t 1; then
echo "$filename"
else
cat "$filename"
rm "$filename"
fi
2022-11-21 13:28:25 +00:00
''