Sign In

Automatic1111 API: model auto-comparison python script

2

Automatic1111 API: model auto-comparison python script

Prologue

I have a problem: I download too many checkpoint models; mostly because the sample images look great and I feel like I'd love to generate images in that style or of this character, and those cel-shaded designs look awesome. You might know what I mean.

In an effort to create a relatively-standard way of getting an idea of what a model can do for me, I normally set up an XYZ grid within A1111 and feed it a series of prompts (X: Prompt S/R) for a specific set of models (Y: checkpoint name). Because my typical series of test images are generated from 17ish prompts designed to test consistency, character recognizeability, style expression and overall accuracy, I'm limited to 10 or 11 checkpoints at a time. When I have, say, 60 or 70 checkpoints to compare, that's a bit of a timesink.

I generated a (terrible; I'm terrible at python) script to ingest model checkpoint names from a given directory, consume a .yaml containing my prompts, then pass a series of image-creation requests to the A1111 API running on the local machine. It was.. not great.

I fed the base script into Claude 3.7 Sonnet and got back a much-refined version. A few revisions later and I actually have something that saves me time, chewing through 1.6TB of checkpoints in two overnight generation sessions. Finally: caught up! Now to find more models..

Purpose

Automatically create grids of images from a prompt file, using all checkpoints in a given folder, allowing for unattended execution for arbitrary periods of time. Upon completion, every checkpoint - such as checkpoint_Y.safetensors, for example - will have an associated image grid with the filename of checkpoint_Y_grid_<date>-<time>.png containing all the images passed in via the prompt .yaml. Various generation parameters such as seed, CFG, height/width or sampler may be passed along with the initial script call.

Instructions

Prereqs:

You must have the --api flag enabled/passed to your A1111 start parameters. In Windows, I believe that would be accomplished by editing the file webui-user.bat and configuring the COMMANDLINE_ARGS parameter; check documentation. In Linux environments, edit webui-user.sh and ensure that the export COMMANDLINE_ARGS= line contains --api.

The Python package pillow and requests are leveraged; pillow is ostensibly non-mandatory, though I've never tested the fallback code. In any case, both packages are in A1111's requirements.txt, so the presumption is that they're installed.

Execution:

Call the script via python as you would normally, e.g.:

python3 ./automatic1111_grid_generator.py --checkpoint-folder <path_to_checkpoints> --output-folder <folder_for_output_images> --prompts-file ./sample_prompts.json --width 896 --height 1152 --sampler "Euler" --add-prompt-labels --steps 24 --cfg-scale 6.0

Syntax of flags for things like sampler, width, height, local port number, etc., are available by calling:

 ./automatic1111_grid_generator.py  --help

If you want to edit some of the defaults (local port number or to enter a remote IP, for instance), you may edit the .py file to obviate the need to pass the parameter via command-line switch.

Caveats

The script is provided entirely free from warranty; use of the provided code indemnifies all providing parties and/or advice-givers of any responsibility of adverse effect. If you don't know what you're doing, stop :)

I have no intent to maintain, grow or bugfix this code. You're free to use it in any legal fashion you see fit, including selling, republishing, sharing, remixing or otherwise enjoying/profiting from it.

Updated: added highres fix flags

2