Merge pull request #299 from Viningr/UI2

New configuration options for image gen/ Fixed prompt and param sending to SD API
This commit is contained in:
ebolam
2022-11-15 12:02:22 -05:00
committed by GitHub
3 changed files with 97 additions and 24 deletions

View File

@@ -9111,8 +9111,8 @@ def UI_2_generate_image(data):
koboldai_vars.generating_image = True koboldai_vars.generating_image = True
eventlet.sleep(0) 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)
print("Generating image using data:{} and art guide:{}".format(data,art_guide))
#get latest action #get latest action
if len(koboldai_vars.actions) > 0: if len(koboldai_vars.actions) > 0:
action = koboldai_vars.actions[-1] action = koboldai_vars.actions[-1]
@@ -9191,7 +9191,9 @@ def UI_2_generate_image(data):
@logger.catch @logger.catch
def text2img_local(prompt, art_guide="", filename="new.png"): def text2img_local(prompt,
art_guide="",
filename="new.png"):
start_time = time.time() start_time = time.time()
logger.debug("Generating Image") logger.debug("Generating Image")
koboldai_vars.aibusy = True koboldai_vars.aibusy = True
@@ -9210,7 +9212,7 @@ def text2img_local(prompt, art_guide="", filename="new.png"):
from torch import autocast from torch import autocast
with autocast("cuda"): with autocast("cuda"):
return pipe(prompt, num_inference_steps=num_inference_steps).images[0] 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=koboldai_vars.img_gen_steps)
buffered = BytesIO() buffered = BytesIO()
image.save(buffered, format="JPEG") image.save(buffered, format="JPEG")
img_str = base64.b64encode(buffered.getvalue()).decode('ascii') img_str = base64.b64encode(buffered.getvalue()).decode('ascii')
@@ -9231,7 +9233,7 @@ def text2img_local(prompt, art_guide="", filename="new.png"):
@logger.catch @logger.catch
def text2img_horde(prompt, 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 = "",
filename = "story_art.png"): filename = "story_art.png"):
logger.debug("Generating Image using Horde") logger.debug("Generating Image using Horde")
koboldai_vars.generating_image = True koboldai_vars.generating_image = True
@@ -9248,8 +9250,8 @@ def text2img_horde(prompt,
"nsfw": True, "nsfw": True,
"sampler_name": "k_euler_a", "sampler_name": "k_euler_a",
"karras": True, "karras": True,
"cfg_scale": 7.0, "cfg_scale": koboldai_vars.img_gen_cfg_scale,
"steps":25, "steps":koboldai_vars.img_gen_steps,
"width":512, "width":512,
"height":512} "height":512}
} }
@@ -9279,13 +9281,10 @@ def text2img_horde(prompt,
@logger.catch @logger.catch
def text2img_api(prompt, def text2img_api(prompt,
#art_guide = 'fantasy illustration, artstation, by Hugin Miyama by Taiki Kawakami, cinematic lighting', art_guide = "",
art_guide = 'fantasy illustration, artstation, by jason felix by steve argyle by tyler jacobson by peter mohrbacher, cinematic lighting',
filename = "story_art.png"): filename = "story_art.png"):
logger.debug("Generating Image using Local SD-WebUI API") logger.debug("Generating Image using Local SD-WebUI API")
koboldai_vars.generating_image = True 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. #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, #"enable_hr": false,
#"denoising_strength": 0, #"denoising_strength": 0,
@@ -9317,22 +9316,19 @@ def text2img_api(prompt,
#"override_settings": {}, #"override_settings": {},
#"sampler_index": "Euler" #"sampler_index": "Euler"
final_imgen_params = { final_imgen_params = {
"n": 1, "prompt": "{}, {}".format(prompt, art_guide),
"n_iter": 1,
"width": 512, "width": 512,
"height": 512, "height": 512,
"steps": 40, "steps": koboldai_vars.img_gen_steps,
"cfg_scale": 10, "cfg_scale": koboldai_vars.img_gen_cfg_scale,
"negative_prompt": "{}".format(negprompt), "negative_prompt": "{}".format(koboldai_vars.img_gen_negative_prompt),
"sampler_index": "Euler a" "sampler_index": "Euler a"
} }
final_submit_dict = {
"prompt": "{}, {}".format(prompt, art_guide),
"params": final_imgen_params,
}
apiaddress = '{}/sdapi/v1/txt2img'.format(koboldai_vars.img_gen_api_url) apiaddress = '{}/sdapi/v1/txt2img'.format(koboldai_vars.img_gen_api_url)
payload_json = json.dumps(final_submit_dict) payload_json = json.dumps(final_imgen_params)
logger.debug(final_submit_dict) logger.debug(final_imgen_params)
#print("payload_json contains " + payload_json)
submit_req = requests.post(url=f'{apiaddress}', data=payload_json).json() submit_req = requests.post(url=f'{apiaddress}', data=payload_json).json()
if submit_req: if submit_req:
results = submit_req results = submit_req
@@ -9350,7 +9346,6 @@ def text2img_api(prompt,
prompttext = results.get('info').split("\",")[0].split("\"")[3] prompttext = results.get('info').split("\",")[0].split("\"")[3]
pnginfo.add_text("parameters","prompttext") pnginfo.add_text("parameters","prompttext")
img.save(final_filename, pnginfo=pnginfo) img.save(final_filename, pnginfo=pnginfo)
#img.save(final_filename)
logger.debug("Saved Image") logger.debug("Saved Image")
koboldai_vars.generating_image = False koboldai_vars.generating_image = False
return(b64img) return(b64img)

View File

@@ -557,6 +557,64 @@ gensettingstf = [
"name": "img_gen_api_url" "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": "float",
"label": "Cfg Scale",
"id": "img_gen_cfg_scale",
"min": 1,
"max": 30,
"step": 0.5,
"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, "UI_V2_Only": True,
"uitype": "toggle", "uitype": "toggle",
"unit": "bool", "unit": "bool",
@@ -573,6 +631,22 @@ gensettingstf = [
"name": "keep_img_gen_in_memory" "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, "UI_V2_Only": True,
"uitype": "toggle", "uitype": "toggle",
"unit": "bool", "unit": "bool",

View File

@@ -993,7 +993,11 @@ class user_settings(settings):
self.beep_on_complete = False self.beep_on_complete = False
self.img_gen_priority = 1 self.img_gen_priority = 1
self.show_budget = False 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.0
self.cluster_requested_models = [] # The models which we allow to generate during cluster mode self.cluster_requested_models = [] # The models which we allow to generate during cluster mode