Package: sd-parsers
FeaturesSupports reading metadata from images generated with:Automatic1111's Stable Diffusion web UIComfyUI *InvokeAINovelAIProvides a list of prompts used in the generation of the image, as well as generator-specific metadata.* Custom ComfyUI nodes might parse incorrectly / with incomplete data.Installationpip install sd-parsersUsageFor a simple query, importParserManagerfromsdparsersand use itsparse()method to parse an image. (seeexamples)TheParserManager()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:fromsdparsersimportParserManagerparser_manager=ParserManager()prompt_data=parser_manager.parse('image.png')forprompt,negative_promptinprompt_data.prompts:ifprompt:print(f"Prompt:{prompt.value}")ifnegative_prompt:print(f"Negative Prompt:{negative_prompt.value}")Read prompt information from an already opened image:fromPILimportImagefromsdparsersimportParserManagerparser_manager=ParserManager()withImage.open('image.png')asimage:prompt_data=parser_manager.parse(image)...Each parser can also be used directly, omitting the use ofParserManager.For that simply import the specific parser instead:fromPILimportImagefromsdparsersimportAUTOMATIC1111Parserparser=AUTOMATIC1111Parser()withImage.open("image.png")asimage:prompt_info=parser.parse(image)Directly using a specific parser, the configuration file is not read automatically. (seeParserManager.__init__())Also, when not called viaParserManager, theparse()method now requires a Pillow Image object as argument. (seeParserManager.parse())OutputTheparse()method returns aPromptInfotype with the following properties (orNoneif 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 ifParserManageris used withprocess_itemsset 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 ifParserManageris used withprocess_itemsset 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"CreditsIdea and motivation using AUTOMATIC1111's stable diffusion webuihttps://github.com/AUTOMATIC1111/stable-diffusion-webuiStealth PNGInfo code adopted from ashen-sensored's sd webui extensionhttps://github.com/ashen-sensored/sd_webui_stealth_pnginfoExample workflows for testing the ComfyUI parserhttps://github.com/comfyanonymous/ComfyUI_examples