From b3d9899534d4c607ee309f09533c3759eef68792 Mon Sep 17 00:00:00 2001 From: AIrjen Date: Fri, 5 Apr 2024 10:17:23 +0200 Subject: [PATCH] davide! --- build_dynamic_prompt.py | 21 +++++++++-------- csv_reader.py | 23 ++++++++++++++++++- .../wildcards/add wildcard files here.txt | 6 +++++ userfiles/wildcards/sample_wildcard.csv | 6 +++++ 4 files changed, 45 insertions(+), 11 deletions(-) create mode 100644 userfiles/wildcards/add wildcard files here.txt create mode 100644 userfiles/wildcards/sample_wildcard.csv diff --git a/build_dynamic_prompt.py b/build_dynamic_prompt.py index b372e9f..c34fe6c 100644 --- a/build_dynamic_prompt.py +++ b/build_dynamic_prompt.py @@ -4808,16 +4808,17 @@ def one_button_superprompt(insanitylevel = 5, prompt = "", seed = -1, override_s # check if its matching all words from the override: possible_words_to_check = override_subject.lower().split() + override_outfit.lower().split() - # print(possible_words_to_check) + #print(possible_words_to_check) words_to_check = [] words_to_remove = ['subject', 'solo', '1girl', '1boy'] for word in possible_words_to_check: word = word.translate(translation_table_remove_stuff) + #print(word) if word not in words_to_remove: - if not word.startswith("-") and not word.endswith("-"): + if (not word.startswith("-") and not word.endswith("-")) and (not word.startswith("_") and not word.endswith("_")) : words_to_check.append(word) - + #print(words_to_check) if chosensubject not in ("humanoid","firstname","job","fictional","non fictional","human"): gender = "" if(superpromptstyle == "" or superpromptstyle == "all"): @@ -4866,7 +4867,6 @@ def one_button_superprompt(insanitylevel = 5, prompt = "", seed = -1, override_s question += "Expand the following " + gender + " " + subject_to_generate + " prompt to make it more " + superpromptstyle else: question += "Expand the following " + gender + " " + subject_to_generate + " prompt to add more detail: " - # question = "Expand the following fantasy character prompt to describe a portrait: " @@ -4936,11 +4936,12 @@ def one_button_superprompt(insanitylevel = 5, prompt = "", seed = -1, override_s return superpromptresult def replace_user_wildcards(completeprompt): - user_wildcards_list = re.findall(r'-[\w_]*-', completeprompt) - for user_wildcard in user_wildcards_list: - user_wildcard_clean = user_wildcard.strip("-") - wordlist = csv_to_list(csvfilename=user_wildcard_clean, directory="./userfiles/") - if(wordlist): - completeprompt = completeprompt.replace(user_wildcard, random.choice(wordlist),1) + for i in range(0,10): + user_wildcards_list = re.findall(r'-[\w_]*-', completeprompt) + for user_wildcard in user_wildcards_list: + user_wildcard_clean = user_wildcard.strip("-") + wordlist = csv_to_list(csvfilename=user_wildcard_clean, directory="./userfiles/wildcards/") + if(wordlist): + completeprompt = completeprompt.replace(user_wildcard, random.choice(wordlist),1) return completeprompt \ No newline at end of file diff --git a/csv_reader.py b/csv_reader.py index 5b2a5cc..bf2058e 100644 --- a/csv_reader.py +++ b/csv_reader.py @@ -31,6 +31,7 @@ def csv_to_list(csvfilename, antilist=[], directory="./csvfiles/", lowerandstrip full_path = os.path.join(script_dir, directory ) userfilesfolder = os.path.join(script_dir, userfilesdirectory ) directoryfilesfolder = os.path.join(script_dir, directory ) + # check if there is a replace file if(directory=="./csvfiles/" or directory=="./csvfiles/special_lists/" or directory=="./csvfiles/templates/"): for filename in os.listdir(userfilesfolder): @@ -81,7 +82,27 @@ def csv_to_list(csvfilename, antilist=[], directory="./csvfiles/", lowerandstrip csvlist.append(row[0].lower().strip()) else: csvlist.append(row[0]) - + # dirty hack for possible .txt files + if(os.path.isfile(full_path + csvfilename + ".txt")): + with open(full_path + csvfilename + ".txt", "r", newline="",encoding="utf8") as file: + reader = csv.reader(file, delimiter=delimiter) + if(skipheader==True): + next(reader) + if(listoflistmode==True): + csvlist = list(reader) + else: + for row in reader: + value = row[0] + if( + gender != "all" and (row[1] == gender or row[1] == "genderless" or row[1] == "both") + or gender == "all" + ): + if(value.lower().strip() not in antilist): + if(lowerandstrip == 1): + csvlist.append(row[0].lower().strip()) + else: + csvlist.append(row[0]) + # do the add ons! if(directory=="./csvfiles/" or directory=="./csvfiles/special_lists/"): if(os.path.isfile(userfilesfolder + csvfilename + "_addon" + ".csv")): diff --git a/userfiles/wildcards/add wildcard files here.txt b/userfiles/wildcards/add wildcard files here.txt new file mode 100644 index 0000000..525980a --- /dev/null +++ b/userfiles/wildcards/add wildcard files here.txt @@ -0,0 +1,6 @@ +Add wildcard files here, if you can't make use of Dynamic Prompts. +Files can be called as "sample_wildcard.csv" and are then usable in One Button Prompt with -sample_wildcard- as the wildcard. +.txt files are also supported here. + +It is not possible to call build-in wildcards from the custom wildcards. +It is possible to nest custom wildcards with other custom wildcards (up to 10 deep). To do this, use the -wildcard- notation inside a wildcard. \ No newline at end of file diff --git a/userfiles/wildcards/sample_wildcard.csv b/userfiles/wildcards/sample_wildcard.csv new file mode 100644 index 0000000..d1a218f --- /dev/null +++ b/userfiles/wildcards/sample_wildcard.csv @@ -0,0 +1,6 @@ +Cool banana wearing sunglasses +Cute Norwegian forest cat +Sock puppet version of Ed Sheeran +An evil wizard casting a spell +The demon queen of hell laughing manically +person wearing a cool hat \ No newline at end of file