Implementation:AUTOMATIC1111 Stable diffusion webui UI Extensions
| Knowledge Sources | |
|---|---|
| Domains | UI, Extensions, PackageManagement |
| Last Updated | 2025-05-15 00:00 GMT |
Overview
The UI extensions module implements the Extensions tab interface, providing functionality to view installed extensions, check for updates, install new extensions from URL or an online index, manage enable/disable states, and backup/restore configuration snapshots.
Description
This module builds a tabbed interface within the Extensions tab containing four sub-tabs:
Installed: Renders an HTML table of all installed extensions with columns for name, URL, branch, version, date, and update status. Each row has an enable/disable checkbox and an update checkbox. The extension_table() function generates this HTML dynamically from the extensions.extensions list. The check_updates() function iterates over enabled extensions with remotes and checks for available updates. apply_and_restart() processes the disable/update lists, fetches and resets selected extensions using git, saves the configuration, and triggers a program restart.
Available: Fetches an online JSON index of available extensions and renders a filterable, sortable table. Users can filter by tags and sort by various criteria. The install_extension_from_index() function clones the selected extension's git repository into the extensions directory.
Install from URL: Provides a text input for a git repository URL and a branch field. The install_extension_from_url() function clones the repository into the extensions directory, handling subdirectory creation and error reporting.
Backup/Restore: Enables saving and restoring configuration state snapshots as JSON files. save_config_state() captures the current webui and extension state with a timestamp. restore_config_state() restores from a selected snapshot, optionally restoring extensions, webui config, or both.
Access control is enforced through check_access(), which raises an assertion error if the --disable-extension-access command line flag is set.
Usage
This module is used by the main ui.py builder to add the Extensions tab to the web interface. Users interact with it to discover, install, update, enable/disable, and manage third-party extensions directly from the browser without command-line interaction. The backup/restore functionality is useful before major updates.
Code Reference
Source Location
- Repository: AUTOMATIC1111_Stable_diffusion_webui
- File: modules/ui_extensions.py
- Lines: 1-701
Signature
def check_access(): ...
def apply_and_restart(disable_list: str, update_list: str, disable_all: bool): ...
def save_config_state(name: str) -> tuple: ...
def restore_config_state(confirmed: bool, config_state_name: str, restore_type: str) -> str: ...
def check_updates(id_task, disable_list: str) -> tuple: ...
def extension_table() -> str: ...
def make_commit_link(commit_hash: str, remote: str, text=None) -> str: ...
def update_config_states_table(state_name: str) -> str: ...
def install_extension_from_url(dirname, url, branch_name) -> tuple: ...
def install_extension_from_index(url, hide_tags, sort_column, filter_text) -> tuple: ...
def create_ui() -> gr.Blocks: ...
Import
from modules import ui_extensions
# Typically used internally by ui.py:
ui_extensions.create_ui()
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| disable_list | str (JSON) | Yes | JSON array of extension names to disable |
| update_list | str (JSON) | Yes | JSON array of extension names to update |
| disable_all | bool | Yes | Whether to disable all extensions globally |
| url | str | Yes | Git repository URL to clone (for install from URL) |
| branch_name | str | No | Specific git branch to checkout (empty for default) |
| dirname | str | No | Custom subdirectory name for the cloned extension |
| config_state_name | str | Yes | Name of the configuration state to restore from |
| restore_type | str | Yes | Type of restore: "extensions", "webui", or "both" |
| confirmed | bool | Yes | User confirmation before restoring config state |
Outputs
| Name | Type | Description |
|---|---|---|
| extension_table_html | str | HTML table string listing all installed extensions |
| config_states_table_html | str | HTML table string showing backup configuration states |
| status_html | str | HTML status message indicating operation result |
| settings_interface | gr.Blocks | The assembled Extensions tab Gradio interface |
Usage Examples
# The Extensions tab is created as part of the main UI
from modules import ui_extensions
# In ui.py create_ui():
with gr.Tabs(elem_id="tabs") as tabs:
# ... other tabs ...
with gr.Tab("Extensions", id="extensions", elem_id="tab_extensions"):
extensions_interface = ui_extensions.create_ui()
# Programmatic extension install (typically triggered via UI):
# install_extension_from_url("", "https://github.com/author/sd-webui-extension.git", "main")
# Save a backup before updating
# save_config_state("Pre-update backup")