This is a dumping ground for small genai-related scripts and data files.
-
sui.py - CLI for SwarmUI API; commands are:
- gen: create an image based on rules, metadata, and options
- jpg: batch-convert image files to JPG, optionally resizing them
- webp: batch-convert image files to WEBP w/stealth metadata
- rename: batch-rename image files based on --pre|set|seq options
- resize: batch-resize image files by percentage or target pixels
- params: extract parameters from PNG, JPG, and JSON files
- prompt: shortcut for
params -p - list-rules: list canned parameter sets (built-in or ~/.sui)
- list-models: list available base models, loras, or vae
- list-luts: print list of available LUTs
- list-params: print list of T2I params available on the server
- preset: create a server preset from merged image metadata
- status: return server/backend status
Note: to avoid getting into the weeds with EXIF, PyExifTool is used,
which requires the exiftool binary be in your
path. Yes, the best way to deal with EXIF in Python is a Perl script.
-
sui-ws.py - experimental version of sui.py using the websocket API to generate images and store the per-step preview images as an animated WEBP.
-
dp.py - CLI wrapper to use the popular dynamicprompts library with image-generation software that doesn't support it directly.
-
prompt.py - pass each line from STDIN to an LM Studio server, with the system prompt set for prompt enhancement. Server url, model, and default system prompt can be set in
~/.pypromptIf the strings@<and>@are detected in a prompt, pass only the section between them to the LLM, keeping the rest intact.-l: list available models on the server-m: use a specific model-t: set model temperature- sysprompt: search
~/.pypromptfor an alternative system prompt
-
prompt_ollama_server.py - minimal Ollama server to feed generated prompts to the SwarmUI GUI via the MagicPrompt extension. You use the companion script
prompt_server_feed.shto upload a bunch of one-line prompts, and the server will return them as chat responses, in the order they were uploaded. -
ollama2lmstudio.py - shim that emulates an Ollama server and forwards requests to LM Studio. TL/DR: MagicPrompt doesn't support LM Studio directly, and using the OpenAI API emulation is flaky. Works for MagicPrompt's chat, prompt, and vision modes; hasn't been tested for anything else.
-
pyshed.py - efficiently emulate the behavior of
shuf|headfor very large text files, quickly retrieving N random lines.-c: number of random lines to extract (default 10)
-
aspect.py - calculate resolutions for arbitrary aspect ratios that do not exceed the "standard" pixel count (sidelength squared) for a model.
-
waifupaper.py - MacOS wallpaper-rotation script with more options than the standard control-panel settings.
-
lmscrub.pl - scrub server responses from an LM Studio chat, leaving only the user prompts.
-
unasp.pl - find the closest well-known aspect ratio for the given resolution(s)
-
randompeople.yaml - dynamicprompts wildcards converted from a heavily-randomized prompt posted to the SwarmUI Discord channel by user Hippotes, with some typos corrected and some weights added. Use as
__p/random__.
- click
- dynamicprompts (dp.py only)
- fastapi (ollama2lmstudio.py & prompt_ollama_server.py)
- lmstudio (prompt.py only)
- pillow
- PyExifTool
- PyYAML (dp.py only)
- requests
- uvicorn (ollama2lmstudio.py & prompt_ollama_server.py)
- websockets (sui-ws.py only)
Typically I generate a few hundred prompts with dp.py, feed them to
sui.py -j gen on STDIN, pick the best ones with my
deathmatch script, and then
use those files as arguments to sui.py gen with refining and
upscaling parameters added.
dp.py __prompt/christmas__ | sui.py --pre out/zit --set xmas -j \
gen -r zit,1080p
deathmatch out
...
sui.py --pre out/zit --set xmas4k -j \
gen -r zit,4k -u -L sensia out/*-{01,15,19,37,82}.jpg
The most recent workflow change is integrating an LLM to enhance part of the prompt to improve variety (prompt script not yet checked in), and then append it to a separate dynamic prompt that didn't get "enhanced" (because most LLMS have odd ideas on how to "enhance" people for diversity):
# "-c" is passed to sui.py solely for the progressbar
dp.py -c 100 __location__ | prompt.py |
dp.py --merge -c 100 __subject__ |
sui.py --pre zit --set withllm gen -c 100 -r zit,1080p
- stealth.py - quick hack to read SwarmUI "stealth" metadata from WEBP and PNG images. I'm only leaving this around because I linked to it elsewhere; the tested read/write code has been rolled into sui.py