Sign In

Custom Stable Diffusion Tools and Extensions

1

Custom Stable Diffusion Tools and Extensions

For years now, I've been using wildcard extensively when generating images, including wildcard which call wildcards which call wildcards. I've come up with many ideas for ways to make the system better fit my needs, but I can't code at all. I learned about the quality of vibe-coding a few weeks ago and have been implementing my ideas ever since.

All of this has been vibe-coded with the free version of Claude for Stable Diffusion ReForge. Honestly, I have absolutely no idea what I'm doing, but I've been very happy with the results. Here's what I've had it make so far:

Overview

Stand Alone Programs:

Image Rater - an image browser tool designed to quickly and easily sort through, and rate, delete bad, and move, stable diffusion outputs

Wildcard Editor - a text editor optimized for wildcards modeled after notepad++, with a hyperlink like feature to allow for jumping between wildcards called by other wildcards among many other features.

ReForge Extensions:

Wildcard Resolver - Allows you to double click wildcards in the prompt window to manually select entries recursively, or right click to revert back to the wildcard that entry came from.

Anti-Wildcards/Wildcard Combos - After wildcards are resolved, this will search through the prompt for key phrases that appear in a .txt file and if a match is found, will add or remove a corresponding phrase to the negative prompt for that generation. Similarly, Wildcard Combos will search through the prompt for multiple key phrases after the wildcards resolve, and if all are present, will add a corresponding phrase to the main prompt.

LoRA Auto Tester - using .txt templates, automatically test a folder of LoRAs for compatibility with your base model/prompting style

Retroactive Hires Fix - Takes files/folders generated normally and retroactively applies the Hires fix upscaling function to them. Has cross integration with the rating system used by the Image Rater program.

Memory Cleaner - A simple extension that clears generations from over 2 batch sets ago from the memory, meaning your computer won't slow down if you leave it generating over night. Frankly I'm amazed this isn't part of the base program.

Toggle Live Preview - Another dead simple extension. This one simply puts a toggle for the "live preview setting" on the main txt2img tab

Permanent Controls - Yet another simple extension. This extension just adds a permanent interrupt and permanent skip button to the UI as well as a generate forever button/indicator just below the generate button.

Wildcard Tracer - Adds a wildcard chain section to generated image's metadata detailing which wildcards lead to which parts of the final prompt.

Smart LoRA Cache - An extension which caches LoRAs based on frequency of usage rather than first usage as the "Number of Lora networks to keep cached in memory" setting goes by.

Here's a more detailed view of each:

Image Rater

Download here

This image browser is modeled after Irfanview, optimized for sifting though thousands of generated images. Using this program has greatly increased my ability to actually engage with my generations and pick out the best ones.

The program keeps track of everything by adding prefixes to image names. A viewed but unrated image will get a "-" prefix as soon as it's opened by the program (You can use the green A:- button to toggle this feature off). This feature is intended to help keep track of everything you've at least looked at, and helps with clean up steps from other features.

The UI will change color based on rating for easier clarity while browsing following video game loot colors. Images can be rated from 0 to 5, getting corresponding prefixes and colors:

0: zzz_trash (red)

1: = (white)

2: _ (green)

3: __ (blue)

4: ___ (purple)

5: ____ (orange)

Ratings can go beyond 5, continuing to add underscores to the title. This is intended to make higher rated images appear first when browsing through the folder in windows explorer.

Ratings can be assigned by using the rating toolbar, number buttons on keyboard, or mouse 4 and mouse 5 for better 1 handed rating.

The buttons on the main toolbar are as follows (there are also tooltips built in if you hover your mouse over a button for a second or two):

Open folder

Open current file in windows explorer

Move all files to another folder (subfolders are preserved)

Toggle fit to window

Zoom in

Zoom out

Open thumbnail browser (see below)

Delete all rating 0 (trash) files

Sort files by keywords into subfolders (searches through png metadata for keywords, then sorts your images into subfolders accordingly)

Jump to subfolder (includes jump to last rated image and jump to last viewed image within those subfolders as well)

Show PNG comment metadata

Toggle auto prefix '-'

Rate all '-' as 0 (trash)

Change sort order

Toggle flat mode (ignore subfolders for browsing order)

Settings menu

Then there's the info block, containing the image index within the folder, the image index within it's subfolder as well as the subfolder name, the image's resolution, and the image's rating.

Cycle rating toolbar (top, side, hidden)

Thumbnail Viewer

the thumbnail viewer is also very extensive, mirroring most of the main browser's functions. the main differences are that actions are applied to whatever thumbnail you've clicked on, and the auto prefix with '-' function is replaced with a button that can add or remove that prefix to all images in the folder instead.

UPDATE: Added a search function which makes it only show images with the searched term in the metadata. this function also has the ability to temporarily disable the automatic "-" prefix when in use, disabling it by default. Updated some of the highlighting behavior for the comment window.

Wildcard Editor

Download here

This one is has proven to be a bit buggy, so make sure to periodically back up your wildcards if you use this, and its much safer to write long edits in a different program like notepad++. That said, for inter-wildcard cohesion, this program works wonders for making all your wildcards play nice.

The marquee feature of this program is the ability to double click on a __wildcard__ within the text of a document to switch to that wildcard. This feature alone makes adding tweaks a breeze compared to scrolling though alphabetized document lists for the wildcard you want to change, but this program does so much more.

Within the main text editor window there are a few more features, namely additive highlighting based on (), {} and [] to denote increased strength as well as prompt grouping. LoRAs or anything else encased in <> are highlighted in their own color as well.

Starting at the top, there's the obligatory new, open, save and save as buttons, but the rename function does something special. when a wildcard is renamed in this program, every instance of that wildcard for all wildcards in the wildcard folder are updated with the new name. This way you can rename your wildcards freely without breaking anything. It works the same way when renaming from the document list on the left.

Next there's the browse forwards and back buttons, which work the same way as an internet browser, going forwards and backwards between which wildcards you've viewed, so you can double click a __wildcard__, make your changes, then go back to the wildcard that called it and continue from there. the mouse thumb buttons also control this feature.

Undo and redo

The clone lines button (or Ctrl+D) lets will copy and instantly paste a highlighted line, meant to be used to weigh probabilities for a line to be called.

The wrap wildcard button turns highlighted text into a wildcard by flanking it with the defined wildcard wrapper (usually __), then creates a new document with that wildcard's name in the document list, so you can instantly double click it to start creating that wildcard.

There's a basic find and replace function, followed by a search all popup, which searches through ALL of the wildcards in the wildcard folder and has a replace feature (which can sometimes be buggy :/)

The diagnose button preforms 2 main functions: it searches through all wildcards in the wildcard folder for stray wrapping characters which if present when the dynamic prompts extension is run will completely break the wildcard function. This feature finds and automatically removes any of those issues. The other function is to look for "dead end" wildcards, either a wildcard being called that isn't in your wildcards folder, or an isolated wildcard that neither calls nor is called by any other wildcards in your wildcards folder.

The LoRA button lets you adjust the strength of LoRAs in a document or across all wildcards by an increment, such as strengthening all <lora:il_contrast_slider_d1:#> instances by +0.1 for example.

Text wrap, hotkeys, settings and the tabs toggle are all pretty basic, but the reoganize button is helpful for keeping your wildcards sorted outside of the program. On the left the main text editor window, the document list is much more malleable than it is in most programs. similar to how layer folders are presented in programs like photoshop, you can create and name folders, and drag documents in and out of them. This is where the reogranize button comes in. If you press this button, the program will create sub-folders and move your wildcards around to match what is seen in the document list. Inversely, you can press the import button at the top of the document list to have the document list be populated by your wildcards in their existing folder structure. the cut isolated button in this region removes wildcards that don't call or are not called by any other wildcards from the document list (the actual .txt file is unaffected).

Underneath the document viewer is the wildcards in doc window, which lists out all wildcards present in the currently open document. double clicking any of these in this window will open that wildcard. It also features an open all button, as well as a search use button, which opens a popup that will list out all wildcards in the wildcard folder that call the currently open document.

Lastly in the bottom right corner there's a wrapper confirmation and a spell check toggle. Overall I find this tool incredibly useful, but it definitely is the buggiest out of the lot.

UPDATE: Changed the core of the text editing section to a MUCH more reliable scintilla base.

Wildcard Resolver

Download here

This extension borrows heavily from the wildcard editor in feel. This extension lets you double click a wildcard inside the normal prompt text field to create a drop down menu listing all entries within that wildcard. You can select an entry and the wildcard will be replaced with what you just selected, highlighted slightly orange to indicate that you can right click that text to revert it back to the wildcard it came from.

The extension allows for this feature to stack, so no matter how deep your chain of wildcards goes, this extension can accommodate it.

When double clicking a wildcard, the drop-down menu features a search bar as well as a small toggle button which switches between merely highlighting the searched term within the wildcard entries and only showing entries which contain the searched term.

UPDATE: Added a "lock" feature which lets you lock a wildcard to a certain entry, even if you revert to a higher wildcard. You can find the lock option in the right click menu. In the UI, a locked segment is red rather than orange, and a wildcard containing a locked segment somewhere within it appears magenta rather than purple. You can undo all locks using the forget button in the double click menu.

Anti-Wildcards/Wildcard Combos

Download here

This is actually the very first extension idea I had, years ago. Adding too many negative prompts can be terrible for your generation's quality for many models, so if a wildcard entry needs an added negative prompt, a pose that is very prone to creating a 3rd arm for example, you're normally either forced to add that to the negative prompt, risking degrading all of your images, or leaving it out, risking the extra arm more often then you'd like. This extension solves that by looking at the prompt after the wildcards have been resolved, then changing the negative prompt accordingly.

The extension looks for a .txt document in the wildcards folder named antiwildcards. Each line in this document needs to be formatted as "trigger phrase///phrase to be added to negative prompt" or "trigger phrase//////phrase to be removed from negative prompt". After the wildcards are resolved but before the image starts being generated, this extension will search through the prompt for trigger phrases. If it finds any, it will then add the corresponding phrase to the negative prompt if "///" or try to remove the corresponding phrase from the negative prompt if "//////" is used. Any actions taken will be reported in the command window.

The other function of this extension is the wildcard combos function, which will add a phrase if multiple trigger phrases are present. The extension looks for a .txt document in the wildcards folder named wildcard_combos. each line in this document needs to be formatted as "trigger phrase 1//trigger phrase 2///combo phrase". A line can have any number of additional required trigger phrases. After the wildcards are resolved but before the image starts being generated, this extension will search through the prompt for trigger phrases. If all trigger phrases for a line are present, this extension will add the combo phrase to the prompt just behind the final trigger phrase. Any actions taken will be reported in the command window. An example use case might be having a __location__ wildcard and a __time-of-day__ wildcard in your prompt. A line in your wildcard_combos.txt might read "forest//day//godrays through canopy", helpful if your wildcards land on a forest during the day, but not a forest at night nor a desert during the day.

UPDATE: Added two more functions and documents, combo_replace.txt and antidouble.txt. Combo_replace works similarly to wildcard_combos, but instead of adding the last word at the end, it replaces the last trigger phrase with the combo phrase. Antidouble is formatted as single trigger phrases per line, and will analyze the prompt after resolution for multiple instances of that trigger phrase and will remove all but the first instance from the prompt before generation.

LoRA Auto Tester

Download here

LoRAs come in all shapes, sizes, levels of quality, and degrees of compatibility with your base model and prompting style. Example images might be generated using settings that don't work for you, and it can be tedious to try out dozens of LoRAs one at a time. This extension helps automate this process to help you evaluate several LoRAs easily.

This extension adds a new "Auto-Test LoRAs" tab to Stable Diffusion. On the left side of this tab, there's a list of subfolders within your models/loras folder, as well as a window with thumbnails of all your installed LoRAs. You can either select a folder, or click on thumbnails individually (using the +Add to selection button to select multiple).

On the right, if a single LoRA is selected, its activation text will be listed. Below that, there are the "Truncate at ||" and "Ignore Act. Text" toggle buttons. the Truncate at || will cut the activation text off at the first use of "||" in the activation text, so if you were testing the LoRA backgrounds_multipack.safetensors with the activation text of "d3s3rt || f0r3st || pl41ns || 0c34n", the LoRA will be tested as if the activation text was only "d3s3rt" if this toggle is on. the Ignore Act. Text only tests the LoRA itself within the template you use with no activation text.

Below that are the prompt Templates. In your wildcards folder, you'll need a folder named "autoloratest" where you'll put your testing templates. These templates need to be named after sub-folders in your models/lora folder in order to show up. When a folder, or a LoRA within a folder is selected, the extension will populate this part of the tab with templates that start with the same name that folder. This is to help evaluate different types of LoRAs differently. For example, you might have the sub-folders characters, poses, and backgrounds in your lora folder, so your templates might be named characters_waving_forest.txt, poses_marnie_forest.txt, and backgrounds_marnie_waving.txt, where everything after the underscore doesn't matter.

The templates should be full prompts, but with the category of LoRA being tested replaced with "*lora*". For example, characters_waving_forest.txt might look like "masterpiece, best quality, *lora* waving hello to the viewer while standing in a forest, happy, smiling, eye contact, trees, grass" you can select multiple templates to test for each LoRA, so long as they are all of the same category. for example, you might choose both characters_waving_forest and chracters_running_sportsfield at the same time.

Below that there's a slider for the strength you want your LoRAs to be tested at, as well as all the basic settings for image generation found in the main tab.

Next is a queue function in case you want to add tests of a different category after the current set is done, followed by the run, run queue, and stop after current buttons, all self explanatory.

When run, the extension will test all selected LoRAs lexicographically (alphabetically, starting with capital letters, then lowercase). It will generate an image for each template selected both in your normal image output location in a folder named "Auto-Test LoRAs Outputs" with the same subfolder structure as your LoRAs folder, as well as next to the LoRA file itself. Then, after the last image for a given LoRA is generated, the extension will move the LoRA and its associated files (.info, .json, preview.png) and the newly generated images to a new sub-folder called "tested". The tested folder will also contain 4 empty sub-sub-folders named "good", "retest - prompt tweak", "retest - too strong", "retest - too weak". These are created to help you manually sort though the LoRAs as you evaluate the generated images. There's no "bad" folder as you can simply delete any that don't seem salvageable.

If the folder selected is one of these retest folders, or the individual LoRA being tested is from one of these folders, the settings will automatically change accordingly:

retest - prompt tweak: Truncation at || is turned off

retest - too strong: LoRA strength is set to 0.8

retest - too weak: LoRA strength is set to 1.2

Retroactive Hires Fix

Download here

The hires fix is great for getting detailed generations with a weaker graphics card, but still takes more than double the time to generate compared to just a base image. If the base image is fundamentally flawed, with extra limbs for example, there's no reason to waste time upscaling it. Instead, I prefer to generate my images normally, then pick out the good ones to upscale, however this can be extremely tedious to do after the fact. This extension streamlines that process.

This extension creates a new tab called "Retro Hires Fix". Inside, you'll find the standard settings options for the hires fix function. To the right, you can input a suffix to be added to the upscaled images. Images with this suffix will be ignored by the extension if they're within a folder being processed.

Below both of these you can upload images individually, or a folder using the folder scan tab. This is where integration with the Image Rater comes into play. There is a setting for a minimum prefix threshold, which will only upload images that have prefixes corresponding to ratings high enough. Alternatively, you can just set it to scan all images instead. If you have rated your images using the Image Rater, it will upscale the highest rated images first.

Once upscaled, the new image will be generated into a new sub-folder called "hires", and the original image will be put into a sub-sub-folder within called "source images". The extension is set up such that it will skip anything contained in a folder named "hires" or anything with the -hires suffix, so you can keep re-running the extension on the same folder without retreading old ground.

Memory Cleaner

Download here

This one is the most simple by far. The image gallery accumulates all generated images in the browser's DOM and memory — every image is kept as a base64 blob in Gradio's internal state, and after hundreds of generations overnight it adds up significantly. This extension purges this for all image generated more than 2 batch sets ago, meaning that on the front end, you can still see the previously generate images once a batch finishes, even if you have live previews off and are currently generating just like always, but anything you couldn't see anyway is no longer bogging the system down.

Toggle Live Preview

Download here

This simply puts a green (on) or red (off) button to toggle on or off the live preview function on the txt2img tab, just below where previews/images are shown, right next to the "open images output directory" button. Its meant to give you all the functionality of live previews, but also the cumulative savings of turning them off for overnight generation.

Permanent Controls

Download here

This extension just adds a permanent interrupt and permanent skip button to the UI just below the generate button in case the UI glitches out and presents the generate button even while generating, as it is prone to do. It also adds in a generate forever button/indicator in the same area which you can click to toggle the generate forever feature on and off, and will turn green or red depending on its state.

Wildcard Tracer

Download here

This extension wildcard chain section to generated images metadata detailing which wildcards lead to which parts of the final prompt in the form of __wildcard__<<wildcard contents>>, and can work with many layers of wildcards referring to further wildcards. for example, if "__wildcard__" resolves to "__subwildcard1__" and from that it resolves to "__subwildcard2__ text text text __subwildcard3__", which resolves to the final prompt being "subwildcard2 contents text text text subwildcard3 contents" the wildcard chain section of the metadata will read "__wildcard__<<__subwildcard1__<<__subwildcard2__<<subwildcard2 contents>> text text text __subwildcard3__<<subwildcard3 contents>>>>>>"

This extension is cross compatible with the wildcard resolver and image rater. If the wildcard chain section of an image's metadata is pasted into the txt2img prompt area, if you have the wildcard resolver extension installed, it will be converted back to the final prompt, but as though you selected all the final results via the wildcard resolver rather than typing it in, meaning you can left-click to revert any segment back to the wildcard that called it. for the image rater, the comment popup window will highlight each layer of wildcards a different color for clarity.

Smart LoRA Cache

Download here

This extension smartly chooses which LoRAs to cache, particularly in regards to wildcard usage. If you use lots of LoRAs in your wildcards, this extension will dramatically increase your generation efficiency.

This extension prioritizes which LoRAs to cache based on frequency, rather than simply caching the first LoRAs called as the setting "Number of Lora networks to keep cached in memory" does. It will automatically analyze resolved wildcard prompts and cache LoRAs for the amount of LoRAs set to be kept in memory for the current batch. It does this along with a user defined history, so that if you are generating images overnight for example, it will be more optimized for for wildcards in general, rather than how your wildcards resolved for the current batch.

It can also detect high frequency usage for specific LoRAs (for example if you always use a detail enhancer LoRA in all your generations) and gives you the option to permanently pin those LoRAs to the cache for future use.

You can find all its settings in its sub-tab on the txt2img tab under the generation settings.


I hope you find these tools useful. If there are any issues, bugs, changes you want to make, or features you want added, I highly recommend vibe-coding, specifically with Claude. Simply provide it with the code, the description above, and whatever you need/want changed. You might be surprised what it's capable of, after all, it did all this!

If any of this inspires you to vibe-code your own extensions, tools, or anything else, go for it! Best of luck!

1