Add ui_block(), ui_tab() and ui_params() support

This commit is contained in:
Vasyanator 2024-08-27 21:17:26 +04:00 committed by GitHub
parent 5522584992
commit c14f7c4e7c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -188,24 +188,42 @@ def _apply_custom_js():
def create_extensions_block():
to_display = []
for extension, name in iterator():
if hasattr(extension, "ui") and not (hasattr(extension, 'params') and extension.params.get('is_tab', False)):
# Use ui_block if it is defined, otherwise use the old ui
if hasattr(extension, "ui_block"):
to_display.append((extension, name))
elif hasattr(extension, "ui") and not (hasattr(extension, 'params') and extension.params.get('is_tab', False)):
to_display.append((extension, name))
# Creating the extension ui elements
if len(to_display) > 0:
with gr.Column(elem_id="extensions"):
for row in to_display:
extension, _ = row
extension.ui()
if hasattr(extension, "ui_block"):
extension.ui_block()
else:
extension.ui()
def create_extensions_tabs():
for extension, name in iterator():
if hasattr(extension, "ui") and (hasattr(extension, 'params') and extension.params.get('is_tab', False)):
# Use ui_tab if it is defined, otherwise use the old ui with the is_tab parameter
if hasattr(extension, "ui_tab"):
display_name = getattr(extension, 'params', {}).get('display_name', name)
with gr.Tab(display_name, elem_classes="extension-tab"):
extension.ui_tab()
elif hasattr(extension, "ui") and (hasattr(extension, 'params') and extension.params.get('is_tab', False)):
display_name = getattr(extension, 'params', {}).get('display_name', name)
with gr.Tab(display_name, elem_classes="extension-tab"):
extension.ui()
# Creates a tab in Parameters to hold the extension settings
def create_extensions_params():
for extension, name in iterator():
if hasattr(extension, "ui_params"):
display_name = getattr(extension, 'params', {}).get('display_name', name)
with gr.Tab(display_name):
extension.ui_params()
EXTENSION_MAP = {
"input": partial(_apply_string_extensions, "input_modifier"),