Skip to content

Commit

Permalink
Add mapping fallback for older gradio versions
Browse files Browse the repository at this point in the history
Fixes #151, fixes #152, fixes #154
  • Loading branch information
DominikDoom committed Apr 4, 2023
1 parent c3f53e1 commit 4331bdc
Showing 1 changed file with 17 additions and 6 deletions.
23 changes: 17 additions & 6 deletions scripts/tag_autocomplete_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,8 +283,8 @@ def on_ui_settings():
shared.opts.add_option("tac_extra.extraFile", shared.OptionInfo("extra-quality-tags.csv", "Extra filename (for small sets of custom tags)", gr.Dropdown, lambda: {"choices": csv_files_withnone}, refresh=update_tag_files, section=TAC_SECTION))
shared.opts.add_option("tac_extra.addMode", shared.OptionInfo("Insert before", "Mode to add the extra tags to the main tag list", gr.Dropdown, lambda: {"choices": ["Insert before","Insert after"]}, section=TAC_SECTION))
# Custom mappings
shared.opts.add_option("tac_keymap", shared.OptionInfo(
"""{
keymapDefault = """\
{
"MoveUp": "ArrowUp",
"MoveDown": "ArrowDown",
"JumpUp": "PageUp",
Expand All @@ -294,9 +294,10 @@ def on_ui_settings():
"ChooseSelected": "Enter",
"ChooseFirstOrSelected": "Tab",
"Close": "Escape"
}""", """Configure Hotkeys. For possible values, see https://www.w3.org/TR/uievents-key, or leave empty / set to 'None' to disable. Must be valid JSON.""", gr.Code, lambda: {"language": "json", "interactive": True}, section=TAC_SECTION))
shared.opts.add_option("tac_colormap", shared.OptionInfo(
"""{
}\
"""
colorDefault = """\
{
"danbooru": {
"-1": ["red", "maroon"],
"0": ["lightblue", "dodgerblue"],
Expand All @@ -316,7 +317,17 @@ def on_ui_settings():
"7": ["whitesmoke", "black"],
"8": ["seagreen", "darkseagreen"]
}
}""", "Configure colors. See https://github.com/DominikDoom/a1111-sd-webui-tagcomplete#colors for info. Must be valid JSON.", gr.Code, lambda: {"language": "json", "interactive": True}, section=TAC_SECTION))
}\
"""
keymapLabel = "Configure Hotkeys. For possible values, see https://www.w3.org/TR/uievents-key, or leave empty / set to 'None' to disable. Must be valid JSON."
colorLabel = "Configure colors. See https://github.com/DominikDoom/a1111-sd-webui-tagcomplete#colors for info. Must be valid JSON."

try:
shared.opts.add_option("tac_keymap", shared.OptionInfo(keymapDefault, keymapLabel, gr.Code, lambda: {"language": "json", "interactive": True}, section=TAC_SECTION))
shared.opts.add_option("tac_colormap", shared.OptionInfo(colorDefault, colorLabel, gr.Code, lambda: {"language": "json", "interactive": True}, section=TAC_SECTION))
except AttributeError:
shared.opts.add_option("tac_keymap", shared.OptionInfo(keymapDefault, keymapLabel, gr.Textbox, lambda: {"multiline": True}, section=TAC_SECTION))
shared.opts.add_option("tac_colormap", shared.OptionInfo(colorDefault, colorLabel, gr.Textbox, lambda: {"multiline": True}, section=TAC_SECTION))


script_callbacks.on_ui_settings(on_ui_settings)

0 comments on commit 4331bdc

Please sign in to comment.