aboutsummaryrefslogtreecommitdiffstats
path: root/desktop/companion/gen-frames
diff options
context:
space:
mode:
Diffstat (limited to 'desktop/companion/gen-frames')
-rwxr-xr-xdesktop/companion/gen-frames26
1 files changed, 17 insertions, 9 deletions
diff --git a/desktop/companion/gen-frames b/desktop/companion/gen-frames
index 75e6655..df78cb9 100755
--- a/desktop/companion/gen-frames
+++ b/desktop/companion/gen-frames
@@ -44,10 +44,12 @@ while (($#)); do
esac
done
-# frames.txt to "output<TAB>reference<TAB>prompt" lines, variables expanded.
+# frames.txt to "output<TAB>references<TAB>prompt" lines, variables expanded.
+# References are joined with + and no spaces: the first is the image edited,
+# any after it are extra images the prompt can point at ("the second image").
parse() {
local line name out ref prompt
- local frame='^[[:space:]]*([a-z0-9/_-]+)[[:space:]]*<-[[:space:]]*([a-z0-9/_-]+)[[:space:]]*:[[:space:]]*(.*)$'
+ local frame='^[[:space:]]*([a-z0-9/_-]+)[[:space:]]*<-[[:space:]]*([a-z0-9/_-]+([[:space:]]*\+[[:space:]]*[a-z0-9/_-]+)*)[[:space:]]*:[[:space:]]*(.*)$'
declare -A vars=()
while IFS= read -r line || [[ -n $line ]]; do
[[ $line =~ ^[[:space:]]*(#|$) ]] && continue
@@ -59,7 +61,7 @@ parse() {
echo "gen-frames: frames.txt: cannot read: $line" >&2
exit 1
fi
- out=${BASH_REMATCH[1]} ref=${BASH_REMATCH[2]} prompt=${BASH_REMATCH[3]}
+ out=${BASH_REMATCH[1]} ref=${BASH_REMATCH[2]// /} prompt=${BASH_REMATCH[4]}
for name in "${!vars[@]}"; do prompt=${prompt//\$\{$name\}/${vars[$name]}}; done
if [[ $prompt == *'${'* ]]; then
echo "gen-frames: frames.txt: $out: undefined variable in: $prompt" >&2
@@ -106,16 +108,22 @@ trap 'rm -rf "$tmp"' EXIT
made=0
for row in "${todo[@]}"; do
IFS=$'\t' read -r out ref prompt <<<"$row"
- if [[ ! -e $art/$ref.png ]]; then
- echo "gen-frames: $out: its reference $ref.png does not exist yet, skipped" >&2
+ IFS=+ read -ra refs <<<"$ref"
+ missing=""
+ for r in "${refs[@]}"; do [[ -e $art/$r.png ]] || missing=$r; done
+ if [[ -n $missing ]]; then
+ echo "gen-frames: $out: its reference $missing.png does not exist yet, skipped" >&2
continue
fi
- echo "gen-frames: $out <- $ref"
- { printf 'data:image/png;base64,'; base64 -w0 "$art/$ref.png"; } >"$tmp/ref"
+ echo "gen-frames: $out <- ${ref//+/ + }"
+ # One JSON string per reference, as data URLs, slurped into the array.
+ for r in "${refs[@]}"; do
+ { printf 'data:image/png;base64,'; base64 -w0 "$art/$r.png"; } | jq -Rs .
+ done >"$tmp/refs.json"
# The settings the frames were tuned with in sd-webui: recipe.txt.
- jq -n --arg prompt "$prompt" --rawfile ref "$tmp/ref" --argjson seed "$seed" '{
+ jq -n --arg prompt "$prompt" --slurpfile refs "$tmp/refs.json" --argjson seed "$seed" '{
prompt: $prompt, negative_prompt: "", width: 1024, height: 1024, seed: $seed,
- batch_count: 1, ref_images: [$ref], auto_resize_ref_image: true,
+ batch_count: 1, ref_images: $refs, auto_resize_ref_image: true,
increase_ref_index: false, lora: [], output_format: "png", output_compression: 100,
sample_params: { sample_steps: 4, sample_method: "euler", scheduler: "default",
guidance: { txt_cfg: 1.0 } }