#!/usr/bin/env bash # # paint.sh: the AI illustrations for "The Turks" # # 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: turks-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, luminous steppe light, \ an immense sky of deep turquoise blue, warm gold highlights and plum shadows, cinematic wide \ composition." CLOSING="Historically plausible medieval clothing and equipment. Natural anatomy. A single \ full-bleed painting without text, lettering, signature or frame." # --------------------------------------------------------------------------------------- # The scenes # --------------------------------------------------------------------------------------- NAMES=(riders wolf blades sky camp flight mamluks harbour) declare -A SCENE SCENE[riders]="A line of mounted steppe riders with long braided hair, lamellar armour and a blue \ banner topped by a golden wolf head gallops along a grassy ridge, snow-covered mountains behind, \ towering white clouds, dust lit from behind." SCENE[wolf]="In a hidden green valley walled by high mountains, seen from the mouth of a cave, a \ large grey she-wolf lies protectively beside a sleeping young child wrapped in a fur blanket, \ morning mist, wild flowers, a quiet and tender legend." SCENE[blades]="Steppe blacksmiths at an open-air forge on a mountain slope hammer glowing iron, \ sparks flying, finished sword blades and arrowheads laid on felt, leather bellows, pack horses and \ the dusk-blue peaks beyond." SCENE[sky]="On the eve of battle an old khan in a fur-trimmed coat stands before clergy of many \ faiths, a drum-bearing shaman, a monk in saffron, a priest with a cross, a scholar with a book, all \ praying together around a fire under an enormous blue evening sky, tents and horsemen behind." SCENE[camp]="A nomad camp of round white felt yurts at golden hour on a wide green steppe, smoke \ rising from the roof openings, women rolling felt, children, grazing horses and two-humped camels, \ heavy wooden wagons, a river winding to the horizon." SCENE[flight]="A long column of nomad families with covered wagons, horses and sheep climbs through \ a snowy mountain pass under a dark storm sky, riders guarding the rear, far behind them a red glow \ and smoke on the plain. No gore." SCENE[mamluks]="Elite horsemen in thirteenth-century Cairo, polished helmets and mail, rich silk \ robes and curved bows, ride out of a great stone city gate with minarets behind, a young commander \ with steppe features in front, hot afternoon light and fine dust." SCENE[harbour]="In a fourteenth-century Black Sea trading port, a Franciscan friar in a brown habit \ and an Italian merchant sit at a table with quill and parchment beside a steppe herder who is \ teaching them words, galleys, stone walls and towers behind, 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/turks-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 Turks: ${#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"