From a0d721e109d7c7b75aefaf3853f7bf58da43847b Mon Sep 17 00:00:00 2001 From: AUTOMATIC1111 <16777216c@gmail.com> Date: Sun, 20 Aug 2023 13:00:59 +0300 Subject: make live preview display work independently from progress bar --- modules/progress.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'modules/progress.py') diff --git a/modules/progress.py b/modules/progress.py index f405f07f..e32b59dd 100644 --- a/modules/progress.py +++ b/modules/progress.py @@ -48,6 +48,7 @@ def add_task_to_queue(id_job): class ProgressRequest(BaseModel): id_task: str = Field(default=None, title="Task ID", description="id of the task to get progress for") id_live_preview: int = Field(default=-1, title="Live preview image ID", description="id of last received last preview image") + live_preview: bool = Field(default=True, title="Include live preview", description="boolean flag indicating whether to include the live preview image") class ProgressResponse(BaseModel): @@ -91,7 +92,7 @@ def progressapi(req: ProgressRequest): id_live_preview = req.id_live_preview shared.state.set_current_image() - if opts.live_previews_enable and shared.state.id_live_preview != req.id_live_preview: + if opts.live_previews_enable and req.live_preview and shared.state.id_live_preview != req.id_live_preview: image = shared.state.current_image if image is not None: buffered = io.BytesIO() -- cgit v1.2.1 From 71a0f6ef85f2124d5fb25b55d6ec577a56265fe4 Mon Sep 17 00:00:00 2001 From: AnyISalIn Date: Mon, 21 Aug 2023 17:48:56 +0800 Subject: feat: replace threading.Lock() to FIFOLock Signed-off-by: AnyISalIn --- modules/progress.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'modules/progress.py') diff --git a/modules/progress.py b/modules/progress.py index e32b59dd..a25a0113 100644 --- a/modules/progress.py +++ b/modules/progress.py @@ -72,7 +72,12 @@ def progressapi(req: ProgressRequest): completed = req.id_task in finished_tasks if not active: - return ProgressResponse(active=active, queued=queued, completed=completed, id_live_preview=-1, textinfo="In queue..." if queued else "Waiting...") + textinfo = "Waiting..." + if queued: + sorted_queued = sorted(pending_tasks.keys(), key=lambda x: pending_tasks[x]) + queue_index = sorted_queued.index(req.id_task) + textinfo = "In queue: {}/{}".format(queue_index + 1, len(sorted_queued)) + return ProgressResponse(active=active, queued=queued, completed=completed, id_live_preview=-1, textinfo=textinfo) progress = 0 -- cgit v1.2.1 From a459075d26eecc38d6d58116e38f453450191460 Mon Sep 17 00:00:00 2001 From: AUTOMATIC1111 <16777216c@gmail.com> Date: Tue, 22 Aug 2023 10:41:10 +0300 Subject: actual solution to the uncommon hanging problem that is seemingly caused by multiple progress requests working on same tensor --- modules/progress.py | 45 ++++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 23 deletions(-) (limited to 'modules/progress.py') diff --git a/modules/progress.py b/modules/progress.py index a25a0113..69921de7 100644 --- a/modules/progress.py +++ b/modules/progress.py @@ -95,31 +95,30 @@ def progressapi(req: ProgressRequest): predicted_duration = elapsed_since_start / progress if progress > 0 else None eta = predicted_duration - elapsed_since_start if predicted_duration is not None else None + live_preview = None id_live_preview = req.id_live_preview - shared.state.set_current_image() - if opts.live_previews_enable and req.live_preview and shared.state.id_live_preview != req.id_live_preview: - image = shared.state.current_image - if image is not None: - buffered = io.BytesIO() - - if opts.live_previews_image_format == "png": - # using optimize for large images takes an enormous amount of time - if max(*image.size) <= 256: - save_kwargs = {"optimize": True} + + if opts.live_previews_enable and req.live_preview: + shared.state.set_current_image() + if shared.state.id_live_preview != req.id_live_preview: + image = shared.state.current_image + if image is not None: + buffered = io.BytesIO() + + if opts.live_previews_image_format == "png": + # using optimize for large images takes an enormous amount of time + if max(*image.size) <= 256: + save_kwargs = {"optimize": True} + else: + save_kwargs = {"optimize": False, "compress_level": 1} + else: - save_kwargs = {"optimize": False, "compress_level": 1} - - else: - save_kwargs = {} - - image.save(buffered, format=opts.live_previews_image_format, **save_kwargs) - base64_image = base64.b64encode(buffered.getvalue()).decode('ascii') - live_preview = f"data:image/{opts.live_previews_image_format};base64,{base64_image}" - id_live_preview = shared.state.id_live_preview - else: - live_preview = None - else: - live_preview = None + save_kwargs = {} + + image.save(buffered, format=opts.live_previews_image_format, **save_kwargs) + base64_image = base64.b64encode(buffered.getvalue()).decode('ascii') + live_preview = f"data:image/{opts.live_previews_image_format};base64,{base64_image}" + id_live_preview = shared.state.id_live_preview return ProgressResponse(active=active, queued=queued, completed=completed, progress=progress, eta=eta, live_preview=live_preview, id_live_preview=id_live_preview, textinfo=shared.state.textinfo) -- cgit v1.2.1