From 58924a1fd617c7342e8c18700570becf1631c605 Mon Sep 17 00:00:00 2001 From: ljleb Date: Thu, 31 Aug 2023 01:34:46 -0400 Subject: [PATCH 1/2] Update README.md (#154) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b7796f3..7f03d7d 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ sd-webui-comfyui is an extension for [Automatic1111's stable-diffusion-webui](ht ## Features - Use ComfyUI directly into the Webui - Support for [loading custom nodes from other Webui extensions](https://github.com/ModelSurge/sd-webui-comfyui/wiki/Developing-custom-nodes-from-webui-extensions) -- Integration of ComfyUI workflows directly into the Webui's pipeline, such as `preprocess`, `preprocess (latent)`, `unet`, `postprocess (latent)`, `postprocess`, `transformer text encode`, etc. +- Integration of [ComfyUI workflows](https://github.com/ModelSurge/sd-webui-comfyui/wiki/Developing-custom-workflow-types) directly into the Webui's pipeline, such as `preprocess`, `preprocess (latent)`, `unet`, `postprocess (latent)`, `postprocess`, `transformer text encode`, etc. - Webui nodes for sharing resources and data, such as the model, the prompt, etc. For a full overview of all the advantageous features this extension adds to ComfyUI and to the Webui, check out the [wiki page](https://github.com/ModelSurge/sd-webui-comfyui/wiki). From 536169922b0715dbe5ca6afd6de52c16be0889ad Mon Sep 17 00:00:00 2001 From: ljleb Date: Thu, 31 Aug 2023 01:40:04 -0400 Subject: [PATCH 2/2] Fix for webui 1.6.0 (#153) * more unnecessary complexity * expect newer versions first * fix patches * fix reload to default workflow * dont need to await * rm print --- .../extensions/webuiNodes.js | 3 +++ .../extensions/webuiPatches.js | 4 ++++ javascript/compute-height.js | 14 ++++++++----- lib_comfyui/webui/patches.py | 21 +++++++++++++++++-- scripts/comfyui.py | 13 ++++++------ 5 files changed, 42 insertions(+), 13 deletions(-) diff --git a/comfyui_custom_scripts/extensions/webuiNodes.js b/comfyui_custom_scripts/extensions/webuiNodes.js index aef645c..af97722 100644 --- a/comfyui_custom_scripts/extensions/webuiNodes.js +++ b/comfyui_custom_scripts/extensions/webuiNodes.js @@ -88,6 +88,9 @@ app.registerExtension({ // 240 and 40 are empirical values that seem to work node.size = [240, 40 + distanceBetweenIoSlots * maxIoLength]; }, + async setup() { + app.loadGraphData(); + }, }); const webuiIoNodeNames = [ diff --git a/comfyui_custom_scripts/extensions/webuiPatches.js b/comfyui_custom_scripts/extensions/webuiPatches.js index 820a943..0a3db1f 100644 --- a/comfyui_custom_scripts/extensions/webuiPatches.js +++ b/comfyui_custom_scripts/extensions/webuiPatches.js @@ -58,6 +58,10 @@ async function patchDefaultGraph(iframeInfo) { const from_webui = LiteGraph.createNode("FromWebui"); const to_webui = LiteGraph.createNode("ToWebui"); + if (!from_webui || !to_webui) { + return; + } + app.graph.add(from_webui); app.graph.add(to_webui); diff --git a/javascript/compute-height.js b/javascript/compute-height.js index 0948641..391d268 100644 --- a/javascript/compute-height.js +++ b/javascript/compute-height.js @@ -90,7 +90,7 @@ function updateFooterStyle() { function getClearEnabledDisplayNamesButtons() { return [ - document.getElementById("script_txt2txt_comfyui_clear_enabled_display_names") ?? null, + document.getElementById("script_txt2img_comfyui_clear_enabled_display_names") ?? document.getElementById("script_txt2txt_comfyui_clear_enabled_display_names") ?? null, document.getElementById("script_img2img_comfyui_clear_enabled_display_names") ?? null, ]; } @@ -125,9 +125,7 @@ function getExtensionDynamicProperty(key) { } function reloadFrameElement(iframeElement) { - oldSrc = iframeElement.src; - iframeElement.src = ''; - iframeElement.src = oldSrc; + iframeElement.src += ""; } function setupIFrame(workflowTypeId) { @@ -138,5 +136,11 @@ function setupIFrame(workflowTypeId) { iframeSearchParams.set("webuiClientId", WEBUI_CLIENT_ID); const iframe = getWorkflowTypeIFrame(workflowTypeId); const base_src = iframe.getAttribute("base_src"); - iframe.src = base_src + "?" + iframeSearchParams.toString(); + const iframe_src = base_src + "?" + iframeSearchParams.toString(); + if (iframe.src !== iframe_src) { + iframe.src = iframe_src; + } + else { + reloadFrameElement(iframe); + } } diff --git a/lib_comfyui/webui/patches.py b/lib_comfyui/webui/patches.py index af89be2..6eebb23 100644 --- a/lib_comfyui/webui/patches.py +++ b/lib_comfyui/webui/patches.py @@ -37,7 +37,7 @@ def watch_prompts(component, **kwargs): attribute = f'last_{"negative" if possible_elem_ids[elem_id] else "positive"}_prompt' for event_listener in event_listeners: getattr(component, event_listener)( - fn = lambda p: setattr(global_state, attribute, p), + fn=lambda p: setattr(global_state, attribute, p), inputs=[component] ) @@ -64,6 +64,15 @@ def create_sampler_hijack(name: str, model, original_function): @ipc.restrict_to_process('webui') def sample_img2img_hijack(p, x, *args, original_function, **kwargs): + from modules import processing + workflow_type = default_workflow_types.preprocess_latent_workflow_type + + if not ( + isinstance(p, processing.StableDiffusionProcessingImg2Img) and + external_code.is_workflow_type_enabled(workflow_type.get_ids("img2img")[0]) + ): + return original_function(p, x, *args, **kwargs) + processed_x = external_code.run_workflow( workflow_type=default_workflow_types.preprocess_latent_workflow_type, tab='img2img', @@ -93,9 +102,14 @@ def patch_processing(p): def p_sample_patch(*args, original_function, is_img2img, **kwargs): x = original_function(*args, **kwargs) + tab = 'img2img' if is_img2img else 'txt2img' + + if not external_code.is_workflow_type_enabled(default_workflow_types.postprocess_latent_workflow_type.get_ids(tab)[0]): + return x + processed_x = external_code.run_workflow( workflow_type=default_workflow_types.postprocess_latent_workflow_type, - tab='img2img' if is_img2img else 'txt2img', + tab=tab, batch_input=type_conversion.webui_latent_to_comfyui(x.to(device='cpu')), identity_on_error=True, ) @@ -104,6 +118,9 @@ def p_sample_patch(*args, original_function, is_img2img, **kwargs): def p_img2img_init(*args, original_function, p_ref, **kwargs): + if not external_code.is_workflow_type_enabled(default_workflow_types.preprocess_workflow_type.get_ids("img2img")[0]): + return original_function(*args, **kwargs) + processed_images = external_code.run_workflow( workflow_type=default_workflow_types.preprocess_workflow_type, tab='img2img', diff --git a/scripts/comfyui.py b/scripts/comfyui.py index dc0de64..44aafa3 100644 --- a/scripts/comfyui.py +++ b/scripts/comfyui.py @@ -54,12 +54,11 @@ def process(self, p, queue_front, enabled_workflow_type_ids, **kwargs): patches.patch_processing(p) def postprocess_batch_list(self, p, pp, *args, **kwargs): - if not getattr(global_state, 'enabled', True): - return - if len(pp.images) == 0: + if not external_code.is_workflow_type_enabled(default_workflow_types.postprocess_workflow_type.get_ids(self.get_tab())[0]): return all_results = [] + p_rescale_factor = 0 for batch_input in extract_contiguous_buckets(pp.images, p.batch_size): batch_results = external_code.run_workflow( workflow_type=default_workflow_types.postprocess_workflow_type, @@ -68,14 +67,16 @@ def postprocess_batch_list(self, p, pp, *args, **kwargs): identity_on_error=True, ) - for list_to_scale in [p.prompts, p.negative_prompts, p.seeds, p.subseeds]: - list_to_scale[:] = list_to_scale * len(batch_results) - + p_rescale_factor += len(batch_results) all_results.extend( image for batch in batch_results for image in type_conversion.comfyui_image_to_webui(batch, return_tensors=True)) + p_rescale_factor = max(1, p_rescale_factor) + for list_to_scale in [p.prompts, p.negative_prompts, p.seeds, p.subseeds]: + list_to_scale[:] = list_to_scale * p_rescale_factor + pp.images.clear() pp.images.extend(all_results) iframe_requests.extend_infotext_with_comfyui_workflows(p, self.get_tab())