#!/usr/bin/env bash # # paint.sh: the AI illustrations for "The Huns" # # Eight 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: huns-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 academic history painting in oil, visible brushwork, low dramatic light, \ a vast sky of smoky amber and storm blue, burnt crimson and old gold accents, deep shadows, \ cinematic wide composition." CLOSING="Clothing and equipment historically plausible for the period described, no plate \ armour. Natural anatomy. A single full-bleed painting without text, lettering, signature or frame." # --------------------------------------------------------------------------------------- # The scenes # --------------------------------------------------------------------------------------- NAMES=(riders wall river margus plains lagoon funeral tally) declare -A SCENE SCENE[riders]="A wave of steppe horse archers in felt caps, fur-trimmed coats and leather riding \ boots gallops across tall dry grass towards the viewer, drawing long asymmetric composite bows, \ small sturdy shaggy horses, dust and a low sun behind them under heavy storm clouds." SCENE[wall]="Ancient mounted nomads of the second century BC with composite bows halt on a barren \ ridge at dawn and look down on a long wall of rammed earth with wooden watchtowers and Han Chinese \ signal fires, cold mist in the valleys." SCENE[river]="At dusk on a wide river bank, fourth-century Gothic families with ox wagons, children \ and bundles crowd into dugout boats and rafts to cross, anxious faces, far behind them on the \ hills the silhouettes of horsemen and a red glow. No gore." SCENE[margus]="Two fifth-century Hun leaders, brothers in plain but fine riding coats, negotiate \ from horseback with Roman envoys in cloaks who also remain mounted, on a meadow beside the Danube, \ a Roman frontier town with walls behind, banners stirring." SCENE[plains]="An enormous cavalry battle of the year 451 on rolling plains in northern Gaul, Hun \ horse archers wheeling against late Roman soldiers and Visigoth warriors with round shields, clouds \ of dust, a blood-red evening sky, a comet faintly visible. No gore." SCENE[lagoon]="Fifth-century refugees from a burning city on the Italian mainland row boats into a \ misty shallow lagoon with reed islands and simple huts on wooden piles, dawn light on still water, \ smoke far on the horizon, hopeful and quiet." SCENE[funeral]="At twilight on an open plain a great tent of pale silk glows from within, a circle \ of horsemen rides around it in solemn procession with torches, mourners in the foreground, an \ immense darkening sky with the first stars." SCENE[tally]="An old Transylvanian shepherd of the late middle ages in a sheepskin cloak sits by a \ campfire and carves small angular notches into a long square wooden stick with a knife, a child \ watching closely, sheep and wooded mountains behind in blue evening light." 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/huns-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 Huns: ${#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"