Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Propmts Queue #1773

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 50 additions & 14 deletions webui.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,49 @@
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):
global FINISHED_IMG
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))
finished = False

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)

Expand All @@ -50,25 +77,30 @@ 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

percentage, title, image = product
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])
FINISHED_IMG = FINISHED_IMG[-32:]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a note, the max image amount per generation is configurable in the config and only defaults to 32, so this might be changed to the config rather the hardcoded number

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather leave it as is, as more items in gallery may break things. It is easy to check what was generated in history log file where prompts are also shown.
@LordMilutin yup, clear button is a good idea and about point 2, see above.

@blablablazhik prompts from file is not in my plans, but you can try hardcoding it yourself (i believe i showed somewhere how to do it).

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would rather leave it as is, as more items in gallery may break things. It is easy to check what was generated in history log file where prompts are also shown. @LordMilutin yup, clear button is a good idea and about point 2, see above.

@blablablazhik prompts from file is not in my plans, but you can try hardcoding it yourself (i believe i showed somewhere how to do it).

Upon further usage, I agree that a clear queue button is a must, as well as a stop queue button. Because right now if I stop it, it will move on to another queue, and so on, so I have to stop each queue which is a lot if I have 50 queues.

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
Expand All @@ -93,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')
Expand All @@ -110,8 +142,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)

Expand Down Expand Up @@ -589,12 +622,15 @@ 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=update_history_link, outputs=history_link) \
.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)
Expand Down