Skip to content

armgit / fuobe

Public Imported from GitHub
0

The open creative studio on ComfyUI: images, video, 3D and audio on open weights, on your own GPU or the cloud. Camera motions, effects, apps, Cinema, Layers, Image to 3D and an AI agent.

7.4 KB
Raw Blame
#!/usr/bin/env python3
"""
Generate src/lib/catalog/influencer-options.generated.ts from docs/research/parity-delta-4.json
(aiInfluencerBuilder: the parity studio's AI Influencer builder, read from its bundle).

Outputs (data only; the rules and the prompt compiler are src/lib/influencer.ts):
  INFLUENCER_CATEGORIES — the 19 categories in the parity research's order: id, label, kind (media / text / color),
                          max picks, and every option with its id, label, the tiers it shows in
                          (visibleIn), its swatch (color categories) and its slot (Features).
                          Gender is Fuobe's own: Male, Female, Other (GENDER_OPTIONS below).
  RETIRED_OPTIONS       — option ids Fuobe no longer shows, and the option a saved pick of one becomes.
  CREATURE_TYPES       — the 6 creature types with their species ids and labels.
  CREATURE_CATEGORIES   — the categories a creature type shows.
  DISPLAY_ORDER_FIRST   — the categories the builder lists first.
  SHUFFLE_RESEARCH      — Shuffle's weights and the picks a reference photo keeps.
  CONFLICT_MESSAGES     — the two researched conflict messages, word for word.

No preview images are copied: Fuobe draws its own tiles, so nothing is hot-linked from the parity studio's CDN.

Run:  python3 scripts/gen-influencer-options.py
"""
import json
import re
from pathlib import Path

ROOT = Path(__file__).resolve().parent.parent
RESEARCH = json.loads((ROOT / "docs/research/parity-delta-4.json").read_text(encoding="utf-8"))["aiInfluencerBuilder"]
OUT = ROOT / "src/lib/catalog/influencer-options.generated.ts"

# Species ids are snake_case; these read better with their proper capitals.
SPECIES_LABELS = {"maine_coon": "Maine Coon", "british_shorthair": "British Shorthair"}

# Gender: Fuobe shows Male, Female and Other, in that order, in every human tier (the research lists five).
HUMAN_TIERS = ["normal", "freak", "total"]
GENDER_OPTIONS = [{"id": i, "label": l, "visibleIn": HUMAN_TIERS} for i, l in (("male", "Male"), ("female", "Female"), ("other", "Other"))]
# Option ids Fuobe no longer shows, and the option a saved pick or link that carries one becomes.
RETIRED_OPTIONS = {"gender": {"trans_man": "male", "trans_woman": "female", "non_binary": "other"}}


def ts(v):
    return json.dumps(v, ensure_ascii=False, indent=2)


def species_label(sid):
    return SPECIES_LABELS.get(sid) or sid.replace("_", " ").capitalize()


categories = []
for c in RESEARCH["categories"]:
    options = []
    for o in c["options"]:
        opt = {"id": o["id"], "label": o["label"]}
        if "visibleIn" in o:
            opt["visibleIn"] = o["visibleIn"]
        if "swatch" in o:
            opt["swatch"] = o["swatch"].lower()
        if "slot" in o:
            opt["slot"] = o["slot"]
        options.append(opt)
    if c["id"] == "gender":
        shown = {o["id"] for o in GENDER_OPTIONS}
        lost = [o["id"] for o in options if o["id"] not in shown and o["id"] not in RETIRED_OPTIONS["gender"]]
        if lost:
            raise SystemExit(f"gender options with no new option: {lost}")
        options = [dict(o) for o in GENDER_OPTIONS]
    categories.append({"id": c["id"], "label": c["label"], "kind": c["kind"], "max": c["max"], "options": options})

tier_labels = {o["id"]: o["label"] for o in next(c for c in RESEARCH["categories"] if c["id"] == "tier")["options"]}
creatures = [
    {"id": cid, "label": tier_labels.get(cid, cid), "species": [{"id": s, "label": species_label(s)} for s in species]}
    for cid, species in RESEARCH["creatureTypes"].items()
]

shuffle = RESEARCH["shuffle"]


def weights(d):
    """{"hs_lampshade (Bob) when visible": 0.2, "otherUniform": 0.8} → {"hs_lampshade": 0.2} (the rest is uniform)."""
    return {k.split(" ")[0]: v for k, v in d.items() if not k.startswith("other")}


shuffle_out = {
    "keepsWithReference": shuffle["keepsWithReference"],
    "weights": {"gender": weights(shuffle["gender"]), "aesthetic": weights(shuffle["aesthetic"]), "hair": weights(shuffle["hair"])},
}
if any(g not in {o["id"] for o in GENDER_OPTIONS} for g in shuffle_out["weights"]["gender"]):
    raise SystemExit(f"gender weights name an option Fuobe does not show: {shuffle_out['weights']['gender']}")

conflicts = [re.sub(r"\s*\(.*\)\s*$", "", r).strip() for r in RESEARCH["rules"] if "cannot be combined" in r]
heavy = next(m for m in conflicts if m.startswith("Heavy"))
legs = next(m for m in conflicts if "Short legs" in m)

errors = []
if len(categories) != 19:
    errors.append(f"expected 19 categories, got {len(categories)}")
if len(creatures) != 6:
    errors.append(f"expected 6 creature types, got {len(creatures)}")
if errors:
    raise SystemExit("; ".join(errors))

OUT.write_text(
    "// GENERATED by scripts/gen-influencer-options.py from docs/research/parity-delta-4.json (aiInfluencerBuilder) — do not edit.\n"
    "// The parity studio's AI Influencer builder: its option ids, labels, tiers, swatches and Shuffle weights (Gender is Fuobe's own: Male, Female, Other).\n\n"
    "/** Human tiers: Average (normal), Bold (freak), Extreme (total). */\n"
    "export type HumanTier = \"normal\" | \"freak\" | \"total\";\n"
    f"export type CreatureType = {' | '.join(json.dumps(c['id']) for c in creatures)};\n"
    "export type InfluencerTier = HumanTier | CreatureType;\n\n"
    "export interface InfluencerOption {\n  id: string;\n  label: string;\n"
    "  /** The tiers that show it (human tiers or creature types; creature types also get every option of their categories but Centaur). */\n"
    "  visibleIn?: InfluencerTier[];\n  /** Colour categories: the tile's swatch. */\n  swatch?: string;\n"
    "  /** Features: one option per slot (marks, cheeks, eyes, lips, brows, nose, ears, teeth, chin, forehead). */\n  slot?: string;\n}\n\n"
    "export interface InfluencerCategory {\n  id: string;\n  label: string;\n  kind: \"media\" | \"text\" | \"color\";\n"
    "  /** How many options can be picked (Features: one per slot, up to this many). */\n  max: number;\n  options: InfluencerOption[];\n}\n\n"
    "export interface CreatureDef {\n  id: CreatureType;\n  label: string;\n  species: { id: string; label: string }[];\n}\n\n"
    f"export const INFLUENCER_CATEGORIES: InfluencerCategory[] = {ts(categories)};\n\n"
    f"export const CREATURE_TYPES: CreatureDef[] = {ts(creatures)};\n\n"
    f"/** The categories a creature type shows (plus its species and body colour). */\nexport const CREATURE_CATEGORIES: string[] = {ts(RESEARCH['creatureCategories'])};\n\n"
    f"/** The builder lists these first, then the rest in the parity research's order. */\nexport const DISPLAY_ORDER_FIRST: string[] = {ts(RESEARCH['displayOrderFirst'])};\n\n"
    "/** Shuffle (function `ae` in the bundle): weighted picks (the rest of each category is uniform) and what a reference photo keeps. */\n"
    f"export const SHUFFLE_RESEARCH = {ts(shuffle_out)} as const;\n\n"
    "/** The researched conflict messages, word for word. */\n"
    f"export const CONFLICT_MESSAGES = {ts({'heavyTall': heavy, 'buildLegs': legs})} as const;\n\n"
    "/** Option ids Fuobe no longer shows, per category: the option a saved pick or link that carries one becomes. */\n"
    f"export const RETIRED_OPTIONS: Record<string, Record<string, string>> = {ts(RETIRED_OPTIONS)};\n",
    encoding="utf-8",
    newline="\n",
)
n = sum(len(c["options"]) for c in categories)
print(f"wrote {OUT.relative_to(ROOT)}: {len(categories)} categories, {n} options, {len(creatures)} creature types")