From 0d4fd185a91b1101edb22c9c7c9d2438d65244c8 Mon Sep 17 00:00:00 2001 From: AIrjen Date: Fri, 18 Aug 2023 15:57:49 +0200 Subject: [PATCH] Adding feature parity for some things for comfyUI Added option to turn off emoji's, that break some stuff on ComfyUI --- OneButtonPromptNodes.py | 159 +++++++++++++++++++++++++++++++++++-- build_dynamic_prompt.py | 4 +- prompttester.py | 6 +- scripts/api.py | 6 +- scripts/onebuttonprompt.py | 4 +- 5 files changed, 166 insertions(+), 13 deletions(-) diff --git a/OneButtonPromptNodes.py b/OneButtonPromptNodes.py index 4fb025e..3bf89ec 100644 --- a/OneButtonPromptNodes.py +++ b/OneButtonPromptNodes.py @@ -10,16 +10,162 @@ onebuttonprompt_path = os.path.join(custom_nodes_path, "OneButtonPrompt") sys.path.append(onebuttonprompt_path) from build_dynamic_prompt import * +from csv_reader import * artists = ["all", "none", "popular", "greg mode", "3D", "abstract", "angular", "anime" ,"architecture", "art nouveau", "art deco", "baroque", "bauhaus", "cartoon", "character", "children's illustration", "cityscape", "clean", "cloudscape", "collage", "colorful", "comics", "cubism", "dark", "detailed", "digital", "expressionism", "fantasy", "fashion", "fauvism", "figurativism", "gore", "graffiti", "graphic design", "high contrast", "horror", "impressionism", "installation", "landscape", "light", "line drawing", "low contrast", "luminism", "magical realism", "manga", "melanin", "messy", "monochromatic", "nature", "nudity", "photography", "pop art", "portrait", "primitivism", "psychedelic", "realism", "renaissance", "romanticism", "scene", "sci-fi", "sculpture", "seascape", "space", "stained glass", "still life", "storybook realism", "street art", "streetscape", "surrealism", "symbolism", "textile", "ukiyo-e", "vibrant", "watercolor", "whimsical"] imagetypes = ["all", "all - force multiple", "photograph", "octane render","digital art","concept art", "painting", "portrait", "anime key visual", "only other types", "only templates mode", "art blaster mode", "quality vomit mode", "color cannon mode", "unique art mode", "massive madness mode", "photo fantasy mode", "subject only mode", "fixed styles mode"] subjects =["all", "object", "animal", "humanoid", "landscape", "concept"] genders = ["all", "male", "female"] +emojis = [False, True] -subjectsubtypesobject = ["all", "generic objects", "vehicles", "food", "buildings", "space", "flora"] -subjectsubtypeshumanoid = ["all", "generic humans", "generic human relations", "celebrities e.a.", "fictional characters", "humanoids", "based on job or title", "based on first name"] -subjectsubtypesconcept = ["all", "event", "the X of Y concepts", "lines from poems", "lines from songs"] - +subjects =["all"] +subjectsubtypesobject = ["all"] +subjectsubtypeshumanoid = ["all"] +subjectsubtypesconcept = ["all"] +#subjectsubtypesobject = ["all", "generic objects", "vehicles", "food", "buildings", "space", "flora"] +#subjectsubtypeshumanoid = ["all", "generic humans", "generic human relations", "celebrities e.a.", "fictional characters", "humanoids", "based on job or title", "based on first name"] +#subjectsubtypesconcept = ["all", "event", "the X of Y concepts", "lines from poems", "lines from songs"] + + +# Load up stuff for personal artists list, if any +# find all artist files starting with personal_artits in userfiles +script_dir = os.path.dirname(os.path.abspath(__file__)) # Script directory +userfilesfolder = os.path.join(script_dir, "./userfiles/" ) +for filename in os.listdir(userfilesfolder): + if(filename.endswith(".csv") and filename.startswith("personal_artists") and filename != "personal_artists_sample.csv"): + name = os.path.splitext(filename)[0] + name = name.replace("_"," ",-1).lower() + # directly insert into the artists list + artists.insert(2, name) + +# on startup, check if we have a config file, or else create it +config = load_config_csv() + + +# load subjects stuff from config +generatevehicle = True +generateobject = True +generatefood = True +generatebuilding = True +generatespace = True +generateflora = True +generateanimal = True +generatemanwoman = True +generatemanwomanrelation = True +generatefictionalcharacter = True +generatenonfictionalcharacter = True +generatehumanoids = True +generatejob = True +generatefirstnames = True +generatelandscape = True +generateevent = True +generateconcepts = True +generatepoemline = True +generatesongline = True + + +for item in config: + # objects + if item[0] == 'subject_vehicle' and item[1] != 'on': + generatevehicle = False + if item[0] == 'subject_object' and item[1] != 'on': + generateobject = False + if item[0] == 'subject_food' and item[1] != 'on': + generatefood = False + if item[0] == 'subject_building' and item[1] != 'on': + generatebuilding = False + if item[0] == 'subject_space' and item[1] != 'on': + generatespace = False + if item[0] == 'subject_flora' and item[1] != 'on': + generateflora = False + # animals + if item[0] == 'subject_animal' and item[1] != 'on': + generateanimal = False + # humanoids + if item[0] == 'subject_manwoman' and item[1] != 'on': + generatemanwoman = False + if item[0] == 'subject_manwomanrelation' and item[1] != 'on': + generatemanwomanrelation = False + if item[0] == 'subject_fictional' and item[1] != 'on': + generatefictionalcharacter = False + if item[0] == 'subject_nonfictional' and item[1] != 'on': + generatenonfictionalcharacter = False + if item[0] == 'subject_humanoid' and item[1] != 'on': + generatehumanoids = False + if item[0] == 'subject_job' and item[1] != 'on': + generatejob = False + if item[0] == 'subject_firstnames' and item[1] != 'on': + generatefirstnames = False + # landscape + if item[0] == 'subject_landscape' and item[1] != 'on': + generatelandscape = False + # concept + if item[0] == 'subject_event' and item[1] != 'on': + generateevent = False + if item[0] == 'subject_concept' and item[1] != 'on': + generateconcepts = False + if item[0] == 'poemline' and item[1] != 'on': + generatepoemline = False + if item[0] == 'songline' and item[1] != 'on': + generatesongline = False + +# build up all subjects we can choose based on the loaded config file +if(generatevehicle or generateobject or generatefood or generatebuilding or generatespace): + subjects.append("object") +if(generateanimal): + subjects.append("animal") +if(generatemanwoman or generatemanwomanrelation or generatefictionalcharacter or generatenonfictionalcharacter or generatehumanoids or generatejob): + subjects.append("humanoid") +if(generatelandscape): + subjects.append("landscape") +if(generateevent or generateconcepts or generatepoemline or generatesongline): + subjects.append("concept") + + +# do the same for the subtype subjects +# subjectsubtypesobject = ["all"] +# subjectsubtypeshumanoid = ["all"] +# subjectsubtypesconcept = ["all"] + +# objects first +if(generateobject): + subjectsubtypesobject.append("generic objects") +if(generatevehicle): + subjectsubtypesobject.append("vehicles") +if(generatefood): + subjectsubtypesobject.append("food") +if(generatebuilding): + subjectsubtypesobject.append("buildings") +if(generatespace): + subjectsubtypesobject.append("space") +if(generateflora): + subjectsubtypesobject.append("flora") + +# humanoids (should I review descriptions??) +if(generatemanwoman): + subjectsubtypeshumanoid.append("generic humans") +if(generatemanwomanrelation): + subjectsubtypeshumanoid.append("generic human relations") +if(generatenonfictionalcharacter): + subjectsubtypeshumanoid.append("celebrities e.a.") +if(generatefictionalcharacter): + subjectsubtypeshumanoid.append("fictional characters") +if(generatehumanoids): + subjectsubtypeshumanoid.append("humanoids") +if(generatejob): + subjectsubtypeshumanoid.append("based on job or title") +if(generatefirstnames): + subjectsubtypeshumanoid.append("based on first name") + +# concepts +if(generateevent): + subjectsubtypesconcept.append("event") +if(generateconcepts): + subjectsubtypesconcept.append("the X of Y concepts") +if(generatepoemline): + subjectsubtypesconcept.append("lines from poems") +if(generatesongline): + subjectsubtypesconcept.append("lines from songs") class OneButtonPrompt: @@ -57,6 +203,7 @@ class OneButtonPrompt: "subject_subtypes_humanoids": (subjectsubtypeshumanoid, {"default": "all"}), "humanoids_gender": (genders, {"default": "all"}), "subject_subtypes_concepts": (subjectsubtypesconcept, {"default": "all"}), + "emojis":(emojis, {"default": False}), "seed": ("INT", {"default": 0, "min": 0, "max": 0xFFFFFFFFFFFFFFFF}), }, @@ -71,8 +218,8 @@ class OneButtonPrompt: CATEGORY = "OneButtonPrompt" - def Comfy_OBP(self, insanitylevel, custom_subject,seed, artist,imagetype, subject, imagemodechance, humanoids_gender, subject_subtype_objects, subject_subtypes_humanoids, subject_subtypes_concepts): - generatedprompt = build_dynamic_prompt(insanitylevel,subject,artist,imagetype,False,"","","",1,"",custom_subject,True,"",imagemodechance, humanoids_gender, subject_subtype_objects, subject_subtypes_humanoids, subject_subtypes_concepts, False) + def Comfy_OBP(self, insanitylevel, custom_subject,seed, artist,imagetype, subject, imagemodechance, humanoids_gender, subject_subtype_objects, subject_subtypes_humanoids, subject_subtypes_concepts, emojis): + generatedprompt = build_dynamic_prompt(insanitylevel,subject,artist,imagetype,False,"","","",1,"",custom_subject,True,"",imagemodechance, humanoids_gender, subject_subtype_objects, subject_subtypes_humanoids, subject_subtypes_concepts, False, emojis) #print(generatedprompt) return (generatedprompt,) diff --git a/build_dynamic_prompt.py b/build_dynamic_prompt.py index 3c754a7..3bf6bbf 100644 --- a/build_dynamic_prompt.py +++ b/build_dynamic_prompt.py @@ -10,7 +10,7 @@ from random_functions import * # insanity level controls randomness of propmt 0-10 # forcesubject van be used to force a certain type of subject # Set artistmode to none, to exclude artists -def build_dynamic_prompt(insanitylevel = 5, forcesubject = "all", artists = "all", imagetype = "all", onlyartists = False, antivalues = "", prefixprompt = "", suffixprompt ="",promptcompounderlevel ="1", seperator = "comma", givensubject="",smartsubject = True,giventypeofimage="", imagemodechance = 20, gender = "all", subtypeobject="all", subtypehumanoid="all", subtypeconcept="all", advancedprompting=True): +def build_dynamic_prompt(insanitylevel = 5, forcesubject = "all", artists = "all", imagetype = "all", onlyartists = False, antivalues = "", prefixprompt = "", suffixprompt ="",promptcompounderlevel ="1", seperator = "comma", givensubject="",smartsubject = True,giventypeofimage="", imagemodechance = 20, gender = "all", subtypeobject="all", subtypehumanoid="all", subtypeconcept="all", advancedprompting=True, hardturnoffemojis=False): # load the config file @@ -352,6 +352,8 @@ def build_dynamic_prompt(insanitylevel = 5, forcesubject = "all", artists = "all if item[0] == 'emojichance': emojichance = item[1] + if(hardturnoffemojis==True): + emojichance='never' if item[0] == 'joboractivitychance': joboractivitychance = item[1] diff --git a/prompttester.py b/prompttester.py index c91077c..9d4495e 100644 --- a/prompttester.py +++ b/prompttester.py @@ -10,7 +10,7 @@ from build_dynamic_prompt import * -def generateprompts(amount = 1,insanitylevel="5",subject="all", artist="all", imagetype="all",onlyartists=False, workprompt="", antistring="",prefixprompt="", suffixprompt="", negativeprompt="",promptcompounderlevel = "1", seperator="comma",givensubject="",smartsubject=True,giventypeofimage="",imagemodechance=20, gender = "all", subtypeobject = "all", subtypehumanoid = "all", subtypeconcept = "all", advancedprompting = True): +def generateprompts(amount = 1,insanitylevel="5",subject="all", artist="all", imagetype="all",onlyartists=False, workprompt="", antistring="",prefixprompt="", suffixprompt="", negativeprompt="",promptcompounderlevel = "1", seperator="comma",givensubject="",smartsubject=True,giventypeofimage="",imagemodechance=20, gender = "all", subtypeobject = "all", subtypehumanoid = "all", subtypeconcept = "all", advancedprompting = True, hardturnoffemojis=False): loops = int(amount) # amount of images to generate steps = 0 @@ -18,7 +18,7 @@ def generateprompts(amount = 1,insanitylevel="5",subject="all", artist="all", im while steps < loops: # build prompt - result = build_dynamic_prompt(insanitylevel,subject,artist,imagetype, onlyartists,antistring,prefixprompt,suffixprompt,promptcompounderlevel, seperator,givensubject,smartsubject,giventypeofimage,imagemodechance, gender, subtypeobject, subtypehumanoid, subtypeconcept, advancedprompting) + result = build_dynamic_prompt(insanitylevel,subject,artist,imagetype, onlyartists,antistring,prefixprompt,suffixprompt,promptcompounderlevel, seperator,givensubject,smartsubject,giventypeofimage,imagemodechance, gender, subtypeobject, subtypehumanoid, subtypeconcept, advancedprompting, hardturnoffemojis) print("") print("loop " + str(steps)) @@ -46,4 +46,4 @@ def generateprompts(amount = 1,insanitylevel="5",subject="all", artist="all", im print("") print("All done!") -generateprompts(10,5,"all","all","fixed styles mode",False,"","","PREFIXPROMPT" ,"SUFFIXPROMPT","",1,"","",True,"",100, "all", "all", "all", "all", False) \ No newline at end of file +generateprompts(10,9,"humanoid","all","all",False,"","","PREFIXPROMPT" ,"SUFFIXPROMPT","",1,"","",True,"",100, "all", "all", "all", "all", False, True) \ No newline at end of file diff --git a/scripts/api.py b/scripts/api.py index 34def4d..9289ffc 100644 --- a/scripts/api.py +++ b/scripts/api.py @@ -38,13 +38,15 @@ def one_button_prompt_api(_: gr.Blocks, app: FastAPI): gender: str = Body('all',title='gender'), subtypeobject: str = Body('all',title='subtypeobject'), subtypehumanoid: str = Body('all', title='subtypehumanoid'), - subtypeconcept: str = Body('all', title='subtypeconcept') + subtypeconcept: str = Body('all', title='subtypeconcept'), + advancedprompting:bool = Body(True,title='advancedprompting'), + hardturnoffemojis:bool = Body(False,title='hardturnoffemojis') ): keys = ['insanitylevel', 'forcesubject', 'artists', 'imagetype', 'onlyartists', 'antivalues', 'prefixprompt', 'suffixprompt', 'promptcompounderlevel', 'seperator', 'givensubject', 'smartsubject', 'giventypeofimage', - 'imagemodechance', 'gender', 'subtypeobject','subtypehumanoid','subtypeconcept'] + 'imagemodechance', 'gender', 'subtypeobject','subtypehumanoid','subtypeconcept','advancedprompting','hardturnoffemojis'] payload = {} for key in keys: payload[key] = locals()[key] diff --git a/scripts/onebuttonprompt.py b/scripts/onebuttonprompt.py index e579346..593af76 100644 --- a/scripts/onebuttonprompt.py +++ b/scripts/onebuttonprompt.py @@ -22,7 +22,7 @@ subjectsubtypesobject = ["all"] subjectsubtypeshumanoid = ["all"] subjectsubtypesconcept = ["all"] artists = ["all", "none", "popular", "greg mode", "3D", "abstract", "angular", "anime" ,"architecture", "art nouveau", "art deco", "baroque", "bauhaus", "cartoon", "character", "children's illustration", "cityscape", "clean", "cloudscape", "collage", "colorful", "comics", "cubism", "dark", "detailed", "digital", "expressionism", "fantasy", "fashion", "fauvism", "figurativism", "gore", "graffiti", "graphic design", "high contrast", "horror", "impressionism", "installation", "landscape", "light", "line drawing", "low contrast", "luminism", "magical realism", "manga", "melanin", "messy", "monochromatic", "nature", "nudity", "photography", "pop art", "portrait", "primitivism", "psychedelic", "realism", "renaissance", "romanticism", "scene", "sci-fi", "sculpture", "seascape", "space", "stained glass", "still life", "storybook realism", "street art", "streetscape", "surrealism", "symbolism", "textile", "ukiyo-e", "vibrant", "watercolor", "whimsical"] -imagetypes = ["all", "all - force multiple", "photograph", "octane render","digital art","concept art", "painting", "portrait", "anime key visual", "only other types", "only templates mode", "art blaster mode", "quality vomit mode", "color cannon mode", "unique art mode", "massive madness mode", "photo fantasy mode", "subject only mode"] +imagetypes = ["all", "all - force multiple", "photograph", "octane render","digital art","concept art", "painting", "portrait", "anime key visual", "only other types", "only templates mode", "art blaster mode", "quality vomit mode", "color cannon mode", "unique art mode", "massive madness mode", "photo fantasy mode", "subject only mode", "fixed styles mode"] promptmode = ["at the back", "in the front"] promptcompounder = ["1", "2", "3", "4", "5"] ANDtogglemode = ["none", "automatic", "prefix AND prompt + suffix", "prefix + prefix + prompt + suffix"] @@ -456,6 +456,8 @@ class Script(scripts.Script): 16. subject only mode --> Will only generate a subject, with no additional frills. + 17. fixed styles mode --> Generate a subject on top of a fixed style. Credits to Triple Headed Monkey. Go check his stuff out! + ### One in X chance to use special image type mode