Add custom prompt format for SD API pictures (#1964)

This commit is contained in:
Minecrafter20 2023-06-27 15:49:18 -05:00 committed by GitHub
parent cb029cf65f
commit 40bbd53640
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -36,9 +36,9 @@ params = {
'sampler_name': 'DDIM', 'sampler_name': 'DDIM',
'steps': 32, 'steps': 32,
'cfg_scale': 7, 'cfg_scale': 7,
'sd_checkpoint' : ' ', 'textgen_prefix': 'Please provide a detailed and vivid description of [subject]',
'checkpoint_list' : [" "] 'sd_checkpoint': ' ',
'checkpoint_list': [" "]
} }
@ -119,14 +119,15 @@ def input_modifier(string):
string = string.lower() string = string.lower()
if "of" in string: if "of" in string:
subject = string.split('of', 1)[1] # subdivide the string once by the first 'of' instance and get what's coming after it subject = string.split('of', 1)[1] # subdivide the string once by the first 'of' instance and get what's coming after it
string = "Please provide a detailed and vivid description of " + subject string = params['textgen_prefix'].replace("[subject]", subject)
else: else:
string = "Please provide a detailed description of your appearance, your surroundings and what you are doing right now" string = params['textgen_prefix'].replace("[subject]", "your appearance, your surroundings and what you are doing right now")
return string return string
# Get and save the Stable Diffusion-generated picture # Get and save the Stable Diffusion-generated picture
def get_SD_pictures(description): def get_SD_pictures(description):
global params global params
if params['manage_VRAM']: if params['manage_VRAM']:
@ -267,6 +268,7 @@ def custom_css():
path_to_css = Path(__file__).parent.resolve() / 'style.css' path_to_css = Path(__file__).parent.resolve() / 'style.css'
return open(path_to_css, 'r').read() return open(path_to_css, 'r').read()
def get_checkpoints(): def get_checkpoints():
global params global params
@ -282,6 +284,7 @@ def get_checkpoints():
return gr.update(choices=params['checkpoint_list'], value=params['sd_checkpoint']) return gr.update(choices=params['checkpoint_list'], value=params['sd_checkpoint'])
def load_checkpoint(checkpoint): def load_checkpoint(checkpoint):
payload = { payload = {
@ -290,6 +293,7 @@ def load_checkpoint(checkpoint):
requests.post(url=f'{params["address"]}/sdapi/v1/options', json=payload) requests.post(url=f'{params["address"]}/sdapi/v1/options', json=payload)
def get_samplers(): def get_samplers():
try: try:
response = requests.get(url=f'{params["address"]}/sdapi/v1/samplers') response = requests.get(url=f'{params["address"]}/sdapi/v1/samplers')
@ -322,6 +326,7 @@ def ui():
with gr.Accordion("Generation parameters", open=False): with gr.Accordion("Generation parameters", open=False):
prompt_prefix = gr.Textbox(placeholder=params['prompt_prefix'], value=params['prompt_prefix'], label='Prompt Prefix (best used to describe the look of the character)') prompt_prefix = gr.Textbox(placeholder=params['prompt_prefix'], value=params['prompt_prefix'], label='Prompt Prefix (best used to describe the look of the character)')
textgen_prefix = gr.Textbox(placeholder=params['textgen_prefix'], value=params['textgen_prefix'], label='textgen prefix (type [subject] where the subject should be placed)')
negative_prompt = gr.Textbox(placeholder=params['negative_prompt'], value=params['negative_prompt'], label='Negative Prompt') negative_prompt = gr.Textbox(placeholder=params['negative_prompt'], value=params['negative_prompt'], label='Negative Prompt')
with gr.Row(): with gr.Row():
with gr.Column(): with gr.Column():
@ -353,6 +358,7 @@ def ui():
address.submit(fn=SD_api_address_update, inputs=address, outputs=address) address.submit(fn=SD_api_address_update, inputs=address, outputs=address)
prompt_prefix.change(lambda x: params.update({"prompt_prefix": x}), prompt_prefix, None) prompt_prefix.change(lambda x: params.update({"prompt_prefix": x}), prompt_prefix, None)
textgen_prefix.change(lambda x: params.update({"textgen_prefix": x}), textgen_prefix, None)
negative_prompt.change(lambda x: params.update({"negative_prompt": x}), negative_prompt, None) negative_prompt.change(lambda x: params.update({"negative_prompt": x}), negative_prompt, None)
width.change(lambda x: params.update({"width": x}), width, None) width.change(lambda x: params.update({"width": x}), width, None)
height.change(lambda x: params.update({"height": x}), height, None) height.change(lambda x: params.update({"height": x}), height, None)