SD Parsers - read metadata from images created by Stable Diffusion
Project description
Features
Supports reading metadata from images generated with:
- Automatic1111's Stable Diffusion web UI
- ComfyUI
- Invoke AI
- NovelAI
Provides a list of prompts used in the generation of the image, as well as generator-specific metadata.
Installation
pip install sd-parsers
Usage
For a simple query, import ParserManager
from sdparsers
and use its parse()
method to parse an image. (see examples)
The ParserManager()
constructor takes two arguments:
config_file
: If you want to provide alternate processing instructions. (absolute path to config file)process_items
: If the parser should try to normalize the output across the different image sources. (defaults toTrue
)
Basic usage:
Read prompt information from a given filename:
from sdparsers import ParserManager
parser_manager = ParserManager()
prompt_data = parser_manager.parse('image.png')
for prompt, negative_prompt in prompt_data.prompts:
if prompt:
print(f"Prompt: {prompt.value}")
if negative_prompt:
print(f"Negative Prompt: {negative_prompt.value}")
Read prompt information from an already opened image:
from PIL import Image
from sdparsers import ParserManager
parser_manager = ParserManager()
with Image.open('image.png') as image:
prompt_data = parser_manager.parse(image)
...
Each parser can also be used directly, omitting the use of ParserManager
.
For that simply import the specific parser instead:
from PIL import Image
from sdparsers import AUTOMATIC1111Parser
parser = AUTOMATIC1111Parser()
with Image.open("image.png") as image:
prompt_info = parser.parse(image)
Directly using a specific parser, the configuration file is not read automatically. (see ParserManager.__init__()
)
Also, when not called via ParserManager
, the parse()
method now requires a Pillow Image object as argument. (see ParserManager.parse()
)
Output
The parse()
method returns a PromptInfo
type with the following properties (or None
if no metadata was found):
-
generator
: A simple string, specifying the parsing module that was used.("AUTOMATIC1111" | "AUTOMATICStealth" | "ComfyUI" | "InvokeAI")
-
prompts
: A list of tuples of prompts as found in the parsed metadata.In the form of
(prompt, negative_prompt)
. -
samplers
: An unordered list of found samplers (and parameters).The key values of the parameters dictionary will be normalized to be more consistent across image generators if
ParserManager
is used withprocess_items
set toTrue
. -
models
: An unordered list of models used in the generation process. -
metadata
: A dictionary of metadata besides the prompt information.Contains additional parameters which are found in the image metadata.
Highly dependent on the provided data structure of the respective image generator.
The key values of this dictionary will be normalized to be more consistent across image generators if
ParserManager
is used withprocess_items
set toTrue
. -
raw_params
: A dictionary of the unmodified metadata entries found in the parsed image (if present).- Automatic1111:
"parameters"
- InvokeAI:
"sd-metadata"
and"Dream"
- ComfyUI:
"prompt"
and"workflow"
- Automatic1111:
Credits
Idea and motivation using AUTOMATIC1111's stable diffusion webui
Stealth PNGInfo code adopted from ashen-sensored's sd webui extension
Example workflows for testing the ComfyUI parser
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for sd_parsers-0.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3780026de6da79763f271158c8686984a0e13204ee9a395c5f8d94b531c13584 |
|
MD5 | aa1d7069e2d1f0eb23c681c6200a7b87 |
|
BLAKE2b-256 | 2487caa23d9b71e01f8d7f1a380a548a0ee21ee073d590e1bfcb31999e6484bb |