use custom-mappings.txt instead of model-keyword-user.txt (updating through webui overwrote model-keyword-user.txt)
parent
b77c198d61
commit
3f9c9c0fe5
|
|
@ -1 +1,2 @@
|
|||
model-keyword-user.txt
|
||||
custom-mappings.txt
|
||||
custom-mappings-backup.txt
|
||||
|
|
|
|||
|
|
@ -43,9 +43,9 @@ When generating image, the extension will try to figure out which model is used
|
|||
|
||||
* Click "Set Keyword for Model" without filling 'Keyword' field -> outputs model name and model_hash in result.
|
||||
* Fill keyword(trigger word) or keywords separated by pipe character |.
|
||||
* Click "Set Keyword for Model" to save mapping. Mappings are saved in model-keyword-user.txt
|
||||
* Click "Set Keyword for Model" to save mapping. Mappings are saved in custom-mappings.txt
|
||||
* If previous mapping is found, it overwrites the mapping.
|
||||
* To delete an entry, edit model-keyword-user.txt in extensions/model-keyword.
|
||||
* To delete an entry, edit custom-mappings.txt in extensions/model-keyword.
|
||||
* do NOT edit model-keyword.txt . It can be overwritten or cause conflict while upgrading.
|
||||
* hash value for model has been changed in webui(2023-01-14), this extension uses old hash value. Old hash value is no longer displayed in webui.
|
||||
|
||||
|
|
|
|||
|
|
@ -1,12 +1,3 @@
|
|||
# csv file for adding custom model_hash to keyword mapping
|
||||
# line starting with # is ignored.
|
||||
#
|
||||
# model_hash, keyword
|
||||
#41fef4bd, nousr robot
|
||||
#
|
||||
# model provides multiple keywords
|
||||
#4d5cca44, TinyPlanet|TinyCityPlanet
|
||||
#
|
||||
# in case there is a hash collision. it will use the closest matching filename.ckpt
|
||||
# model_hash, keyword, filename.ckpt
|
||||
#a2a802b2, SKSKS app icon, App_Icons_V1_PublicPrompts.ckpt
|
||||
# This file is no long used.
|
||||
# User settings are now saved in custom-mappings.txt
|
||||
# Instead of manually editing, use the UI to add custom mappings.
|
||||
|
|
|
|||
|
|
@ -53,10 +53,11 @@ class Script(scripts.Script):
|
|||
insert_line = f'{model_hash}, {txt}, {model_ckpt}'
|
||||
global scripts_dir
|
||||
|
||||
user_file = f'{scripts_dir}/model-keyword-user.txt'
|
||||
user_backup_file = f'{scripts_dir}/model-keyword-user-backup.txt'
|
||||
user_file = f'{scripts_dir}/custom-mappings.txt'
|
||||
user_backup_file = f'{scripts_dir}/custom-mappings-backup.txt'
|
||||
lines = []
|
||||
|
||||
if os.path.exists(user_file):
|
||||
with open(user_file, newline='') as csvfile:
|
||||
csvreader = csv.reader(csvfile)
|
||||
for row in csvreader:
|
||||
|
|
@ -75,7 +76,10 @@ class Script(scripts.Script):
|
|||
lines.append(insert_line)
|
||||
csvtxt = '\n'.join(lines) + '\n'
|
||||
import shutil
|
||||
try:
|
||||
shutil.copy(user_file, user_backup_file)
|
||||
except:
|
||||
pass
|
||||
open(user_file, 'w').write(csvtxt)
|
||||
|
||||
return 'added: ' + insert_line
|
||||
|
|
@ -83,7 +87,6 @@ class Script(scripts.Script):
|
|||
with gr.Group():
|
||||
with gr.Accordion('Model Keyword', open=False):
|
||||
is_enabled = gr.Checkbox(label='Model Keyword Enabled', value=True)
|
||||
info = gr.HTML("<p style=\"margin-bottom:0.75em\">You can edit extensions/model-keyword/model-keyword-user.txt to add custom mappings</p>")
|
||||
|
||||
keyword_placement = gr.Dropdown(choices=["keyword prompt", "prompt keyword", "keyword, prompt", "prompt, keyword"],
|
||||
value='keyword prompt',
|
||||
|
|
@ -94,7 +97,7 @@ class Script(scripts.Script):
|
|||
label='Multiple keywords:')
|
||||
|
||||
with gr.Accordion('Add Custom Mappings', open=False):
|
||||
info = gr.HTML("<p style=\"margin-bottom:0.75em\">Add custom keyword(trigger word) mapping for current model. Custom mappings are saved to extensions/model-keyword/model-keyword-user.txt</p>")
|
||||
info = gr.HTML("<p style=\"margin-bottom:0.75em\">Add custom keyword(trigger word) mapping for current model. Custom mappings are saved to extensions/model-keyword/custom-mappings.txt</p>")
|
||||
text_input = gr.Textbox(placeholder="Keyword or keywords separated by |", label="Keyword(trigger word)")
|
||||
add_custom_mappings = gr.Button(value='Set Keyword for Model')
|
||||
text_output = gr.Textbox(interactive=False, label='result')
|
||||
|
|
@ -102,18 +105,19 @@ class Script(scripts.Script):
|
|||
add_custom_mappings.click(add_custom, inputs=text_input, outputs=text_output)
|
||||
|
||||
|
||||
return [is_enabled, info, keyword_placement, multiple_keywords]
|
||||
return [is_enabled, keyword_placement, multiple_keywords]
|
||||
|
||||
def load_hash_dict(self):
|
||||
global hash_dict, hash_dict_modified, scripts_dir
|
||||
|
||||
default_file = f'{scripts_dir}/model-keyword.txt'
|
||||
user_file = f'{scripts_dir}/model-keyword-user.txt'
|
||||
user_file = f'{scripts_dir}/custom-mappings.txt'
|
||||
modified = str(os.stat(default_file).st_mtime) + '_' + str(os.stat(user_file).st_mtime)
|
||||
|
||||
if hash_dict is None or hash_dict_modified != modified:
|
||||
hash_dict = defaultdict(list)
|
||||
def parse_file(path):
|
||||
if os.path.exists(path):
|
||||
with open(path, newline='') as csvfile:
|
||||
csvreader = csv.reader(csvfile)
|
||||
for row in csvreader:
|
||||
|
|
@ -134,7 +138,7 @@ class Script(scripts.Script):
|
|||
|
||||
return hash_dict
|
||||
|
||||
def process(self, p, is_enabled, _, keyword_placement, multiple_keywords):
|
||||
def process(self, p, is_enabled, keyword_placement, multiple_keywords):
|
||||
|
||||
if not is_enabled:
|
||||
global hash_dict
|
||||
|
|
|
|||
Loading…
Reference in New Issue