ComfyUI Extension: SD Prompt Reader
The ultimate solution for managing image metadata and multi-tool compatibility. ComfyUI node version of the SD Prompt Reader.
Custom Nodes (11)
README
This is a subproject of the <a href="https://github.com/receyuki/stable-diffusion-prompt-reader">SD Prompt Reader.</a> It helps you extract metadata from images in any format supported by the <a href="https://github.com/receyuki/stable-diffusion-prompt-reader">SD Prompt Reader</a> and saves the images with additional metadata to ensure compatibility with metadata detection on websites such as Civitai. <br>
<p> <a href="#supported-formats">Supported Formats</a> • <a href="#installation">Installation</a> • <a href="#usage">Usage</a> • <a href="./CHANGELOG.md">Change Log</a> • <a href="#credits">Credits</a> </p> <img src="./images/screenshot_v130.png"> </div>Supported Formats
| | PNG | JPEG | WEBP | TXT* | |----------------------------------------------------------------------------------------|:---:|:----:|:----:|:----:| | A1111's webUI | ✅ | ✅ | ✅ | ✅ | | Easy Diffusion | ✅ | ✅ | ✅ | | | StableSwarmUI* | ✅ | ✅ | | | | StableSwarmUI (prior to 0.5.8-alpha)* | ✅ | ✅ | | | | Fooocus-MRE* | ✅ | ✅ | | | | NovelAI (stealth pnginfo) | ✅ | | ✅ | | | NovelAI (legacy) | ✅ | | | | | InvokeAI | ✅ | | | | | InvokeAI (prior to 2.3.5-post.2) | ✅ | | | | | InvokeAI (prior to 1.15) | ✅ | | | | | ComfyUI* | ✅ | | | | | Draw Things | ✅ | | | | | Naifu(4chan) | ✅ | | | |
See SD Prompt Reader for details
Installation
[!NOTE] While ZIP package is available, it is strongly recommended not to use it for installation.
Install and update via ComfyUI Manager (Recommended)
Search for SD Prompt Reader in the ComfyUI Manager and install it.
Install manually
Please make sure to install the submodules along with the main repository.
cdto thecustom_nodefolder- Clone this repo
git clone --recursive https://github.com/receyuki/comfyui-prompt-reader-node.git - Install dependencies
cd comfyui-prompt-reader-node pip install -r requirements.txt
Update
When updating, don't forget to include the submodules along with the main repository.
git pull --recurse-submodules
Usage
Prompt Reader Node
<div align="center"> <img src="./images/reader.png" width="25%" height="25%" alt="reader node"> </div>- The
Prompt ReaderNode works exactly the same as the standalone SD Prompt Reader. It uses the Image Data Reader from the standalone SD Prompt Reader, allowing it to support the same formats and receive updates along with the SD Prompt Reader.
<details> <summary><b>More Information</b></summary>[!IMPORTANT] Due to custom nodes and complex workflows potentially causing issues with SD Prompt Reader's ability to read image metadata correctly, it is recommended to embed the
Prompt SaverNode within the workflow to ensure maximum compatibility.
parameter_index
- For images containing multiple sets of parameters, such as those processed through
hires-fixorrefiner, you will need to modify theparameter_indexto select the parameters you need
SDXL
- For images generated by SDXL and containing multiple sets of prompts,
the
text_gwill be combined withtext_linto a single prompt
Batch Read
- For batch processing, please use the
Batch Loadernode. When using theBatch Loadernode for bulk reading, the preview image will not update, and the text box will only display the metadata of the last image.
Additional Parameters
- To read parameters other than the existing output, please connect the
settingsto theParameter Extractornode.
MODEL_NAME
MODEL_NAMEis a special output that matches the model name in the metadata with the existing models on the server according to the following priority:- Identical path, filename, and extension.
- Identical filename, and extension.
e.g.
sd_xl_base.safetensorswill be matched withSDXL\sd_xl_base.safetensors, and vice versa. - Identical filename.
e.g.
sd_xl_basewill be matched withSDXL\sd_xl_base.safetensors, and vice versa. - If a matching model cannot be found, the original name will be outputted.
Prompt Saver Node
<div align="center"> <img src="./images/saver.png" width="25%" height="25%" alt="saver node"> </div>- The
Prompt SaverNode and theParameter GeneratorNode are designed to be used together. - The
Prompt SaverNode will write additional metadata in the A1111 format to the output images to be compatible with any tools that support the A1111 format, including SD Prompt Reader and Civitai. - Due to custom nodes and complex workflows potentially causing issues with SD Prompt Reader's ability to read image metadata correctly, it's recommended to embed this node within the workflow to ensure maximum compatibility.
<details> <summary><b>More Information</b></summary>[!TIP] Since it's not possible to directly extract metadata from
KSampler, it's necessary to use theParameter GeneratorNode to generate parameters and simultaneously output them to thePrompt SaverNode andKSamplerNode.
Image Format
- Only PNG format supports embedding both metadata and workflow at the same time. Other formats can only embed metadata.
Duplicate Filename
- When the filename already exists, an index will be added at the end of the filename,
e.g.
file.png, file_1.png, file_2.png.
Hashes & Auto-Detection on Civitai
- When
calculate_hashis enabled, the node will compute the hash values of checkpoint, VAE, Lora, and embedding/Textual Inversion, and write them into the metadata. After the server restarts, or a new checkpoint, VAE, Lora, or embedding/Textual Inversion is loaded, the first image generation may take a longer time for hash calculation. The hash value will be stored in temporary storage without the need for repeated calculation, until the server is restarted. - When
resource_hashis enabled, the resource hashes will be written into the metadata to support auto-detection on Civitai. This function will only run whencalculate_hashis enabled. - If you need to calculate the hash of Lora, please use the
Lora LoaderNode or theLora SelectorNode. The hash value of the embedding/Textual Inversion will be automatically detected from the prompt.
save_metadata_file
- When the
save_metadata_fileis turned on, the metadata will be saved as a TXT file with the same name alongside the image.
date_format & time_format
- For the
date_formatandtime_format, please refer to strftime.org or www.strfti.me.
filename & path
-
%countercannot be used forpath, it can only be used forfilename. This%counteris slightly different from the%counterin the built-inSavernode, it will count all image files in thepath. -
Please refer to the following table for placeholders supported by the
filenameandpath.| | | |------------|------------| | %seed | %date | | %steps | %time | | %cfg | %counter | | %model | %extension | | %sampler | %quality | | %scheduler | |
Parameter Generator Node
<div align="center"> <img src="./images/generator.png" width="25%" height="25%" alt="generator node"> </div>- Since it's not possible to directly extract metadata from
KSampler, it's necessary to use theParameter GeneratorNode to generate parameters and simultaneously output them to both thePrompt SaverNode andKSamplerNode.
<details> <summary><b>More Information</b></summary>[!TIP] The
Parameter GeneratorNode can also be used as a control panel for complex ComfyUI workflows, just like the AP workflow.
Optimal Resolution
- The
model_versionandaspect_ratioare used only for calculating the optimal resolution of the selected model version under the chosen aspect ratio. The calculation method is based on the Stability AI development documentation and the StableSwarmUI source code (developed by Stability AI).
refiner_start
refiner_startrefers to the proportion of steps completed when the refiner starts running, i.e., the proportion of base steps to total steps. This is used to calculate thestart_at_step(REFINER_START_STEP) required by the refinerKSamplerunder the selected step ratio.
Batch Loader Node
<div align="center"> <img src="./images/loader.png" width="25%" height="25%" alt="loader node"> </div>- The
Batch LoaderNode is specifically designed for thePrompt ReaderNode to batch-read image files in a directory and cannot be used with other custom nodes.
- For batch processing, please connect the
IMAGEoutput of theBatch LoaderNode to theimageinput of thePrompt ReaderNode.
path
- The
pathsupports relative paths such as./input/or absolute paths likeC:/Users/receyuki/Pictures. - Both
\and/are acceptable. - You can also input a single file or a list of files into the
path, in which case theimage_load_limitandstart_indexwill not function.
Parameter Extractor Node
<div align="center"> <img src="./images/extractor.png" width="25%" height="25%" alt="extractor node"> </div>- The
Parameter ExtractorNode is an extension of thePrompt ReaderNode, designed to retrieve the values of all parameters in the settings (including those parameters that thePrompt ReaderNode cannot output). e.g.Hires upscaler
- Connect the
SETTINGSof thePrompt ReaderNode to thesettingsof theParameter ExtractorNode. After the first run, the parameter list will be loaded.
Prompt Merger Node & Type Converter Node
<div align="center"> <img src="./images/merger_converter.png" width="25%" height="25%" alt="merger and converter node"> </div>- Since the A1111 format cannot store
text_gandtext_lseparately, SDXL users need to use thePrompt MergerNode to combinetext_gandtext_linto a single prompt. - Since
model_name,sampler_name, andschedulerare special types that cannot be directly used by some other nodes, You can use theType ConverterNode to convert them intoSTRINGtype.
Lora Loader Node & Lora Selector Node
<div align="center"> <img src="./images/lora.png" width="50%" height="50%" alt="lora loader and selector node"> </div>- The
Lora LoaderNode andLora SelectorNode are used to write Lora data into metadata and support auto-detection on Civitai.
- Replace the original loader with the
Lora LoaderNode, or connect theLORA_NAMEoutput of theLora SelectorNode to thelora_nameinput of other lora loaders (built-in or custom), and link theNEXT_LORAoutput to thelora_nameinput of thePrompt SaverNode. Both of these nodes have the same function, please choose according to your needs.
Multiple Loras
- If you need to load multiple Loras, please connect the
Lora LoaderNode orLora SelectorNode head to tail throughlast_loraandNEXT_LORA, and connect theNEXT_LORAat the end of the Lora chain to thelora_nameinput of thePrompt SaverNode.
- Lora Loader chain
- Lora Selector chain
Example Workflow
<details> <summary><b>Simple Example</b></summary> <div align="center"> <img src="./workflows/simple_example.png" width="100%" height="100%" alt="example workflow"> </div> </details> <details> <summary><b>Lora Example</b></summary> <div align="center"> <img src="./workflows/lora_example.png" width="100%" height="100%" alt="example workflow"> </div> </details> <details> <summary><b>Hires-fix Example</b></summary> <div align="center"> <img src="./workflows/hires_fix_example.png" width="100%" height="100%" alt="example workflow"> </div> </details> <details> <summary><b>SDXL Example</b></summary> <div align="center"> <img src="./workflows/sdxl_example.png" width="100%" height="100%" alt="example workflow"> </div> </details>Credits
- The SD Prompt Reader node is based on ComfyUI Load Image With Metadata
- The SD Prompt Saver node is based on Comfy Image Saver & Stable Diffusion Webui
- The seed generator in the SD Parameter Generator is modified from rgthree's Comfy Nodes
- A special thanks to @alessandroperilli and his AP Workflow for providing numerous suggestions