Updated image generation functions with extra configurable settings for:

koboldai_vars.img_gen_art_guide
koboldai_vars.img_gen_negative_prompt (local SD API only until Horde supports passing negative prompts.)
koboldai_vars.img_gen_steps
koboldai_vars.img_gen_cfg_scale
Added toggle for the image_generating flag to allow resetting it in the case of interruption without needing to restart KoboldAI.


Signed-off-by: viningr
This commit is contained in:
Robert Vining
2022-11-15 16:44:21 +10:00
parent 7ab86a80ff
commit 100a889eda
3 changed files with 98 additions and 14 deletions

View File

@@ -9111,7 +9111,9 @@ def UI_2_generate_image(data):
koboldai_vars.generating_image = True
eventlet.sleep(0)
art_guide = 'fantasy illustration, artstation, by jason felix by steve argyle by tyler jacobson by peter mohrbacher, cinematic lighting'
art_guide = '{}'.format(koboldai_vars.img_gen_art_guide)
steps = '{}'.format(koboldai_vars.img_gen_steps)
cfg_scale = '{}'.format(koboldai_vars.img_gen_cfg_scale)
#get latest action
if len(koboldai_vars.actions) > 0:
@@ -9194,6 +9196,8 @@ def UI_2_generate_image(data):
def text2img_local(prompt, art_guide="", filename="new.png"):
start_time = time.time()
logger.debug("Generating Image")
steps = '{}'.format(koboldai_vars.img_gen_steps)
cfg_scale = '{}'.format(koboldai_vars.img_gen_cfg_scale)
koboldai_vars.aibusy = True
koboldai_vars.generating_image = True
from diffusers import StableDiffusionPipeline
@@ -9210,7 +9214,7 @@ def text2img_local(prompt, art_guide="", filename="new.png"):
from torch import autocast
with autocast("cuda"):
return pipe(prompt, num_inference_steps=num_inference_steps).images[0]
image = tpool.execute(get_image, pipe, prompt, num_inference_steps=35)
image = tpool.execute(get_image, pipe, prompt, num_inference_steps=steps)
buffered = BytesIO()
image.save(buffered, format="JPEG")
img_str = base64.b64encode(buffered.getvalue()).decode('ascii')
@@ -9231,8 +9235,11 @@ def text2img_local(prompt, art_guide="", filename="new.png"):
@logger.catch
def text2img_horde(prompt,
art_guide = 'fantasy illustration, artstation, by jason felix by steve argyle by tyler jacobson by peter mohrbacher, cinematic lighting',
#art_guide = '{}'.format(koboldai_vars.img_gen_art_guide),
art_guide = "",
filename = "story_art.png"):
steps = '{}'.format(koboldai_vars.img_gen_steps)
cfg_scale = '{}'.format(koboldai_vars.img_gen_cfg_scale)
logger.debug("Generating Image using Horde")
koboldai_vars.generating_image = True
@@ -9248,8 +9255,8 @@ def text2img_horde(prompt,
"nsfw": True,
"sampler_name": "k_euler_a",
"karras": True,
"cfg_scale": 7.0,
"steps":25,
"cfg_scale": cfg_scale,
"steps":steps,
"width":512,
"height":512}
}
@@ -9279,13 +9286,13 @@ def text2img_horde(prompt,
@logger.catch
def text2img_api(prompt,
#art_guide = 'fantasy illustration, artstation, by Hugin Miyama by Taiki Kawakami, cinematic lighting',
art_guide = 'fantasy illustration, artstation, by jason felix by steve argyle by tyler jacobson by peter mohrbacher, cinematic lighting',
#art_guide = '{}'.format(koboldai_vars.img_gen_art_guide),
art_guide = "",
filename = "story_art.png"):
steps = '{}'.format(koboldai_vars.img_gen_steps)
cfg_scale = '{}'.format(koboldai_vars.img_gen_cfg_scale)
logger.debug("Generating Image using Local SD-WebUI API")
koboldai_vars.generating_image = True
#Add items that you want the AI to avoid in your image.
negprompt = '((((misshapen)))),((((ugly)))), (((duplicate))), ((morbid)), ((mutilated)), out of frame, extra fingers, mutated hands, ((poorly drawn hands)), ((poorly drawn face)), (((mutation))), (((deformed))), ((ugly)), blurry, ((bad anatomy)), (((bad proportions))), ((extra limbs)), cloned face, (((disfigured))), out of frame, ugly, extra limbs, (bad anatomy), gross proportions, (malformed limbs), ((missing arms)), ((missing legs)), (((extra arms))), (((extra legs))), mutated hands, (fused fingers), (too many fingers), (((long neck))), captions, words'
#The following list are valid properties with their defaults, to add/modify in final_imgen_params. Will refactor configuring values into UI element in future.
#"enable_hr": false,
#"denoising_strength": 0,
@@ -9320,9 +9327,9 @@ def text2img_api(prompt,
"n": 1,
"width": 512,
"height": 512,
"steps": 40,
"cfg_scale": 10,
"negative_prompt": "{}".format(negprompt),
"steps": steps,
"cfg_scale": cfg_scale,
"negative_prompt": "{}".format(koboldai_vars.img_gen_negative_prompt),
"sampler_index": "Euler a"
}
@@ -9350,7 +9357,6 @@ def text2img_api(prompt,
prompttext = results.get('info').split("\",")[0].split("\"")[3]
pnginfo.add_text("parameters","prompttext")
img.save(final_filename, pnginfo=pnginfo)
#img.save(final_filename)
logger.debug("Saved Image")
koboldai_vars.generating_image = False
return(b64img)

View File

@@ -557,6 +557,64 @@ gensettingstf = [
"name": "img_gen_api_url"
},
{
"UI_V2_Only": True,
"uitype": "text",
"unit": "text",
"label": "Art Guide",
"id": "img_gen_art_guide",
"default": "",
"tooltip": "The art guide sent with image gen requests. \nDefault: fantasy illustration, artstation, by jason felix by steve argyle by tyler jacobson by peter mohrbacher, cinematic lighting",
"menu_path": "Interface",
"sub_path": "Images",
"classname": "user",
"name": "img_gen_art_guide"
},
{
"UI_V2_Only": True,
"uitype": "text",
"unit": "text",
"label": "Negative Prompt",
"id": "img_gen_negative_prompt",
"default": "",
"tooltip": "Enter features you do not want generated in your images here, only works for img_gen_api. \nDefault: lowres, bad anatomy, bad hands, text, error, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry, artist name",
"menu_path": "Interface",
"sub_path": "Images",
"classname": "user",
"name": "img_gen_negative_prompt"
},
{
"UI_V2_Only": True,
"uitype": "slider",
"unit": "int",
"label": "Steps",
"id": "img_gen_steps",
"min": 15,
"max": 50,
"step": 1,
"default": "30",
"tooltip": "Set the number of iterations the image generator will use to refine your image.\nDefault:30",
"menu_path": "Interface",
"sub_path": "Images",
"classname": "user",
"name": "img_gen_steps"
},
{
"UI_V2_Only": True,
"uitype": "slider",
"unit": "int",
"label": "Cfg Scale",
"id": "img_gen_cfg_scale",
"min": 1,
"max": 30,
"step": 1,
"default": "7",
"tooltip": "Set how strictly the AI will follow prompts, 5-15 are good values.\nDefault:7",
"menu_path": "Interface",
"sub_path": "Images",
"classname": "user",
"name": "img_gen_cfg_scale"
},
{
"UI_V2_Only": True,
"uitype": "toggle",
"unit": "bool",
@@ -573,6 +631,22 @@ gensettingstf = [
"name": "keep_img_gen_in_memory"
},
{
"UI_V2_Only": True,
"uitype": "toggle",
"unit": "bool",
"label": "Reset Image Generating",
"id": "generating_image",
"min": 0,
"max": 1,
"step": 1,
"default": 0,
"tooltip": "Use to reset image gen flag in case of error.",
"menu_path": "Interface",
"sub_path": "Images",
"classname": "system",
"name": "generating_image"
},
{
"UI_V2_Only": True,
"uitype": "toggle",
"unit": "bool",

View File

@@ -993,7 +993,11 @@ class user_settings(settings):
self.beep_on_complete = False
self.img_gen_priority = 1
self.show_budget = False
self.img_gen_api_url = "http://127.0.0.1:7860/"
self.img_gen_api_url = "http://127.0.0.1:7860"
self.img_gen_art_guide = "fantasy illustration, artstation, by jason felix by steve argyle by tyler jacobson by peter mohrbacher, cinematic lighting"
self.img_gen_negative_prompt = "lowres, bad anatomy, bad hands, text, error, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality, normal quality, jpeg artifacts, signature, watermark, username, blurry, artist name"
self.img_gen_steps = 30
self.img_gen_cfg_scale = 7
self.cluster_requested_models = [] # The models which we allow to generate during cluster mode