GithubHelp home page GithubHelp logo

grauho / sdpromptdumper Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 31 KB

A command line tool to convert stable-diffusion.cpp generated image metadata back into a valid stable-diffusion.cpp invocation.

License: BSD 4-Clause "Original" or "Old" License

Makefile 1.07% C 98.93%
ansi-c c c89 c90 c99 civitai cli metadata png stable-diffusion

sdpromptdumper's Introduction

sdPromptDumper, stable-diffusion.cpp Prompt Dumper

This program is a simple tool to take the metadata information that is encoded into images produced by stable-diffusion.cpp and use it to construct a valid stable-diffusion.cpp invocation. Naturally due to the limitations of the information encoded this merely produces the closest invocation that it can get with the information provided.

I made this tool because I often want to go back to previously generated images and experiment with tweaking various settings but it was annoying to copy and paste each option from a PNG metadata inspector program. This way the user just has to run a single program and copy and paste a single command that they have the option of editing beforehand.

I considered just writing this in Perl but figured access to a working C99 compiler was a lower bar to clear than having a Perl interpreter, especially those on platforms where Perl is not immediately available. Plus, this was a fun excuse to write a little non-destructive tokenizer and dig into the PNG specification a little bit.

Tested and works on images produced by the following programs:

Building

This program has no external dependencies beyond the C standard library. It requires at least a C99 compliant compiler due to its inclusion of stdint. The adventurous can provide an alternative header with definitions for those specific bit-width types should they wish to compile it with a C90 compiler.

A Makefile is provided for those with access to POSIX make, the program can be built as follows:

make

Otherwise, it should suffice to simply build the object files and link them together manually:

cc -Wall -pedantic -O2 -c -o main.o main.c
cc -Wall -pedantic -O2 -c -o stiTokenizer.o stiTokenizer.c
cc -Wall -pedantic -O2 -c -o pngProcessing.o pngProcessing.c
cc -Wall -pedantic -O2 -c -o loadConfig.o loadConfig.c
cc -Wall -pedantic -O2 -o sdPromptDump main.o stiTokenizer.o pngProcessing.o loadConfig.o

Notes:

  • PNG files contain values encoded using Big-Endian byte order, this program addresses this already for those on little-endian systems. If for whatever reason all PNG files are failing to process try running the program with the -e switch and checking that the result agrees with the system byte order. See the information below for more information.

Command Line Options

-M, --model  <DIR PATH> : Prepends this path to the encoded model name 
-L, --lora   <DIR PATH> : Passes this path directly to --lora-model-dir
-B, --bin    <DIR PATH> : Prepends this path to the sd executable 
-E, --exe   <FILE NAME> : Alternative name for the sd executable
-V, --vae   <FILE PATH> : Passes this file path directly to --vae
-c, --config <DIR PATH> : Path to alternative config file directory
-a, --abrv              : Uses abreviated switch names in the output
-e, --endian            : Prints assumed endian form and exits
-h, --help              : Prints a help message much like this one

Notes:

  • By default no path is prepended to "sd" in the result unless set with -B, this is to accommodate those who have it installed somewhere like /usr/local/bin. Default arguments for --model, --lora, --vae, --bin, --exe, and --abrv may be set by providing a configuration file, sdPromptDumper.cfg, in the appropriate directory. ie:

    POSIX: $HOME/.config/sdPromptDumper/sdPromptDumper.cfg

    WINDOWS: %HOMEPATH%\AppData\Local\sdPromptDumper\sdPromptDumper.cfg

  • Users should create the configuration directory themselves. An alternative configuration path may be supplied with the -c, --config switch. An example config file is included in this repo, exampleConfig.cfg, This has only been tested on Linux.

  • Should the endian switch suggest a different byte order than what is known to be the system order the behavior can be forced by defining either PORTEGG_LITTLE_ENDIAN_SYSTEM or PORTEGG_BIG_ENDIAN_SYSTEM either using a compiler switch or simply before portegg.h is included in the main.h header.

  • This program was written to work with images produced using txt2img and lacks handling for other modes or more advanced workflows that don't have their information encoded into the resulting output image. It should also go without saying that this program will only work with programs generated using stable-diffusion.cpp or ones using the same metadata encoding style that have not had their metadata stripped.

Example Invocation

./sdPromptDumper --model ~/.sd/models/ --vae myVAE.safetensors foo.png bar.png

Bugs

  • Please report any bugs or issues to the associated github issues page for this repository.

License

License information can be found in the LICENSE.txt file in this repository.

sdpromptdumper's People

Contributors

grauho avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.