#!/usr/bin/env bash # # paint.sh: the AI illustrations for "The Goths" # # Seven painted scenes in the manner of a 19th-century history painting, rendered with rose.py and # FLUX 3 on Replicate. They are inventions for atmosphere, not reconstructions, and the post marks # each of them as an AI illustration. The historical pictures and the figures come from build.sh. # # Model: https://replicate.com/black-forest-labs/flux-3-image # # Usage: ./paint.sh [options] (REPLICATE_API_TOKEN must be set) # -s, --scene NAME[,NAME...] only these scenes # -r, --resolution RES 768sq, 1k, 1.5k, 2k or 4k (default 1.5k) # -j, --jobs N parallel predictions (default 4) # -f, --force paint scenes that already exist # -n, --dry-run print the prompts and payloads, generate nothing # -h, --help # # Output: goths-scene-.jpg next to this file. FLUX 3 has no seed input, so a rerun gives new # takes on the same prompts; existing pictures are skipped. set -Eeuo pipefail HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" ROSE="${ROSE_PY:-$HERE/../../../rose.py}" MODEL="black-forest-labs/flux-3-image" RESOLUTION="1.5k" ASPECT="3:2" JOBS=4 FORCE=0 DRY=0 ONLY="" # --------------------------------------------------------------------------------------- # The look, reused in every prompt # --------------------------------------------------------------------------------------- STYLE="A monumental 19th-century academic history painting in oil, visible brushwork, dramatic \ chiaroscuro, a stormy sky, deep plum shadows with warm gold light, cinematic wide composition." CLOSING="Clothing and equipment of late antiquity, no horned helmets. Natural anatomy. A single \ full-bleed painting without text, lettering, signature or frame." # --------------------------------------------------------------------------------------- # The scenes # --------------------------------------------------------------------------------------- NAMES=(north storm wulfila rome funeral crimea tales) declare -A SCENE SCENE[north]="Long wooden clinker-built rowing boats without sails leave a rocky northern shore at \ dawn. Families with bundles, cattle and children crowd the boats, a woman looks back at standing \ stones on the headland, grey Baltic waves, a band of gold on the horizon." SCENE[storm]="At dusk a vast crowd of refugees with ox carts, shields and children waits on the \ bank of a wide swollen river, rafts and dugout boats pushing off. Behind them on the far hills, \ small silhouettes of mounted archers and columns of smoke under a black storm cloud." SCENE[wulfila]="An elderly bearded bishop in a plain wool robe writes by oil lamp at a wooden \ desk, silver ink gleaming on a sheet of deep purple parchment. Young scribes watch, an open \ window shows a night landscape of the lower Danube." SCENE[rome]="Gothic warriors on horseback pass at night through a great Roman city gate into a \ marble forum, torches and a red glow over temple columns, a toppled bronze shield on the steps, \ citizens watching in silence from a colonnade. No gore." SCENE[funeral]="On a battlefield at sunset warriors carry their fallen old king, white-bearded, \ on a great round shield, raised spears all around, a young prince in mail stands bareheaded \ before the bier, riderless horse, a wide plain with distant campfires. No gore." SCENE[crimea]="A fortress town carved into a high flat-topped limestone mountain in Crimea at \ golden hour, cave dwellings, stone walls and a small domed church, a few villagers with goats on \ a winding path, the Black Sea hazy in the distance." SCENE[tales]="In a candlelit old library an open ancient book releases a swirl of golden light \ that forms ghostly riders crossing a river, an eagle-shaped garnet brooch lies beside the book, \ tall shelves fading into darkness." say() { printf '%s\n' "$*" >&2; } die() { say "error: $*"; exit 2; } usage() { sed -n '/^# Usage:/,/^# -h/p' "${BASH_SOURCE[0]}" | sed 's/^# \{0,1\}//'; } squash() { tr -s '[:space:]' ' '; } file_of() { printf '%s/goths-scene-%s.jpg' "$HERE" "$1"; } while (($#)); do case "$1" in -s | --scene) ONLY="${2:?--scene needs a value}"; shift 2 ;; -r | --resolution) RESOLUTION="${2:?--resolution needs a value}"; shift 2 ;; -j | --jobs) JOBS="${2:?--jobs needs a value}"; shift 2 ;; -f | --force) FORCE=1; shift ;; -n | --dry-run) DRY=1; shift ;; -h | --help) usage; exit 0 ;; *) die "unknown option: $1 (try --help)" ;; esac done [[ -f "$ROSE" ]] || die "rose.py not found at $ROSE (set ROSE_PY)" command -v python3 >/dev/null || die "python3 is required" [[ -n "${REPLICATE_API_TOKEN:-}" ]] || die "REPLICATE_API_TOKEN is not set" if [[ -n "$ONLY" ]]; then IFS=',' read -r -a WANT <<<"$ONLY" for name in "${WANT[@]}"; do [[ -n "${SCENE[$name]:-}" ]] || die "no scene called '$name' (${NAMES[*]})"; done else WANT=("${NAMES[@]}") fi todo=() for name in "${WANT[@]}"; do if ((FORCE || DRY)) || [[ ! -f "$(file_of "$name")" ]]; then todo+=("$name"); fi done ((${#todo[@]})) || { say "all scenes exist (use --force to paint them again)"; exit 0; } TMP="$(mktemp -d)" trap 'rm -rf "$TMP"' EXIT prompts="$TMP/prompts.txt" for name in "${todo[@]}"; do printf '%s %s %s' "$STYLE" "${SCENE[$name]}" "$CLOSING" | squash >>"$prompts" printf '\n' >>"$prompts" done say "The Goths: ${#todo[@]} scene(s) with $MODEL at $RESOLUTION" args=(replicate "$MODEL" --prompts-file "$prompts" --jobs "$JOBS" --timeout 900 --aspect-ratio "$ASPECT" --resolution "$RESOLUTION" --no-grounding --output-format jpg --output-quality 92 --output-dir "$TMP/out" --no-meta) ((DRY)) && args+=(--dry-run) failed=0 python3 "$ROSE" "${args[@]}" || failed=1 ((DRY)) && exit "$failed" i=0 for name in "${todo[@]}"; do i=$((i + 1)) src="$(find "$TMP/out" -maxdepth 1 -type f -name "*-$(printf '%02d' "$i").*" 2>/dev/null | head -n1 || true)" if [[ -z "$src" ]]; then say "missing: $name (rerun to retry)" continue fi mv -f "$src" "$(file_of "$name")" say "saved ${name}" done exit "$failed"