Implementation:AUTOMATIC1111 Stable diffusion webui UI Settings
| Knowledge Sources | |
|---|---|
| Domains | UI, Settings, Configuration |
| Last Updated | 2025-05-15 00:00 GMT |
Overview
The UI settings module builds and manages the Settings tab, dynamically creating Gradio components for all registered options organized into tabbed sections, handling quicksettings at the top of the page, the apply/save workflow, and action buttons for system operations.
Description
The central class is UiSettings, which manages the complete settings interface:
create_ui() iterates over all opts.data_labels entries and creates appropriate Gradio components (textbox, slider, checkbox, dropdown, radio, color picker) organized into TabItems by section. It skips items that belong to quicksettings (which are rendered separately) and hidden sections. The method also creates special tabs:
- Defaults: Integrates the load/save UI for managing default configurations
- Sysinfo: Provides download links for system information and a validity checker
- Actions: Contains buttons for requesting browser notifications, downloading localization templates, reloading script bodies, unloading/loading the SD model to/from VRAM, calculating checkpoint hashes (with configurable thread count), and reloading the UI
- Licenses: Displays license information
add_quicksettings() renders the quicksettings bar at the top of the page, creating setting components for items listed in opts.quicksettings_list.
add_functionality() wires the apply button to run_settings() (which validates types, applies all changes, and persists to config), quicksettings components to run_settings_single() for immediate individual changes, and the checkpoint change button for programmatic model switching.
create_setting_component() maps option types to Gradio components. It selects the component based on info.component (if specified) or the default value type (str->Textbox, int->Number, bool->Checkbox). It adds a refresh button when the option has a refresh callback.
get_value_for_setting() retrieves the current value and component args for a setting key, used when populating component state on page load.
Usage
This module is called by the main ui.py builder to construct the Settings tab and the quicksettings bar. It serves as the bridge between the options system (defined in shared_options.py) and the visual interface, allowing users to view and modify all application settings through the browser.
Code Reference
Source Location
- Repository: AUTOMATIC1111_Stable_diffusion_webui
- File: modules/ui_settings.py
- Lines: 1-345
Signature
class UiSettings:
submit: gr.Button
result: gr.HTML
interface: gr.Blocks
components: list
component_dict: dict
dummy_component: gr.Component
quicksettings_list: list
text_settings: gr.Textbox
def run_settings(self, *args) -> tuple[str, str]: ...
def run_settings_single(self, value, key) -> tuple: ...
def register_settings(self): ...
def create_ui(self, loadsave, dummy_component): ...
def add_quicksettings(self): ...
def add_functionality(self, demo): ...
def get_value_for_setting(key: str) -> gr.update: ...
def create_setting_component(key: str, is_quicksettings=False) -> gr.Component: ...
Import
from modules.ui_settings import UiSettings, create_setting_component
from modules.ui_settings import get_value_for_setting
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| key | str | Yes | The option key name (e.g. "sd_model_checkpoint", "samples_format") |
| value | any | Yes | The new value to set for the option |
| *args | tuple | Yes | All setting component values passed to run_settings() in order of data_labels |
| loadsave | UiLoadsave | Yes | Load/save UI manager for the Defaults tab |
| dummy_component | gr.Component | Yes | Placeholder component for skipped settings |
| is_quicksettings | bool | No | Whether the component is being created for the quicksettings bar |
Outputs
| Name | Type | Description |
|---|---|---|
| settings_json | str | JSON dump of all current settings (returned by run_settings) |
| status_message | str | Human-readable message indicating which settings changed |
| component | gr.Component | The created Gradio component for a setting (from create_setting_component) |
| gr.update | gr.update | Updated component value and args (from get_value_for_setting) |
Usage Examples
# Settings UI is created during main UI build
from modules.ui_settings import UiSettings
settings = UiSettings()
settings.register_settings()
# In create_ui():
settings.create_ui(loadsave, dummy_component)
# Quicksettings bar at top of page:
settings.add_quicksettings()
# Wire functionality after demo is created:
settings.add_functionality(demo)
# Creating an individual setting component:
from modules.ui_settings import create_setting_component
component = create_setting_component("sd_model_checkpoint", is_quicksettings=True)