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.-i imagefile: upload an image and send an appropriate sysprompt-l: list available models on the server-m: use a specific model-n: disable thinking-r: don't strip newlines from output (mostly for Markdown)-s: list available sysprompts from the file~/.pyprompt-S: dump the contents of the selected sysprompt-t: set model temperature-u: set the URL of the LM Studio server- sysprompt: search
~/.pypromptfor an alternative system prompt; multiple sysprompt arguments will be invoked in order.
-
sysprompts/*.txt - prompt-enhancement system prompts collected from various models.
prompt.pycurrently defaults tohidream.txt. -
prompt-server/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.prompt_server_count.shreturns the current number of loaded prompts andprompt_server_clear.shdeletes them all. Set your prompt to<param[mpusecache]:false><mpprompt:test>and hit "Generate Forever". -
ol2lm.py - shim that emulates an Ollama server and forwards requests to LM Studio. Works for both the MagicPrompt and Ollamavision extensions (although Ollamavision now has stable support for LM Studio via its OpenAI API support).
-
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)
-
namescrub.py - trivial batch-rename script to strip out special characters
-
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 (ol2lm.py & prompt-server/prompt_ollama_server.py)
- lmstudio (prompt.py only)
- pillow
- PyExifTool
- PyYAML (dp.py only)
- requests
- uvicorn (ol2lm.py & prompt-server/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