From 1f5a66fc15709bb5d86eef25e87957137f3addd8 Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 6 Jan 2024 19:23:19 +0100 Subject: [PATCH 1/3] Propmts Queue --- webui.py | 60 ++++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 47 insertions(+), 13 deletions(-) diff --git a/webui.py b/webui.py index 581e3101b..8c69d487a 100644 --- a/webui.py +++ b/webui.py @@ -23,13 +23,38 @@ from modules.auth import auth_enabled, check_auth +QUEUE_PROMPT = [] +FINISHED_IMG = [] + + +def queue_prompt_add(*args): + QUEUE_PROMPT.append(args) + + +def queue_prompt_start(*args): + FINISHED_IMG.clear() + if not QUEUE_PROMPT: + yield from generate_clicked(*args) + else: + while True: + try: + yield from generate_clicked(*QUEUE_PROMPT.pop(0)) + except IndexError: + break + yield gr.update(visible=False), \ + gr.update(visible=False), \ + gr.update(visible=False), \ + gr.update(visible=True, value=FINISHED_IMG), \ + gr.update(value=f"Queue ({len(QUEUE_PROMPT)})") + + def generate_clicked(*args): import ldm_patched.modules.model_management as model_management with model_management.interrupt_processing_mutex: model_management.interrupt_processing = False - # outputs=[progress_html, progress_window, progress_gallery, gallery] + # outputs=[progress_html, progress_window, progress_gallery, gallery, queue_button] execution_start_time = time.perf_counter() task = worker.AsyncTask(args=list(args)) @@ -37,8 +62,9 @@ def generate_clicked(*args): yield gr.update(visible=True, value=modules.html.make_progress_html(1, 'Waiting for task to start ...')), \ gr.update(visible=True, value=None), \ - gr.update(visible=False, value=None), \ - gr.update(visible=False) + gr.update(visible=bool(FINISHED_IMG), value=FINISHED_IMG), \ + gr.update(visible=False), \ + gr.update() worker.async_tasks.append(task) @@ -50,7 +76,7 @@ def generate_clicked(*args): # help bad internet connection by skipping duplicated preview if len(task.yields) > 0: # if we have the next item - if task.yields[0][0] == 'preview': # if the next item is also a preview + if task.yields[0][0] == 'preview': # if the next item is also a preview # print('Skipped one preview for better internet connection.') continue @@ -58,17 +84,21 @@ def generate_clicked(*args): yield gr.update(visible=True, value=modules.html.make_progress_html(percentage, title)), \ gr.update(visible=True, value=image) if image is not None else gr.update(), \ gr.update(), \ - gr.update(visible=False) + gr.update(visible=False), \ + gr.update() if flag == 'results': + FINISHED_IMG.append(product[-1]) yield gr.update(visible=True), \ gr.update(visible=True), \ - gr.update(visible=True, value=product), \ - gr.update(visible=False) - if flag == 'finish': - yield gr.update(visible=False), \ + gr.update(visible=True, value=FINISHED_IMG), \ gr.update(visible=False), \ + gr.update() + if flag == 'finish': + yield gr.update(visible=True), \ + gr.update(visible=True), \ + gr.update(visible=True, value=FINISHED_IMG), \ gr.update(visible=False), \ - gr.update(visible=True, value=product) + gr.update(value=f"Queue ({len(QUEUE_PROMPT)})") finished = True execution_time = time.perf_counter() - execution_start_time @@ -110,8 +140,9 @@ def generate_clicked(*args): shared.gradio_root.load(lambda: default_prompt, outputs=prompt) with gr.Column(scale=3, min_width=0): - generate_button = gr.Button(label="Generate", value="Generate", elem_classes='type_row', elem_id='generate_button', visible=True) - load_parameter_button = gr.Button(label="Load Parameters", value="Load Parameters", elem_classes='type_row', elem_id='load_parameter_button', visible=False) + generate_button = gr.Button(label="Generate", value="Generate", elem_classes='type_row_half', elem_id='generate_button', visible=True) + queue_button = gr.Button(label="Queue", value="Queue (0)", elem_classes='type_row_half', elem_id='queue_button', visible=True) + load_parameter_button = gr.Button(label="Load Parameters", value="Load Parameters", elem_classes='type_row_half', elem_id='load_parameter_button', visible=False) skip_button = gr.Button(label="Skip", value="Skip", elem_classes='type_row_half', visible=False) stop_button = gr.Button(label="Stop", value="Stop", elem_classes='type_row_half', elem_id='stop_button', visible=False) @@ -583,11 +614,14 @@ def parse_meta(raw_prompt_txt, is_generating): outputs=[stop_button, skip_button, generate_button, gallery, state_is_generating]) \ .then(fn=refresh_seed, inputs=[seed_random, image_seed], outputs=image_seed) \ .then(advanced_parameters.set_all_advanced_parameters, inputs=adps) \ - .then(fn=generate_clicked, inputs=ctrls, outputs=[progress_html, progress_window, progress_gallery, gallery]) \ + .then(fn=queue_prompt_start, inputs=ctrls, outputs=[progress_html, progress_window, progress_gallery, gallery, queue_button]) \ .then(lambda: (gr.update(visible=True, interactive=True), gr.update(visible=False, interactive=False), gr.update(visible=False, interactive=False), False), outputs=[generate_button, stop_button, skip_button, state_is_generating]) \ .then(fn=lambda: None, _js='playNotification').then(fn=lambda: None, _js='refresh_grid_delayed') + queue_button.click(fn=queue_prompt_add, inputs=ctrls) \ + .then(lambda: (gr.update(value=f"Queue ({len(QUEUE_PROMPT)})")), outputs=[queue_button]) + for notification_file in ['notification.ogg', 'notification.mp3']: if os.path.exists(notification_file): gr.Audio(interactive=False, value=notification_file, elem_id='audio_notification', visible=False) From ff823b61fff35c571636327d57441209b24c5ed2 Mon Sep 17 00:00:00 2001 From: docppp <29142757+docppp@users.noreply.github.com> Date: Sat, 13 Jan 2024 22:36:57 +0100 Subject: [PATCH 2/3] max 32 in gallery --- webui.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/webui.py b/webui.py index 8c69d487a..b95e85144 100644 --- a/webui.py +++ b/webui.py @@ -87,7 +87,9 @@ def generate_clicked(*args): gr.update(visible=False), \ gr.update() if flag == 'results': + global FINISHED_IMG FINISHED_IMG.append(product[-1]) + FINISHED_IMG = FINISHED_IMG[-32:] yield gr.update(visible=True), \ gr.update(visible=True), \ gr.update(visible=True, value=FINISHED_IMG), \ @@ -123,7 +125,7 @@ def generate_clicked(*args): with gr.Row(): progress_window = grh.Image(label='Preview', show_label=True, visible=False, height=768, elem_classes=['main_view']) - progress_gallery = gr.Gallery(label='Finished Images', show_label=True, object_fit='contain', + progress_gallery = gr.Gallery(label='Finished Images (max last 32)', show_label=True, object_fit='contain', height=768, visible=False, elem_classes=['main_view', 'image_gallery']) progress_html = gr.HTML(value=modules.html.make_progress_html(32, 'Progress 32%'), visible=False, elem_id='progress-bar', elem_classes='progress-bar') From b3b26136a2ca777a50efc739ff7b2fc0ec669179 Mon Sep 17 00:00:00 2001 From: docppp <29142757+docppp@users.noreply.github.com> Date: Sat, 13 Jan 2024 22:40:24 +0100 Subject: [PATCH 3/3] Update webui.py --- webui.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webui.py b/webui.py index b95e85144..9126384c9 100644 --- a/webui.py +++ b/webui.py @@ -49,6 +49,7 @@ def queue_prompt_start(*args): def generate_clicked(*args): + global FINISHED_IMG import ldm_patched.modules.model_management as model_management with model_management.interrupt_processing_mutex: @@ -87,7 +88,6 @@ def generate_clicked(*args): gr.update(visible=False), \ gr.update() if flag == 'results': - global FINISHED_IMG FINISHED_IMG.append(product[-1]) FINISHED_IMG = FINISHED_IMG[-32:] yield gr.update(visible=True), \