From 67c191575fec6569fe58d0fb7725951069dda2ec Mon Sep 17 00:00:00 2001 From: Manuel Schmid <9307310+mashb1t@users.noreply.github.com> Date: Sun, 19 May 2024 20:43:11 +0200 Subject: [PATCH] feat: progress bar improvements (#2962) * feat: align progress bar vertically * feat: use fixed width for status text, remove ordinals * refactor: align progress to actions --- css/style.css | 6 ++++++ modules/async_worker.py | 37 +++++++++++++++++++------------------ modules/flags.py | 1 + modules/util.py | 4 ---- 4 files changed, 26 insertions(+), 22 deletions(-) diff --git a/css/style.css b/css/style.css index b9e6e2ce18..b5f7a44886 100644 --- a/css/style.css +++ b/css/style.css @@ -27,6 +27,7 @@ progress { border-radius: 5px; /* Round the corners of the progress bar */ background-color: #f3f3f3; /* Light grey background */ width: 100%; + vertical-align: middle !important; } /* Style the progress bar container */ @@ -69,6 +70,11 @@ progress::after { height: 30px !important; } +.progress-bar span { + text-align: right; + width: 200px; +} + .type_row{ height: 80px !important; } diff --git a/modules/async_worker.py b/modules/async_worker.py index 302db84c10..8e4d6d957b 100644 --- a/modules/async_worker.py +++ b/modules/async_worker.py @@ -49,7 +49,7 @@ def worker(): from modules.private_logger import log from extras.expansion import safe_str from modules.util import (remove_empty_str, HWC3, resize_image, get_image_shape_ceil, set_image_shape_ceil, - get_shape_ceil, resample_image, erode_or_dilate, ordinal_suffix, get_enabled_loras, + get_shape_ceil, resample_image, erode_or_dilate, get_enabled_loras, parse_lora_references_from_prompt, apply_wildcards) from modules.upscaler import perform_upscale from modules.flags import Performance @@ -72,7 +72,7 @@ def progressbar(async_task, number, text): async_task.yields.append(['preview', (number, text, None)]) def yield_result(async_task, imgs, black_out_nsfw, censor=True, do_not_show_finished_images=False, - progressbar_index=13): + progressbar_index=flags.preparation_step_count): if not isinstance(imgs, list): imgs = [imgs] @@ -456,7 +456,7 @@ def handler(async_task): extra_positive_prompts = prompts[1:] if len(prompts) > 1 else [] extra_negative_prompts = negative_prompts[1:] if len(negative_prompts) > 1 else [] - progressbar(async_task, 3, 'Loading models ...') + progressbar(async_task, 2, 'Loading models ...') loras = parse_lora_references_from_prompt(prompt, loras, modules.config.default_max_lora_number) @@ -523,25 +523,25 @@ def handler(async_task): if use_expansion: for i, t in enumerate(tasks): - progressbar(async_task, 5, f'Preparing Fooocus text #{i + 1} ...') + progressbar(async_task, 4, f'Preparing Fooocus text #{i + 1} ...') expansion = pipeline.final_expansion(t['task_prompt'], t['task_seed']) print(f'[Prompt Expansion] {expansion}') t['expansion'] = expansion t['positive'] = copy.deepcopy(t['positive']) + [expansion] # Deep copy. for i, t in enumerate(tasks): - progressbar(async_task, 7, f'Encoding positive #{i + 1} ...') + progressbar(async_task, 5, f'Encoding positive #{i + 1} ...') t['c'] = pipeline.clip_encode(texts=t['positive'], pool_top_k=t['positive_top_k']) for i, t in enumerate(tasks): if abs(float(cfg_scale) - 1.0) < 1e-4: t['uc'] = pipeline.clone_cond(t['c']) else: - progressbar(async_task, 10, f'Encoding negative #{i + 1} ...') + progressbar(async_task, 6, f'Encoding negative #{i + 1} ...') t['uc'] = pipeline.clip_encode(texts=t['negative'], pool_top_k=t['negative_top_k']) if len(goals) > 0: - progressbar(async_task, 13, 'Image processing ...') + progressbar(async_task, 7, 'Image processing ...') if 'vary' in goals: if 'subtle' in uov_method: @@ -562,7 +562,7 @@ def handler(async_task): uov_input_image = set_image_shape_ceil(uov_input_image, shape_ceil) initial_pixels = core.numpy_to_pytorch(uov_input_image) - progressbar(async_task, 13, 'VAE encoding ...') + progressbar(async_task, 8, 'VAE encoding ...') candidate_vae, _ = pipeline.get_candidate_vae( steps=steps, @@ -579,7 +579,7 @@ def handler(async_task): if 'upscale' in goals: H, W, C = uov_input_image.shape - progressbar(async_task, 13, f'Upscaling image from {str((H, W))} ...') + progressbar(async_task, 9, f'Upscaling image from {str((H, W))} ...') uov_input_image = perform_upscale(uov_input_image) print(f'Image upscaled.') @@ -628,7 +628,7 @@ def handler(async_task): denoising_strength = overwrite_upscale_strength initial_pixels = core.numpy_to_pytorch(uov_input_image) - progressbar(async_task, 13, 'VAE encoding ...') + progressbar(async_task, 10, 'VAE encoding ...') candidate_vae, _ = pipeline.get_candidate_vae( steps=steps, @@ -686,7 +686,7 @@ def handler(async_task): do_not_show_finished_images=True) return - progressbar(async_task, 13, 'VAE Inpaint encoding ...') + progressbar(async_task, 11, 'VAE Inpaint encoding ...') inpaint_pixel_fill = core.numpy_to_pytorch(inpaint_worker.current_task.interested_fill) inpaint_pixel_image = core.numpy_to_pytorch(inpaint_worker.current_task.interested_image) @@ -706,7 +706,7 @@ def handler(async_task): latent_swap = None if candidate_vae_swap is not None: - progressbar(async_task, 13, 'VAE SD15 encoding ...') + progressbar(async_task, 12, 'VAE SD15 encoding ...') latent_swap = core.encode_vae( vae=candidate_vae_swap, pixels=inpaint_pixel_fill)['samples'] @@ -832,16 +832,17 @@ def handler(async_task): zsnr=False)[0] print(f'Using {scheduler_name} scheduler.') - async_task.yields.append(['preview', (13, 'Moving model to GPU ...', None)]) + async_task.yields.append(['preview', (flags.preparation_step_count, 'Moving model to GPU ...', None)]) def callback(step, x0, x, total_steps, y): done_steps = current_task_id * steps + step async_task.yields.append(['preview', ( - int(15.0 + 85.0 * float(done_steps) / float(all_steps)), - f'Step {step}/{total_steps} in the {current_task_id + 1}{ordinal_suffix(current_task_id + 1)} Sampling', - y)]) + int(flags.preparation_step_count + (100 - flags.preparation_step_count) * float(done_steps) / float(all_steps)), + f'Sampling step {step + 1}/{total_steps}, image {current_task_id + 1}/{image_number} ...', y)]) for current_task_id, task in enumerate(tasks): + current_progress = int(flags.preparation_step_count + (100 - flags.preparation_step_count) * float(current_task_id * steps) / float(all_steps)) + progressbar(async_task, current_progress, f'Preparing task {current_task_id + 1}/{image_number} ...') execution_start_time = time.perf_counter() try: @@ -884,12 +885,12 @@ def callback(step, x0, x, total_steps, y): imgs = [inpaint_worker.current_task.post_process(x) for x in imgs] img_paths = [] - current_progress = int(15.0 + 85.0 * float((current_task_id + 1) * steps) / float(all_steps)) + current_progress = int(flags.preparation_step_count + (100 - flags.preparation_step_count) * float((current_task_id + 1) * steps) / float(all_steps)) if modules.config.default_black_out_nsfw or black_out_nsfw: progressbar(async_task, current_progress, 'Checking for NSFW content ...') imgs = default_censor(imgs) - progressbar(async_task, current_progress, 'Saving image to system ...') + progressbar(async_task, current_progress, f'Saving image {current_task_id + 1}/{image_number} to system ...') for x in imgs: d = [('Prompt', 'prompt', task['log_positive_prompt']), ('Negative Prompt', 'negative_prompt', task['log_negative_prompt']), diff --git a/modules/flags.py b/modules/flags.py index 77ad012a22..7b3ac39330 100644 --- a/modules/flags.py +++ b/modules/flags.py @@ -93,6 +93,7 @@ class MetadataScheme(Enum): ] controlnet_image_count = 4 +preparation_step_count = 13 class OutputFormat(Enum): diff --git a/modules/util.py b/modules/util.py index 7343023063..8e85ffbe91 100644 --- a/modules/util.py +++ b/modules/util.py @@ -372,10 +372,6 @@ def get_file_from_folder_list(name, folders): return os.path.abspath(os.path.realpath(os.path.join(folders[0], name))) -def ordinal_suffix(number: int) -> str: - return 'th' if 10 <= number % 100 <= 20 else {1: 'st', 2: 'nd', 3: 'rd'}.get(number % 10, 'th') - - def makedirs_with_log(path): try: os.makedirs(path, exist_ok=True)