Nodes/comfyui-flower-tools/🌸Flower Keyword Replacer
ComfyUI Node

🌸Flower Keyword Replacer

Ten-slot find-and-replace for prompt templates, no regex required

By weichenglin0215·Created 8 months ago·Updated 2 months ago· 0
🌸Flower Keyword Replacer
    • text
    ◄text►
    ◄keyword_1►
    ◄replacement_1►
    ◄keyword_2►
    ◄replacement_2►
    ◄keyword_3►
    ◄replacement_3►
    ◄keyword_4►
    ◄replacement_4►
    ◄keyword_5►
    ◄replacement_5►
    ◄keyword_6►
    ◄replacement_6►
    ◄keyword_7►
    ◄replacement_7►
    ◄keyword_8►
    ◄replacement_8►
    ◄keyword_9►
    ◄replacement_9►
    ◄keyword_10►
    ◄replacement_10►

    Flower Keyword Replacer is the prompt template's duct tape: ten keyword→replacement slots, one text in, one text out, and zero AI involved. You write a prompt with placeholder tokens like *WOMAN* and *Color*, this node swaps them for concrete values, and the result goes to the CLIP encoder. If you've ever hand-edited the same prompt ten times to test ten variations, this is the node that makes that a two-second change instead.

    How it works

    The mechanism is exactly as unglamorous as it sounds: a sequential str.replace() for each slot, in order from slot 1 to slot 10. Empty keywords are skipped, and only non-empty keywords are replaced - so leaving most slots blank and using one or two is the normal way to run it. Output is a single text STRING ready to feed a Text Encode or another node downstream.

    Two things follow from "sequential replace" that people forget:

    1. Order matters. Slot 1's replacement happens before slot 2 matches, so a later keyword can match text that an earlier replacement just produced. If your tokens can overlap, order them deliberately.
    2. It's plain literal substitution. No regex, no wildcards, no case-insensitive matching. *color* and *Color* are different tokens. That's a feature for prompt work - you control exactly what changes - but it means you must match your placeholder spelling exactly.

    The one workflow it shines in

    The pack's own demo shows the intended pattern: pair it with the Flower Multiline Prompt Selector in Combination mode. The selector picks one unit from each of several wildcard files (a nationality, an age, an expression, a body type), concatenates them, and this replacer's job is to slot those picks into a fixed template. Say the selector outputs 一位青春洋溢的18歲少女,表情自然帶笑 and 駝色; a template like "*WOMAN*,穿著*Color*短版襯衫。" becomes a complete, varied prompt each run. The whole thing runs headless per batch, which is the point - variation without you retyping anything.

    It's also fine as a standalone testing tool: swap one concept at a time in a fixed prompt and batch with a locked seed to isolate what each substitution actually changes. That's the closest thing this pack has to an A/B test rig.

    Install

    Same pack as everything else in this family:

    cd ComfyUI/custom_nodes
    git clone https://github.com/weichenglin0215/comfyui-flower-tools.git
    

    Then restart. Or ComfyUI Manager → search ComfyUI Flower Tools. No models, no downloads; the pack's only real dependency (opencc) isn't even used by this node.

    Gotchas

    • Ten slots is the ceiling - if your template needs eleven tokens, you'll chain two of these nodes or pre-merge some replacements into a single slot.
    • The text input is multiline, and each replacement_N is multiline too, so multi-line replacements work fine. Multi-line keywords are technically possible but a terrible idea - keep keywords short and distinctive.
    • Because every slot runs even when empty (it just no-ops), there's no harm in leaving slots 5–10 unused. Don't feel obligated to fill all ten.
    Categoryflower-tools

    Inputs (21)

    NameTypeDefaultDescription
    textSTRING—
    keyword_1optSTRING—
    replacement_1optSTRING—
    keyword_2optSTRING—
    replacement_2optSTRING—
    keyword_3optSTRING—
    replacement_3optSTRING—
    keyword_4optSTRING—
    replacement_4optSTRING—
    keyword_5optSTRING—
    replacement_5optSTRING—
    keyword_6optSTRING—
    replacement_6optSTRING—
    keyword_7optSTRING—
    replacement_7optSTRING—
    keyword_8optSTRING—
    replacement_8optSTRING—
    keyword_9optSTRING—
    replacement_9optSTRING—
    keyword_10optSTRING—
    replacement_10optSTRING—

    Outputs (1)

    NameTypeDescription
    textSTRING—