1#!/usr/bin/env bash
2#
3# build.sh: the images for "Black No. 1"
4#
5# A poetry-to-image project after "Black No. 1 (Little Miss Scare-All)" by Type O Negative
6# (written by Peter Steele, 1993). Here it becomes a gothic beauty magazine editorial: eight
7# movements of three plates each, twenty-four plates and twenty-four different women. The lyrics are
8# copyrighted and are not reproduced here; the scenes below are original interpretations. All models
9# are invented adults. Read the words at the source:
10#
11# Lyrics: https://genius.com/Type-o-negative-black-no-1-little-miss-scare-all-lyrics
12# Model: https://replicate.com/black-forest-labs/flux-3-image
13# Look: gothic beauty portraits, luxury fashion magazine photography
14#
15# Every plate is a head-and-neck beauty portrait: the make-up, hair, headpiece and neckwear
16# carry the look.
17#
18# Usage: ./build.sh [options] (REPLICATE_API_TOKEN must be set)
19# -p, --part N[,N...] only these movements (1-8)
20# -k, --shot N[,N...] only these plates (1-3)
21# -a, --aspect RATIO aspect ratio (default 4:5)
22# -r, --resolution RES 768sq, 1k, 1.5k, 2k or 4k (default 2k)
23# -j, --jobs N parallel predictions (default 4)
24# -f, --force regenerate plates that already exist
25# -n, --dry-run print the prompts and payloads, generate nothing
26# -h, --help
27#
28# Output: black-no-1-<movement>-<plate>.jpg next to this file.
29# FLUX 3 has no seed input, so a rerun gives new takes on the same prompts; keep the images you
30# like, they are skipped. Web grounding is switched off so the model invents its own faces.
31# When all 24 plates exist, the post's `draft` flag is cleared.
32
33set -Eeuo pipefail
34
35HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
36ROSE="${ROSE_PY:-$HERE/../../../rose.py}"
37
38MODEL="black-forest-labs/flux-3-image"
39ASPECT="4:5"
40RESOLUTION="2k"
41JOBS=4
42FORMAT="jpg"
43QUALITY=92
44FORCE=0
45DRY=0
46PART_ONLY=""
47SHOT_ONLY=""
48
49PARTS=8
50SHOTS=3
51
52# ---------------------------------------------------------------------------------------
53# The look, reused in every prompt
54# ---------------------------------------------------------------------------------------
55STYLE="High fashion beauty photography for a luxury gothic magazine. Photorealistic, shot on a \
56medium format camera with a 105mm portrait lens, shallow depth of field, masterful beauty \
57lighting, deep velvety blacks, rich tonal range, natural skin texture with visible pores, razor \
58sharp eyes with bright catchlights, magnificent professional goth make-up applied with precision: \
59detailed eyeshadow, crisp eyeliner, full lashes, shaped brows and flawlessly painted lips. Refined \
60colour grading."
61
62NEGATIVE="One single adult woman, alone in the frame. No hands, no arms. One full-bleed \
63photograph: no text, no lettering, no logos, no magazine masthead, no borders, no collage, no \
64watermark."
65
66# Framing, the same for every plate
67FRAME="Tight beauty portrait of the head and neck only: the whole head, hair or headpiece and the \
68complete neck are inside the frame, cropped at the collarbones, the face large and in sharp focus."
69
70# ---------------------------------------------------------------------------------------
71# Eight movements, three plates each. shot <movement> <plate> <scene>
72# ---------------------------------------------------------------------------------------
73declare -A SCENE
74shot() { SCENE["$1-$2"]=$3; }
75
76# I. Raven Gloss
77shot 1 1 "A Japanese woman in her late twenties with a mirror-glossy blunt black bob and micro \
78fringe, porcelain matte skin, razor-sharp graphic winged eyeliner and deep black-cherry lips, a \
79high black patent leather collar encircling her neck. She gazes straight into the camera, serious \
80and still. Crisp beauty-dish light against a seamless charcoal backdrop."
81shot 1 2 "A Nigerian woman in her thirties with deep dark skin and long jet black braids adorned \
82with silver rings, metallic gunmetal smoky eyes, glossy black lips, tiny black crystals under the \
83eyes and a tall stack of black beaded necklaces up her throat. Chin raised, regal. A single hard \
84key light with a cool silver rim light."
85shot 1 3 "A Swedish woman in her forties with sleek jet black hair parted in the middle, ice-pale \
86skin, bleached brows, dramatic charcoal smoky eyes and glossy black lips, a high sheer black \
87organza collar. A commanding, level stare. Soft overhead light against a stark black backdrop."
88
89# II. Velvet Devotion
90shot 2 1 "A Mexican woman in her thirties with long black waves crowned by dark red roses, ornate \
91black filigree eye make-up, oxblood lips, a wide black lace choker with a garnet drop. Eyes lifted \
92in quiet devotion. Warm soft key light against a perfectly clean, plain, seamless dark charcoal \
93studio backdrop."
94shot 2 2 "An Ethiopian woman in her late twenties with a voluminous halo of black coils, burnished \
95plum eyeshadow, gold-flecked black lips, layers of antique silver chains around her neck above a \
96midnight purple velvet collar. Serene and intense. Chiaroscuro light like an old master painting."
97shot 2 3 "A Tamil woman in her thirties with a thick black braid woven with black blossoms, \
98dramatic winged kohl eyes with plum shadow, glossy black-wine lips, ornate oxidised silver \
99earrings and a black velvet beaded collar. Looking up toward a shaft of warm light, devoted."
100
101# III. Lace and Moonlight
102shot 3 1 "A pale Korean woman in her twenties with long ash-black hair, translucent skin, soft \
103silver-grey smoky eyes, glass-gloss berry black lips, a delicate black net veil across her eyes \
104and a black lace choker. Lips slightly parted, a cool seductive gaze. Blue moonlight from one \
105side."
106shot 3 2 "An Irish woman in her thirties with cascading deep auburn curls, freckled fair skin, \
107emerald and black smoky eyes, dark plum lips and a high-necked black Chantilly lace collar. A \
108seductive glance over her turned neck. Cold window moonlight."
109shot 3 3 "A Samoan woman in her thirties with long glossy black waves, bronze skin, iridescent \
110teal-black eye make-up sweeping to the temples, black lips and a scalloped black lace collar with \
111a dark pearl strand. A calm, powerful gaze. Deep blue night light with a silver rim."
112
113# IV. The Mourning Salon
114shot 4 1 "A Persian woman in her thirties with thick dark brows, dramatic elongated black \
115eyeliner, matte burgundy lips, a small tilted Victorian mourning hat with a spotted black net veil \
116and raven feathers, and a jet bead collar. A grave, magnetic stare. Soft window light on a dark \
117damask background."
118shot 4 2 "A Black British woman in her fifties with a close-cropped silver afro, high cheekbones, \
119violet-black eyeshadow, deep aubergine lips, jet drop earrings and a high black lace jabot collar \
120with a cameo. Dignified and unsmiling. Elegant sculpted side light."
121shot 4 3 "A Chinese woman in her late twenties with an elaborate high black updo pinned with \
122silver hair ornaments, red-black graphic eye make-up, a precise dark crimson lip and a tall \
123ruffled black taffeta collar. A poised, serious three-quarter turn of the head. Soft salon light."
124
125# V. Leather and Chrome
126shot 5 1 "A Brazilian woman of African descent in her twenties with a shaved head, bold \
127chrome-silver and black avant-garde eye make-up sweeping to the temples, black lips with a silver \
128centre line and stacked silver neck rings. Fierce direct gaze. Hard flash with a violet gel."
129shot 5 2 "A Russian woman in her thirties with a platinum white sleek high ponytail, heavy black \
130smoky eyes, nearly black lips and a wide black leather collar with silver buckles. Confident and \
131provocative. Hard side light with red and blue gels in smoke."
132shot 5 3 "A Filipina woman in her late twenties with a black and violet split-dyed shag haircut, \
133smudged deathrock eye make-up with fine drawn lines beneath the eyes, black lips, silver ear cuffs \
134and a studded leather choker. A defiant stare. A single hard backlight against raw concrete."
135
136# VI. Crimson Vanity
137shot 6 1 "A Lebanese woman in her thirties with glossy dark finger waves, smouldering copper-black \
138eyes, a perfect deep blood-red lip, a beauty mark, ruby drop earrings and a black velvet ribbon \
139with a ruby at her throat. A slow seductive glance into the camera. Warm red-tinted glamour \
140light."
141shot 6 2 "An Italian woman in her forties with dark upswept hair, long black winged liner, deep \
142crimson and black smoky eyes, glossy black-red lips and a garnet and black lace collar. A knowing \
143seductive gaze. Low amber lamp light."
144shot 6 3 "A South Asian Punjabi woman in her thirties with long straight black hair parted in the \
145middle, extended graphic black eyeliner, blood-red and black smoky eyes reaching to the temples, \
146glossy near-black lips and an ornate black lace choker. Intense and alluring. Deep red rim light."
147
148# VII. All Hallows
149shot 7 1 "A Peruvian Quechua woman in her thirties with two long black braids tied with black \
150ribbons, burnt-orange and black smoky eyes, dark brick lips, a crown of black autumn leaves and a \
151beaded black collar. Calm, piercing eyes. Golden lantern glow against deep blue dusk."
152shot 7 2 "A Moroccan woman in her late twenties with big glossy dark curls swept to one side, \
153refined bronze-black cat eyes, espresso-black lips, elegant jet drop earrings and a high black \
154velvet couture collar. A knowing half smile, sophisticated and understated. Soft side light \
155against a seamless dark grey backdrop."
156shot 7 3 "A woman with albinism in her twenties with long white hair, pale lashes, striking black \
157and silver eye make-up, black lips and a tall black raven-feather collar framing her neck. Solemn. \
158A soft key light against a misty twilight blue."
159
160# VIII. The Black Coronation
161shot 8 1 "A Mongolian woman in her thirties with sleek black hair swept back under a spiked black \
162metal halo crown, a band of black pigment painted across the eyes, rosy wind-flushed cheeks, black \
163lips and a high structured black collar. Imperious, unblinking. Dramatic top light."
164shot 8 2 "An Aboriginal Australian woman in her thirties with rich brown skin and wavy dark hair, \
165star-like silver crystals around smoky black eyes, deep mulberry lips and an ornate black filigree \
166metal collar set with polished obsidian stones, fitted closely around her neck, bare shoulders. \
167Majestic. Crisp rim light against a perfectly clean, plain, seamless light grey studio backdrop, \
168completely empty, without smoke or haze."
169shot 8 3 "A Sudanese woman in her late twenties with very deep dark skin, a sculpted black crown \
170of braids with black jewels, glossy black eye make-up, black lips and a tall column of black metal \
171neck rings. The sovereign of the night, looking slightly down into the camera. One shaft of light \
172in darkness."
173
174# ---------------------------------------------------------------------------------------
175# Helpers
176# ---------------------------------------------------------------------------------------
177if [[ -t 2 ]]; then
178 B=$'\033[1m' D=$'\033[2m' R=$'\033[31m' G=$'\033[32m' Y=$'\033[33m' C=$'\033[36m' Z=$'\033[0m'
179else
180 B="" D="" R="" G="" Y="" C="" Z=""
181fi
182say() { printf '%s\n' "$*" >&2; }
183die() { say "${R}error:${Z} $*"; exit 2; }
184usage() { sed -n '/^# Usage:/,/^# -h/p' "${BASH_SOURCE[0]}" | sed 's/^# \{0,1\}//'; }
185squash() { tr -s '[:space:]' ' '; }
186file_of() { printf '%s/black-no-1-%d-%d' "$HERE" "$1" "$2"; } # movement plate -> path, no extension
187have() { compgen -G "$(file_of "$1" "$2").*" >/dev/null; }
188
189shot_prompt() { # movement plate -> one-line prompt
190 printf '%s %s %s %s' "$FRAME" "${SCENE[$1-$2]}" "$STYLE" "$NEGATIVE" | squash
191}
192
193result() { # out_dir index -> the file rose.py saved for that prompt, if any
194 find "$1" -maxdepth 1 -type f -name "*-$(printf '%02d' "$2").*" 2>/dev/null | head -n1 || true
195}
196
197# ---------------------------------------------------------------------------------------
198# Options
199# ---------------------------------------------------------------------------------------
200while (($#)); do
201 case "$1" in
202 -p | --part) PART_ONLY="${2:?--part needs a value}"; shift 2 ;;
203 -k | --shot) SHOT_ONLY="${2:?--shot needs a value}"; shift 2 ;;
204 -a | --aspect) ASPECT="${2:?--aspect needs a value}"; shift 2 ;;
205 -r | --resolution) RESOLUTION="${2:?--resolution needs a value}"; shift 2 ;;
206 -j | --jobs) JOBS="${2:?--jobs needs a value}"; shift 2 ;;
207 -f | --force) FORCE=1; shift ;;
208 -n | --dry-run) DRY=1; shift ;;
209 -h | --help) usage; exit 0 ;;
210 *) die "unknown option: $1 (try --help)" ;;
211 esac
212done
213
214[[ -f "$ROSE" ]] || die "rose.py not found at $ROSE (set ROSE_PY)"
215command -v python3 >/dev/null || die "python3 is required"
216[[ -n "${REPLICATE_API_TOKEN:-}" ]] || die "REPLICATE_API_TOKEN is not set"
217
218if [[ -n "$PART_ONLY" ]]; then
219 IFS=',' read -r -a WANT <<<"$PART_ONLY"
220 for n in "${WANT[@]}"; do [[ "$n" =~ ^[1-8]$ ]] || die "movement must be 1-8, got '$n'"; done
221else
222 WANT=(1 2 3 4 5 6 7 8)
223fi
224if [[ -n "$SHOT_ONLY" ]]; then
225 IFS=',' read -r -a SHOT_WANT <<<"$SHOT_ONLY"
226 for n in "${SHOT_WANT[@]}"; do [[ "$n" =~ ^[1-3]$ ]] || die "plate must be 1-3, got '$n'"; done
227else
228 SHOT_WANT=(1 2 3)
229fi
230
231TMP="$(mktemp -d)"
232trap 'rm -rf "$TMP"' EXIT
233failed=0
234
235say "${B}Black No. 1${Z} ${D}${MODEL} · ${ASPECT} · ${RESOLUTION}${Z}"
236
237# ---------------------------------------------------------------------------------------
238# Shoot everything that is still missing, in one batch
239# ---------------------------------------------------------------------------------------
240todo=()
241for m in "${WANT[@]}"; do
242 for k in "${SHOT_WANT[@]}"; do
243 if ((FORCE || DRY)) || ! have "$m" "$k"; then todo+=("$m $k"); fi
244 done
245done
246
247if ((${#todo[@]})); then
248 say ""
249 say "${C}${B}the editorial${Z} ${D}(${#todo[@]} plate(s))${Z}"
250 : >"$TMP/prompts.txt"
251 for item in "${todo[@]}"; do
252 read -r m k <<<"$item"
253 shot_prompt "$m" "$k" >>"$TMP/prompts.txt"
254 printf '\n' >>"$TMP/prompts.txt"
255 done
256
257 args=(replicate "$MODEL" --prompts-file "$TMP/prompts.txt" --jobs "$JOBS" --timeout 900
258 --aspect-ratio "$ASPECT" --resolution "$RESOLUTION" --no-grounding
259 --output-format "$FORMAT" --output-quality "$QUALITY" --output-dir "$TMP/out" --no-meta)
260 ((DRY)) && args+=(--dry-run)
261 if ! python3 "$ROSE" "${args[@]}"; then
262 say "${Y}some plates failed, rerun to retry them${Z}"
263 failed=1
264 fi
265
266 if ((!DRY)); then
267 i=0
268 for item in "${todo[@]}"; do
269 i=$((i + 1))
270 read -r m k <<<"$item"
271 src="$(result "$TMP/out" "$i")"
272 [[ -n "$src" ]] || continue
273 mv -f "$src" "$(file_of "$m" "$k").${src##*.}"
274 say "${G}saved${Z} black-no-1-$m-$k.${src##*.}"
275 done
276 fi
277fi
278
279# ---------------------------------------------------------------------------------------
280# Publish the post once everything exists
281# ---------------------------------------------------------------------------------------
282if ((!DRY)); then
283 missing=0
284 for ((m = 1; m <= PARTS; m++)); do
285 for ((k = 1; k <= SHOTS; k++)); do have "$m" "$k" || missing=$((missing + 1)); done
286 done
287 if ((missing)); then
288 say ""
289 say "${Y}${missing} plate(s) still missing.${Z}"
290 elif [[ -f "$HERE/index.md" ]] && grep -q '^draft: true$' "$HERE/index.md"; then
291 sed -i 's/^draft: true$/draft: false/' "$HERE/index.md"
292 say ""
293 say "${G}All $((PARTS * SHOTS)) plates exist: draft flag cleared in index.md.${Z}"
294 fi
295fi
296
297exit "$failed"