Skip to content

Prompt formatter extension for automatic1111's stable diffusion web-ui

Notifications You must be signed in to change notification settings

uwidev/sd_extension-prompt_formatter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Demonstration

sd_extension-prompt_formatter

This is an extension for AUTOMATIC1111/stable-diffusion-webui that adds a magic button next to your prompt to make it look neat and "optimized." It does several things.

  1. Normalizes the characters to their standard equivalent (NFKC)
  2. Normalizes brackets to their minimum matching pair
  3. Removes excessive whitespace
  4. Properly spaces commas, bracketing, commas, and |
  5. Converts nested brackets ((a)) to a single bracket weight (a:1.21)

Works for txt2img and img2img for both positive and negative prompts.

Currenty as of commit 54d57c2 v0.3, may not respect escaped parenthesis and square brackets, and may crash the extension.

Example

Raw Prompt

photorealistic   photo of a handsome male (wizard  :1.2), <lora:LuisapHotlineStyle:0.5> <lora:ElegantHanfuRuqunStyle:0.2>    short beard, white wizard  shirt, (with golden    trim:0.8), (((bald))

Formatted

photorealistic photo of a handsome male (wizard:1.2), <lora:LuisapHotlineStyle:0.5> <lora:ElegantHanfuRuqunStyle:0.2> short beard, white wizard shirt, (with golden trim:0.8), (bald:1.21)

Raw Prompt

a, [[b, [c, [A:B], [A|B], [A :1.2 AND B :1.2]], e]]

Formatted

a, (b, (c, [A:B], [A|B], [A :1.2 AND B :1.2]:0.91), e:0.83)

Inspiration from taken from canisminor1990/sd-webui-kitchen-theme's prompt formatter.

Installation

  1. In your Stable Diffusion Web UI, navigate to Extensions > Install from URL
  2. Copy and paste this repository to the URL install

https://github.com/uwidev/sd_extension-prompt_formatter

  1. Install
  2. Go to the Installed tab and click Apply and restart UI

Other planned(?) features

  • take into account prompt editing (do not convert [from:to:when] ⏫ ✅ 2023-04-27
  • fix: do not convert {} to () (wildcard fix) ⏫ ✅ 2023-04-27
  • handle additional bracekt weighting within nested brackets e.g. ((A), (B)) => ((A, B)) => (A, B:1.21) ✅ 2023-04-27
  • Somehow magically resolve mixed bracketing (e.g. ([<1girl>]) who types their prompts like this?!1) ✅ 2023-04-27 maybe fixed?
  • Respect new lines (useful when splitting prompt on BREAK)
  • Further simplify [(a:0.91)] => (a:0.83), instead of ((a:0.91):0.91)
  • A Revert button just in case it formats it incorrectly (and my logic be funky) 🔼
  • Have moving networks to the back a option rather than always enforced.
  • Extension settings menu.
  • Option to convert token spaces to underscore
  • have an option multiple weighted tagged blocks into individual blocks? e.g. (A, B:1.2) => (A:1.2), (B:1.2)
  • Update the top right token counter so that it's not red on prompt format (need to learn javascript for that one it seems)
  • Option to normalize brackets to their maximum matching pair (e.g. (((a -> (((a)))
  • proper testing of prompts for faster development ✅ 2023-04-27