From 003b60b94e42e21e9213b286b6a51a222db1076a Mon Sep 17 00:00:00 2001 From: AUTOMATIC <16777216c@gmail.com> Date: Fri, 9 Sep 2022 09:15:36 +0300 Subject: [PATCH] add an option to show negative prompt --- modules/img2img.py | 3 ++- modules/shared.py | 3 +++ modules/ui.py | 4 +++- style.css | 2 +- 4 files changed, 9 insertions(+), 3 deletions(-) diff --git a/modules/img2img.py b/modules/img2img.py index 0c91ef3f0..00bd626c3 100644 --- a/modules/img2img.py +++ b/modules/img2img.py @@ -11,7 +11,7 @@ from modules.ui import plaintext_to_html import modules.images as images import modules.scripts -def img2img(prompt: str, init_img, init_img_with_mask, steps: int, sampler_index: int, mask_blur: int, inpainting_fill: int, restore_faces: bool, tiling: bool, mode: int, n_iter: int, batch_size: int, cfg_scale: float, denoising_strength: float, denoising_strength_change_factor: float, seed: int, height: int, width: int, resize_mode: int, upscaler_index: str, upscale_overlap: int, inpaint_full_res: bool, inpainting_mask_invert: int, *args): +def img2img(prompt: str, negative_prompt: str, init_img, init_img_with_mask, steps: int, sampler_index: int, mask_blur: int, inpainting_fill: int, restore_faces: bool, tiling: bool, mode: int, n_iter: int, batch_size: int, cfg_scale: float, denoising_strength: float, denoising_strength_change_factor: float, seed: int, height: int, width: int, resize_mode: int, upscaler_index: str, upscale_overlap: int, inpaint_full_res: bool, inpainting_mask_invert: int, *args): is_inpaint = mode == 1 is_loopback = mode == 2 is_upscale = mode == 3 @@ -32,6 +32,7 @@ def img2img(prompt: str, init_img, init_img_with_mask, steps: int, sampler_index outpath_samples=opts.outdir_samples or opts.outdir_img2img_samples, outpath_grids=opts.outdir_grids or opts.outdir_img2img_grids, prompt=prompt, + negative_prompt=negative_prompt, seed=seed, sampler_index=sampler_index, batch_size=batch_size, diff --git a/modules/shared.py b/modules/shared.py index 89e44f3de..280c07fff 100644 --- a/modules/shared.py +++ b/modules/shared.py @@ -37,6 +37,8 @@ parser.add_argument("--esrgan-models-path", type=str, help="path to directory wi parser.add_argument("--opt-split-attention", action='store_true', help="enable optimization that reduce vram usage by a lot for about 10%% decrease in performance") parser.add_argument("--listen", action='store_true', help="launch gradio with 0.0.0.0 as server name, allowing to respond to network requests") parser.add_argument("--port", type=int, help="launch gradio with given server port, you need root/admin rights for ports < 1024, defaults to 7860 if available", default=None) +parser.add_argument("--show-negative-prompt", action='store_true', help="enable the field that lets you input negative prompt", default=False) + cmd_opts = parser.parse_args() if torch.has_cuda: @@ -76,6 +78,7 @@ artist_db = modules.artists.ArtistsDatabase(os.path.join(script_path, 'artists.c face_restorers = [] + def find_any_font(): fonts = ['/usr/share/fonts/truetype/liberation/LiberationSans-Regular.ttf'] diff --git a/modules/ui.py b/modules/ui.py index ccd2d8539..a2ff660a2 100644 --- a/modules/ui.py +++ b/modules/ui.py @@ -196,7 +196,7 @@ def create_ui(txt2img, img2img, run_extras, run_pnginfo): with gr.Blocks(analytics_enabled=False) as txt2img_interface: with gr.Row(): prompt = gr.Textbox(label="Prompt", elem_id="txt2img_prompt", show_label=False, placeholder="Prompt", lines=1) - negative_prompt = gr.Textbox(label="Negative prompt", elem_id="txt2img_negative_prompt", show_label=False, placeholder="Negative prompt", lines=1, visible=False) + negative_prompt = gr.Textbox(label="Negative prompt", elem_id="txt2img_negative_prompt", show_label=False, placeholder="Negative prompt", lines=1, visible=cmd_opts.show_negative_prompt) roll = gr.Button('Roll', elem_id="txt2img_roll", visible=len(shared.artist_db.artists) > 0) submit = gr.Button('Generate', elem_id="txt2img_generate", variant='primary') check_progress = gr.Button('Check progress', elem_id="check_progress", visible=False) @@ -314,6 +314,7 @@ def create_ui(txt2img, img2img, run_extras, run_pnginfo): with gr.Blocks(analytics_enabled=False) as img2img_interface: with gr.Row(): prompt = gr.Textbox(label="Prompt", elem_id="img2img_prompt", show_label=False, placeholder="Prompt", lines=1) + negative_prompt = gr.Textbox(label="Negative prompt", elem_id="img2img_negative_prompt", show_label=False, placeholder="Negative prompt", lines=1, visible=cmd_opts.show_negative_prompt) submit = gr.Button('Generate', elem_id="img2img_generate", variant='primary') check_progress = gr.Button('Check progress', elem_id="check_progress", visible=False) @@ -423,6 +424,7 @@ def create_ui(txt2img, img2img, run_extras, run_pnginfo): _js="submit", inputs=[ prompt, + negative_prompt, init_img, init_img_with_mask, steps, diff --git a/style.css b/style.css index 2898686da..0ae72cc8e 100644 --- a/style.css +++ b/style.css @@ -14,7 +14,7 @@ button{ align-self: stretch !important; } -#img2img_prompt, #txt2img_prompt{ +#img2img_prompt, #txt2img_prompt, #img2img_negative_prompt, #txt2img_negative_prompt{ padding: 0; border: none !important; }