From 87e2703c65dd9e3d85e83d7f8087315ca5c2c094 Mon Sep 17 00:00:00 2001 From: hlky <106811348+hlky@users.noreply.github.com> Date: Wed, 24 Aug 2022 15:30:02 +0100 Subject: [PATCH 1/6] loopback fix messed up on merge due to conflicts --- webui.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/webui.py b/webui.py index 42dec131451..029e1343908 100644 --- a/webui.py +++ b/webui.py @@ -635,7 +635,7 @@ def flag(self, flag_data, flag_option=None, flag_index=None, username=None): ) -def img2img(prompt: str, init_img, ddim_steps: int, use_GFPGAN: bool, prompt_matrix, n_iter: int, batch_size: int, cfg_scale: float, denoising_strength: float, seed: int, height: int, width: int, resize_mode: int): +def img2img(prompt: str, init_img, ddim_steps: int, use_GFPGAN: bool, prompt_matrix, loopback: bool, n_iter: int, batch_size: int, cfg_scale: float, denoising_strength: float, seed: int, height: int, width: int, resize_mode: int): outpath = opt.outdir or "outputs/img2img-samples" err = False @@ -754,6 +754,7 @@ def sample(init_data, x, conditioning, unconditional_conditioning): gr.Slider(minimum=1, maximum=150, step=1, label="Sampling Steps", value=50), gr.Checkbox(label='Fix faces using GFPGAN', value=False, visible=GFPGAN is not None), gr.Checkbox(label='Create prompt matrix (separate multiple prompts using |, and get all combinations of them)', value=False), + gr.Checkbox(label='Loopback (use images from previous batch when creating next batch)', value=False), gr.Slider(minimum=1, maximum=16, step=1, label='Batch count (how many batches of images to generate)', value=1), gr.Slider(minimum=1, maximum=8, step=1, label='Batch size (how many images are in a batch; memory-hungry)', value=1), gr.Slider(minimum=1.0, maximum=15.0, step=0.5, label='Classifier Free Guidance Scale (how strongly the image should follow the prompt)', value=7.0), From e59b0ef903929b5cb18bb2c0f3020f43605dd986 Mon Sep 17 00:00:00 2001 From: hlky <106811348+hlky@users.noreply.github.com> Date: Wed, 24 Aug 2022 15:33:25 +0100 Subject: [PATCH 2/6] do_not_save_grid merge conflict again --- webui.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/webui.py b/webui.py index 029e1343908..3b647e79d8e 100644 --- a/webui.py +++ b/webui.py @@ -377,7 +377,7 @@ def check_prompt_length(prompt, comments): comments.append(f"Warning: too many input tokens; some ({len(overflowing_words)}) have been truncated:\n{overflowing_text}\n") -def process_images(outpath, func_init, func_sample, prompt, seed, sampler_name, batch_size, n_iter, steps, cfg_scale, width, height, prompt_matrix, use_GFPGAN): +def process_images(outpath, func_init, func_sample, prompt, seed, sampler_name, batch_size, n_iter, steps, cfg_scale, width, height, prompt_matrix, use_GFPGAN, do_not_save_grid=False): """this is the main loop that both txt2img and img2img use; it calls func_init once inside all the scopes and func_sample once per batch""" assert prompt is not None torch_gc() @@ -474,7 +474,7 @@ def process_images(outpath, func_init, func_sample, prompt, seed, sampler_name, output_images.append(image) base_count += 1 - if prompt_matrix or not opt.skip_grid: + if (prompt_matrix or not opt.skip_grid) and not do_not_save_grid: grid = image_grid(output_images, batch_size, round_down=prompt_matrix) if prompt_matrix: From 10c856011c4cba36dfdcfcb258b28e23554bdc7f Mon Sep 17 00:00:00 2001 From: hlky <106811348+hlky@users.noreply.github.com> Date: Wed, 24 Aug 2022 15:38:48 +0100 Subject: [PATCH 3/6] image_grid CONFLIIIIICT --- webui.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/webui.py b/webui.py index 3b647e79d8e..18deec19029 100644 --- a/webui.py +++ b/webui.py @@ -237,8 +237,10 @@ def load_GFPGAN(): model = (model if opt.no_half else model.half()).to(device) -def image_grid(imgs, batch_size, round_down=False): - if opt.n_rows > 0: +def image_grid(imgs, batch_size, round_down=False, force_n_rows=None): + if force_n_rows is not None: + rows = force_n_rows + elif opt.n_rows > 0: rows = opt.n_rows elif opt.n_rows == 0: rows = batch_size @@ -257,6 +259,7 @@ def image_grid(imgs, batch_size, round_down=False): return grid + def draw_prompt_matrix(im, width, height, all_prompts): def wrap(text, d, font, line_length): lines = [''] From b2685b0a1b99657f4851acde278980150d517aad Mon Sep 17 00:00:00 2001 From: hlky <106811348+hlky@users.noreply.github.com> Date: Wed, 24 Aug 2022 15:44:34 +0100 Subject: [PATCH 4/6] jpg grid f u --- webui.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/webui.py b/webui.py index 18deec19029..a8aa9951c6b 100644 --- a/webui.py +++ b/webui.py @@ -709,7 +709,8 @@ def sample(init_data, x, conditioning, unconditional_conditioning): grid_count = len(os.listdir(outpath)) - 1 grid = image_grid(history, batch_size, force_n_rows=1) - grid.save(os.path.join(outpath, f'grid-{grid_count:04}.{opt.grid_format}')) + grid_file = f"grid-{grid_count:05}-{seed}_{prompt.replace(' ', '_').translate({ord(x): '' for x in invalid_filename_chars})[:128]}.jpg" + grid.save(os.path.join(outpath, grid_file), 'jpeg', quality=80, optimize=True) output_images = history seed = initial_seed From 741182aee88b4f9c22ea3a40550d1cca160a5444 Mon Sep 17 00:00:00 2001 From: hlky <106811348+hlky@users.noreply.github.com> Date: Wed, 24 Aug 2022 16:05:14 +0100 Subject: [PATCH 5/6] Ready for theme support Currently, only the 'default' theme is supported wait Gradio to do the needful theme support --- webui.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/webui.py b/webui.py index a8aa9951c6b..68adad64615 100644 --- a/webui.py +++ b/webui.py @@ -634,7 +634,8 @@ def flag(self, flag_data, flag_option=None, flag_index=None, username=None): ], title="Stable Diffusion Text-to-Image Unified", description="Generate images from text with Stable Diffusion", - flagging_callback=Flagging() + flagging_callback=Flagging(), + theme="default", ) @@ -777,6 +778,7 @@ def sample(init_data, x, conditioning, unconditional_conditioning): title="Stable Diffusion Image-to-Image Unified", description="Generate images from images with Stable Diffusion", allow_flagging="never", + theme="default", ) interfaces = [ @@ -809,12 +811,14 @@ def run_GFPGAN(image, strength): title="GFPGAN", description="Fix faces on images", allow_flagging="never", + theme="default", ), "GFPGAN")) demo = gr.TabbedInterface( interface_list=[x[0] for x in interfaces], tab_names=[x[1] for x in interfaces], - css=("" if opt.no_progressbar_hiding else css_hide_progressbar) + css=("" if opt.no_progressbar_hiding else css_hide_progressbar), + theme="default", ) demo.launch() \ No newline at end of file From 065ad3239d02742d129b0076ff8149c7a3ef4886 Mon Sep 17 00:00:00 2001 From: hlky <106811348+hlky@users.noreply.github.com> Date: Wed, 24 Aug 2022 16:06:11 +0100 Subject: [PATCH 6/6] local network support --- webui.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webui.py b/webui.py index 68adad64615..6525e80b34e 100644 --- a/webui.py +++ b/webui.py @@ -821,4 +821,4 @@ def run_GFPGAN(image, strength): theme="default", ) -demo.launch() \ No newline at end of file +demo.launch(server_name='0.0.0.0') \ No newline at end of file