Skip to content

Commit

Permalink
Merge branch 'feature-refresh-temp-files' into main
Browse files Browse the repository at this point in the history
Added a "fake" settings option that refreshes some internal temporary files without needing to restart
  • Loading branch information
DominikDoom committed May 26, 2023
2 parents da65fee + 2d7e618 commit 1cb4fc8
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 31 deletions.
17 changes: 17 additions & 0 deletions javascript/tagAutocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -958,6 +958,21 @@ function navigateInList(textArea, event) {
event.stopPropagation();
}

async function refreshTacTempFiles() {
setTimeout(async () => {
wildcardFiles = [];
wildcardExtFiles = [];
yamlWildcards = [];
embeddings = [];
hypernetworks = [];
loras = [];
lycos = [];
await processQueue(QUEUE_FILE_LOAD, null);

console.log("TAC: Refreshed temp files");
}, 2000);
}

function addAutocompleteToArea(area) {
// Return if autocomplete is disabled for the current area type in config
let textAreaId = getTextAreaIdentifier(area);
Expand Down Expand Up @@ -1033,6 +1048,8 @@ async function setup() {
}, 500);
})
});
// Listener for internal temp files refresh button
gradioApp().querySelector("#refresh_tac_refreshTempFiles")?.addEventListener("click", refreshTacTempFiles);

// Add mutation observer for the model hash text to also allow hash-based blacklist again
let modelHashText = gradioApp().querySelector("#sd_checkpoint_hash");
Expand Down
71 changes: 40 additions & 31 deletions scripts/tag_autocomplete_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,41 +241,49 @@ def update_json_files():
if not TEMP_PATH.joinpath("emb.txt").exists():
write_to_temp_file('emb.txt', [])

# Write wildcards to wc.txt if found
if WILDCARD_PATH.exists():
wildcards = [WILDCARD_PATH.relative_to(FILE_DIR).as_posix()] + get_wildcards()
if wildcards:
write_to_temp_file('wc.txt', wildcards)

# Write extension wildcards to wce.txt if found
if WILDCARD_EXT_PATHS is not None:
wildcards_ext = get_ext_wildcards()
if wildcards_ext:
write_to_temp_file('wce.txt', wildcards_ext)
# Write yaml extension wildcards to wcet.txt if found
wildcards_yaml_ext = get_ext_wildcard_tags()
if wildcards_yaml_ext:
write_to_temp_file('wcet.txt', wildcards_yaml_ext)

# Write embeddings to emb.txt if found
if EMB_PATH.exists():
# Get embeddings after the model loaded callback
script_callbacks.on_model_loaded(get_embeddings)

if HYP_PATH.exists():
hypernets = get_hypernetworks()
if hypernets:
write_to_temp_file('hyp.txt', hypernets)

if LORA_PATH is not None and LORA_PATH.exists():
lora = get_lora()
if lora:
write_to_temp_file('lora.txt', lora)

if LYCO_PATH is not None and LYCO_PATH.exists():
lyco = get_lyco()
if lyco:
write_to_temp_file('lyco.txt', lyco)
def refresh_temp_files():
write_temp_files()
get_embeddings(shared.sd_model)

def write_temp_files():
# Write wildcards to wc.txt if found
if WILDCARD_PATH.exists():
wildcards = [WILDCARD_PATH.relative_to(FILE_DIR).as_posix()] + get_wildcards()
if wildcards:
write_to_temp_file('wc.txt', wildcards)

# Write extension wildcards to wce.txt if found
if WILDCARD_EXT_PATHS is not None:
wildcards_ext = get_ext_wildcards()
if wildcards_ext:
write_to_temp_file('wce.txt', wildcards_ext)
# Write yaml extension wildcards to wcet.txt if found
wildcards_yaml_ext = get_ext_wildcard_tags()
if wildcards_yaml_ext:
write_to_temp_file('wcet.txt', wildcards_yaml_ext)

if HYP_PATH.exists():
hypernets = get_hypernetworks()
if hypernets:
write_to_temp_file('hyp.txt', hypernets)

if LORA_PATH is not None and LORA_PATH.exists():
lora = get_lora()
if lora:
write_to_temp_file('lora.txt', lora)

if LYCO_PATH is not None and LYCO_PATH.exists():
lyco = get_lyco()
if lyco:
write_to_temp_file('lyco.txt', lyco)


write_temp_files()

# Register autocomplete options
def on_ui_settings():
Expand Down Expand Up @@ -366,5 +374,6 @@ def on_ui_settings():
shared.opts.add_option("tac_keymap", shared.OptionInfo(keymapDefault, keymapLabel, gr.Textbox, section=TAC_SECTION))
shared.opts.add_option("tac_colormap", shared.OptionInfo(colorDefault, colorLabel, gr.Textbox, section=TAC_SECTION))


shared.opts.add_option("tac_refreshTempFiles", shared.OptionInfo("Refresh TAC temp files", "Refresh internal temp files", gr.HTML, {}, refresh=refresh_temp_files, section=TAC_SECTION))

script_callbacks.on_ui_settings(on_ui_settings)

0 comments on commit 1cb4fc8

Please sign in to comment.