///
`sd-webui-infinite-image-browsing` is designed with extensibility in mind, allowing it to adapt to various AI image generation software outputs and to be expanded with custom functionalities through a
132 views
~132 views from guests
Guest views are estimated from total page views. These include anonymous visitors and users who weren't logged in when they viewed the page.
sd-webui-infinite-image-browsing is designed with extensibility in mind, allowing it to adapt to various AI image generation software outputs and to be expanded with custom functionalities through a modular system of parsers and plugins.
The core of sd-webui-infinite-image-browsing's ability to read and categorize images from diverse sources lies in its parsers. These are Python modules located in the scripts/iib/parsers/ directory, each specialized in extracting generation metadata from files produced by a specific AI software.
Role of Parsers:
.txt files.ImageGenerationInfo object, defined in scripts/iib/parsers/model.py. This ensures that the rest of the application (tagging, searching, displaying) can work with a unified data structure.test method that quickly determines if it can correctly process a given image file. This allows the system to automatically select the appropriate parser for each image.Supported Software Parsers (as of codebase):
sd_webui.py / sd_webui_stealth.py): Handles metadata typically found in A1111-generated PNGs (PNG info text chunk) or accompanying .txt files, including a "stealth" parser for hidden metadata.comfyui.py): Processes ComfyUI's unique JSON-formatted metadata, often stored in PNG prompt and workflow chunks or WEBP EXIF.fooocus.py): Extracts information by reading a log.html sidecar file typically generated by Fooocus.novelai.py): Parses metadata found in NovelAI-generated images, typically within a Comment field.stable_swarm_ui.py): Handles metadata embedded in Stable Swarm UI outputs, often in a UTF-16 encoded JSON format within EXIF data.invoke_ai.py): Extracts metadata from the invokeai_graph field in image info.The scripts/iib/parsers/index.py module acts as the central dispatcher, attempting each registered parser in order until one successfully identifies and processes the image.
Beyond just parsing, sd-webui-infinite-image-browsing supports a general plugin system to allow for broader extensibility.
Plugin Loading Mechanism:
scripts/iib/plugin.py module scans a plugins/ directory (located in the application's current working directory).plugins/ that contains a main.py file, it attempts to import main.py as a Python module.Main. An instance of this Main class is created.plugin_insts, plugin_inst_map) within plugin.py, making them accessible to other parts of the application.db/update_image_data.py) uses plugin_inst_map to ask plugins for extra_convert_to_tag_meta_keys, which are additional metadata fields the plugin wants converted into searchable tags.This design allows for modular additions without modifying the core codebase.
Developers can extend sd-webui-infinite-image-browsing by creating new parsers or general-purpose plugins.
If you want to add support for a new AI image generation software, you'll need to create a new parser:
Create a new file: In scripts/iib/parsers/, create a new Python file (e.g., my_new_ai_parser.py).
Define a parser class: Inside this file, define a class (e.g., MyNewAIParser) that adheres to the parser interface:
test(cls, img: Image, file_path: str) -> bool: This class method should take a PIL Image object and the file path. It should perform a quick check to determine if the image was generated by your target AI software. Return True if it can parse the image, False otherwise.
img.info (for PNGs/WebPs) or specific patterns in accompanying .txt files.comfyui.py checks img.info.get('prompt') and img.info.get('workflow').parse(cls, img: Image, file_path: str) -> ImageGenerationInfo: If test returns True, this method will be called. It should extract all relevant generation metadata from the Image object or associated files and construct an ImageGenerationInfo object.
ImageGenerationInfo structure: Refer to scripts/iib/parsers/model.py. The params attribute should contain meta (a dictionary of key-value pairs like "Model", "Sampler", "Steps"), pos_prompt (a list of positive prompt tags), and extra (any additional raw data).sd_webui.py uses read_sd_webui_gen_info_from_image and parse_generation_parameters from scripts/iib/tool.py to get the raw info and then break it down. Your parser might need custom logic for this.Register your parser: Open scripts/iib/parsers/index.py and add your new parser class to the parsers list. The order in this list matters; more specific parsers should come before more generic ones (e.g., SdWebUIStealthParser before SdWebUIParser).
To create a plugin that extends sd-webui-infinite-image-browsing in other ways (e.g., adding custom metadata keys, integrating with external services, or modifying behavior):
sd-webui-infinite-image-browsing extension (or standalone application's cwd), create a plugins/ directory if it doesn't exist. Inside plugins/, create a new subdirectory for your plugin (e.g., plugins/my_custom_plugin/).main.py: Inside your plugin's directory, create a main.py file.Main class:
scripts/iib/db/update_image_data.py calls get_extra_meta_keys_from_plugins(meta.get("Source Identifier", "")) to dynamically get metadata keys from plugins based on the image's "Source Identifier". Ensure your Main class has the necessary attributes or methods that the core application might look for.By following these guidelines, developers can effectively extend the capabilities of sd-webui-infinite-image-browsing to support new AI tools or add custom features.