Giter VIP home page Giter VIP logo

sd-parsers's Introduction

Important

Version 0.3 featuring a revisited API and extended ComfyUI & InvokeAI parsing logic is available.

See release notes for changes.

Features

Supports reading metadata from images generated with:

  • Automatic1111's Stable Diffusion web UI
  • ComfyUI *
  • InvokeAI
  • NovelAI

Provides 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.

Installation

pip install sd-parsers

Usage

From command line: python3 -m sd_parsers <filenames>.

Basic usage:

For a simple query, import ParserManager from sd_parsers and use its parse() method to parse an image. (see examples)

Read prompt information from a given filename:

from sd_parsers import ParserManager

parser_manager = ParserManager()

def main():
    prompt_info = parser_manager.parse("image.png")

    if prompt_info:
        for prompt in prompt_info.prompts:
            print(f"Prompt: {prompt.value}")

Read prompt information from an already opened image:

from PIL import Image
from sd_parsers import ParserManager

parser_manager = ParserManager()

def main():
    with Image.open('image.png') as image:
        prompt_info = parser_manager.parse(image)

Each parser module can also be used directly, omitting the use of ParserManager:

from PIL import Image
from sd_parsers.exceptions import ParserError
from sd_parsers.parsers import AUTOMATIC1111Parser

parser = AUTOMATIC1111Parser()

def main():
    with Image.open("image.png") as image:
        try:
            prompt_info = parser.read_parameters(image)
    
            if prompt_info:
                # the following can be omitted for an equivalent
                # of ParserManager(lazy_read=True)
                prompt_info.parse()

        except ParserError:
            ...

Output

The output returned from ParserManager is a PromptInfo object (as can be seen when executing python3 -m sd_parsers <image.png>) or None if no metadata was found.

PromptInfo contains the following properties :

  • generator: Specifies the image generator that may have been used for creating the image.

  • prompts: Prompts as found in the parsed metadata.

  • negative_prompts: Negative prompts as found in the parsed metadata.

  • samplers: Samplers used in the image generation process.

  • models: Models used in the image generation process.

  • metadata: Additional metadata which could not be attributed to one of the former described.

    Highly dependent on the provided data structure of the respective image generator.

  • parameters: A dictionary of unmodified metadata entries as found in the parsed image (if present).

Contributing

As i don't have the time and resources to keep up with all the available AI-based image generators out there, the scale and features of this library is depending greatly on your help.

If you find the sd-parsers library unable to read metadata from an image, feel free to open an issue.

See CONTRIBUTING.md, if you are willing to help with improving the library itself and/or to create/maintain an additional parser module.

Credits

Idea and motivation using AUTOMATIC1111's stable diffusion webui

Example workflows for testing the ComfyUI parser

sd-parsers's People

Contributors

d3x-at avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

sd-parsers's Issues

Update import statement in README or refactor code.

When using pip to install the package, it is installed as sdparsers and not sd_parsers. Importing the library now requires sdparsers instead of sd_parsers. Please either refactor code or fix the documentation in README.md.

image cannot be parsed

Hi,
this image failed to be parsed, prompt_data = parser_manager.parse(filename) returns None
I got the image from civitai.com, PNG info from automatic1111 can parse it.

Thanks.

00031-3995568945

AttributeError: 'list' object has no attribute 'strip'

i`m trying to read comfyui metadata, and have this error:

PS D:\rep\pnginfo> File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\sdparsers\parsers\comfyui.py", line 139, in _get_prompt positive_id, positive_prompt = get_prompt( File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\sdparsers\parsers\comfyui.py", line 131, in get_prompt parts = list(self._get_parts(image_data, source_id, text_keys)) File "C:\Users\User\AppData\Local\Programs\Python\Python310\lib\site-packages\sdparsers\parsers\comfyui.py", line 163, in _get_parts yield node['inputs'][text_key].strip() AttributeError: 'list' object has no attribute 'strip'

Saving SD info to images

Would it be an idea to have the ability to save SD info to images?
Could have it save by which parser you choose?

I've been considering adding that to Promptvision, but your idea of using this as a lib is much better.

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.