Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:AUTOMATIC1111 Stable diffusion webui User Metadata Editor

From Leeroopedia
Revision as of 14:04, 16 February 2026 by Admin (talk | contribs) (Auto-imported from implementations/AUTOMATIC1111_Stable_diffusion_webui_User_Metadata_Editor.md)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


Knowledge Sources
Domains Extra Networks, Metadata Management
Last Updated 2025-05-15 00:00 GMT

Overview

Implements the UserMetadataEditor class that provides a Gradio-based popup UI for viewing and editing user-defined metadata (description, notes, preview images) for extra network items such as models, LoRAs, and embeddings.

Description

The UserMetadataEditor class creates a modal editor UI within the extra networks panel. It is initialized with a reference to the parent UI, tab name, and the extra networks page it belongs to. The editor provides fields for viewing the item name, editing a description and notes, displaying file metadata (filename, file size, hash, modification date), and showing/replacing a preview image.

Key methods include:

  • get_user_metadata(name) - Retrieves user metadata for a named item, initializing it from the item's description if absent.
  • create_default_editor_elems() - Builds the two-column layout with name, description, file data on the left and preview on the right.
  • create_default_buttons() - Creates Cancel, Replace Preview, and Save buttons with status display.
  • get_card_html(name) - Generates HTML for the preview card image.
  • get_metadata_table(name) - Returns file metadata as a list of label-value pairs.
  • put_values_into_components(name) - Populates all editor fields from stored metadata.
  • write_user_metadata(name, metadata) - Persists metadata to a JSON sidecar file alongside the model file.
  • save_preview(index, gallery, name) - Saves a gallery image as the item's preview image.
  • create_ui() - Assembles the full popup UI with hidden trigger elements.
  • setup_ui(gallery) - Wires up the replace preview button to the gallery.

Usage

Use this class when building extra networks pages that need user-editable metadata. Subclass it to add custom fields or behaviors for specific network types.

Code Reference

Source Location

Signature

class UserMetadataEditor:
    def __init__(self, ui, tabname: str, page)
    def get_user_metadata(self, name: str) -> dict
    def create_extra_default_items_in_left_column(self) -> None
    def create_default_editor_elems(self) -> None
    def create_default_buttons(self) -> None
    def get_card_html(self, name: str) -> str
    def relative_path(self, path: str) -> str
    def get_metadata_table(self, name: str) -> list[tuple]
    def put_values_into_components(self, name: str) -> tuple
    def write_user_metadata(self, name: str, metadata: dict) -> None
    def save_user_metadata(self, name: str, desc: str, notes: str) -> None
    def setup_save_handler(self, button, func, components) -> None
    def create_editor(self) -> None
    def create_ui(self) -> None
    def save_preview(self, index, gallery, name: str) -> tuple
    def setup_ui(self, gallery) -> None

Import

from modules.ui_extra_networks_user_metadata import UserMetadataEditor

I/O Contract

Inputs

Name Type Required Description
ui object Yes Parent UI object reference.
tabname str Yes Name of the tab (e.g., "txt2img", "img2img").
page ExtraNetworksPage Yes The extra networks page this editor is associated with.
name str Yes The name/identifier of the extra network item being edited.
desc str Yes User-provided description text for save_user_metadata.
notes str Yes User-provided notes text for save_user_metadata.
index int Yes Gallery image index for save_preview.
gallery list Yes List of gallery image info objects for save_preview.

Outputs

Name Type Description
editor_values tuple Tuple of (name_html, description, filedata_html, preview_html, notes) from put_values_into_components.
preview_result tuple Tuple of (preview_html, status_message) from save_preview.

Usage Examples

from modules.ui_extra_networks_user_metadata import UserMetadataEditor

class MyNetworkMetadataEditor(UserMetadataEditor):
    def create_extra_default_items_in_left_column(self):
        # Add custom fields to the editor
        import gradio as gr
        self.custom_field = gr.Textbox(label="Custom Field")

    def create_editor(self):
        super().create_editor()
        # Wire up custom save logic
        self.setup_save_handler(
            self.button_save,
            self.save_custom_metadata,
            [self.edit_description, self.edit_notes, self.custom_field]
        )

# Standard usage in an extra networks page
editor = UserMetadataEditor(ui=demo, tabname="txt2img", page=lora_page)
editor.create_ui()
editor.setup_ui(gallery=txt2img_gallery)

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment