Skip to content

Commit

Permalink
fix patches
Browse files Browse the repository at this point in the history
  • Loading branch information
ljleb committed Aug 31, 2023
1 parent e6e7daf commit 33ea102
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 9 deletions.
8 changes: 7 additions & 1 deletion javascript/compute-height.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,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);
}
}
24 changes: 22 additions & 2 deletions lib_comfyui/webui/patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
)

Expand All @@ -64,6 +64,16 @@ 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)

print('preprocess_latent')
processed_x = external_code.run_workflow(
workflow_type=default_workflow_types.preprocess_latent_workflow_type,
tab='img2img',
Expand Down Expand Up @@ -93,9 +103,15 @@ 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

print('postprocess_latent')
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,
)
Expand All @@ -104,6 +120,10 @@ 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)

print('preprocess')
processed_images = external_code.run_workflow(
workflow_type=default_workflow_types.preprocess_workflow_type,
tab='img2img',
Expand Down
17 changes: 11 additions & 6 deletions scripts/comfyui.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,15 @@ 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 (
getattr(global_state, 'enabled', True) and
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
print('postprocess')
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,
Expand All @@ -68,14 +71,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())
Expand Down

0 comments on commit 33ea102

Please sign in to comment.