diff --git a/lib_comfyui/webui/workflow_patcher.py b/lib_comfyui/webui/workflow_patcher.py
index 8f4ecd5..00eb064 100644
--- a/lib_comfyui/webui/workflow_patcher.py
+++ b/lib_comfyui/webui/workflow_patcher.py
@@ -33,14 +33,12 @@ def create_sampler_hijack(name: str, model, original_function):
@ipc.restrict_to_process('webui')
def sample_img2img_hijack(p, x, *args, original_function, **kwargs):
- if getattr(global_state, 'enabled', True):
- preprocessed_x = external_code.run_workflow(
- workflow_type=default_workflow_types.preprocess_latent_workflow_type,
- tab='img2img',
- batch_input=x.to(device='cpu'),
- )
- x = torch.stack(preprocessed_x).to(device=x.device) if isinstance(preprocessed_x, list) else preprocessed_x.to(device=x.device)
-
+ processed_x = external_code.run_workflow(
+ workflow_type=default_workflow_types.preprocess_latent_workflow_type,
+ tab='img2img',
+ batch_input=x.to(device='cpu'),
+ )
+ x = torch.stack(processed_x).to(device=x.device) if isinstance(processed_x, list) else processed_x.to(device=x.device)
return original_function(p, x, *args, **kwargs)
@@ -62,15 +60,12 @@ def patch_processing(p):
def p_sample_patch(*args, original_function, is_img2img, **kwargs):
x = original_function(*args, **kwargs)
- if getattr(global_state, 'enabled', True):
- postprocessed_x = external_code.run_workflow(
- workflow_type=default_workflow_types.postprocess_latent_workflow_type,
- tab='img2img' if is_img2img else 'txt2img',
- batch_input=x.to(device='cpu'),
- )
- x = torch.stack(postprocessed_x).to(device=x.device) if isinstance(postprocessed_x, list) else postprocessed_x.to(device=x.device)
-
- return x
+ processed_x = external_code.run_workflow(
+ workflow_type=default_workflow_types.postprocess_latent_workflow_type,
+ tab='img2img' if is_img2img else 'txt2img',
+ batch_input=x.to(device='cpu'),
+ )
+ return torch.stack(processed_x).to(device=x.device) if isinstance(processed_x, list) else processed_x.to(device=x.device)
def p_img2img_init(*args, original_function, p_ref, **kwargs):
@@ -80,5 +75,4 @@ def p_img2img_init(*args, original_function, p_ref, **kwargs):
batch_input=[F.pil_to_tensor(image) / 255 for image in p_ref.init_images],
)
p_ref.init_images = [F.to_pil_image(image_tensor) for image_tensor in preprocessed_images]
-
return original_function(*args, **kwargs)
diff --git a/scripts/comfyui.py b/scripts/comfyui.py
index 0aa34ad..9e5a8d1 100644
--- a/scripts/comfyui.py
+++ b/scripts/comfyui.py
@@ -22,7 +22,7 @@ def show(self, is_img2img):
def ui(self, is_img2img):
global_state.is_ui_instantiated = True
- with gr.Accordion(f"ComfyUI", open=False, elem_id=self.elem_id('accordion')):
+ with gr.Accordion(f"ComfyUI", open=False, elem_id=self.elem_id('accordion')) as accordion:
return self.get_alwayson_ui(is_img2img)
def get_alwayson_ui(self, is_img2img: bool):
@@ -35,23 +35,22 @@ def get_alwayson_ui(self, is_img2img: bool):
for workflow_type in workflow_types
}
- current_workflow_type_id = gr.Text(
+ current_workflow_type_id = gr.HTML(
value=workflow_type_ids[first_workflow_type.display_name],
visible=False,
interactive=False,
)
- enabled_display_names_json = gr.Textbox(
+
+ enabled_display_names_json = gr.HTML(
json.dumps([]),
visible=False,
interactive=False,
)
with gr.Row():
- queue_front = gr.Checkbox(
- label='Queue front',
- elem_id=self.elem_id('queue_front'),
- value=True,
- )
+ gr.HTML(value=self.get_iframes_html(is_img2img, workflow_type_ids[first_workflow_type.display_name]))
+
+ with gr.Row():
enable = gr.Checkbox(
label='Enable',
elem_id=self.elem_id('enabled'),
@@ -64,68 +63,17 @@ def get_alwayson_ui(self, is_img2img: bool):
value=first_workflow_type.display_name,
elem_id=self.elem_id('displayed_workflow_type'),
)
- current_workflow_display_name.change(
- fn=workflow_type_ids.get,
- inputs=[current_workflow_display_name],
- outputs=[current_workflow_type_id],
- )
- current_workflow_type_id.change(
- fn=None,
- _js='changeDisplayedWorkflowType',
- inputs=[current_workflow_type_id],
- )
- current_workflow_display_name.change(
- fn=lambda current_workflow_display_name, enabled_display_names_json: current_workflow_display_name in json.loads(enabled_display_names_json),
- inputs=[current_workflow_display_name, enabled_display_names_json],
- outputs=[enable],
- )
- enable.select(
- fn=lambda current_workflow_display_name, enabled_display_names_json, enable: json.dumps(list(
- (set(json.loads(enabled_display_names_json)) | {current_workflow_display_name})
- if enable
- else (set(json.loads(enabled_display_names_json)) - {current_workflow_display_name})
- )),
- inputs=[current_workflow_display_name, enabled_display_names_json, enable],
- outputs=[enabled_display_names_json]
- )
- enable_style = gr.HTML()
- for comp in [current_workflow_display_name, enabled_display_names_json]:
- comp.change(
- fn=lambda enabled_display_names_json, current_workflow_display_name: f'''''',
- inputs=[enabled_display_names_json, current_workflow_display_name],
- outputs=[enable_style],
- )
-
- def update_enabled_workflow_type_ids(enabled_display_names_json):
- enabled_display_names = json.loads(enabled_display_names_json)
- if not hasattr(global_state, 'enabled_workflow_type_ids'):
- global_state.enabled_workflow_type_ids = {}
-
- enabled_workflow_type_ids = {
- workflow_type_ids[workflow_type.display_name]: workflow_type.display_name in enabled_display_names
- for workflow_type in workflow_types
- }
- global_state.enabled_workflow_type_ids.update(enabled_workflow_type_ids)
-
- enabled_display_names_json.change(
- fn=update_enabled_workflow_type_ids,
- inputs=[enabled_display_names_json],
- )
with gr.Row():
- gr.HTML(value=self.get_iframes_html(is_img2img, workflow_type_ids[first_workflow_type.display_name]))
+ queue_front = gr.Checkbox(
+ label='Queue front',
+ elem_id=self.elem_id('queue_front'),
+ value=True,
+ )
with gr.Row():
refresh_button = gr.Button(
- value=f'{ui.refresh_symbol} Reload ComfyUI interface (client side)',
+ value=f'{ui.refresh_symbol} Reload ComfyUI interfaces (client side)',
elem_id=self.elem_id('refresh_button'),
)
refresh_button.click(
@@ -133,6 +81,63 @@ def update_enabled_workflow_type_ids(enabled_display_names_json):
_js='reloadComfyuiIFrames'
)
+ current_workflow_display_name.change(
+ fn=workflow_type_ids.get,
+ inputs=[current_workflow_display_name],
+ outputs=[current_workflow_type_id],
+ )
+ current_workflow_type_id.change(
+ fn=None,
+ _js='changeDisplayedWorkflowType',
+ inputs=[current_workflow_type_id],
+ )
+ current_workflow_display_name.change(
+ fn=lambda current_workflow_display_name, enabled_display_names_json: current_workflow_display_name in json.loads(enabled_display_names_json),
+ inputs=[current_workflow_display_name, enabled_display_names_json],
+ outputs=[enable],
+ )
+ enable.select(
+ fn=lambda current_workflow_display_name, enabled_display_names_json, enable: json.dumps(list(
+ (set(json.loads(enabled_display_names_json)) | {current_workflow_display_name})
+ if enable
+ else (set(json.loads(enabled_display_names_json)) - {current_workflow_display_name})
+ )),
+ inputs=[current_workflow_display_name, enabled_display_names_json, enable],
+ outputs=[enabled_display_names_json]
+ )
+ enable_style = gr.HTML()
+ for comp in [current_workflow_display_name, enabled_display_names_json]:
+ comp.change(
+ fn=lambda enabled_display_names_json, current_workflow_display_name: f'''''',
+ inputs=[enabled_display_names_json, current_workflow_display_name],
+ outputs=[enable_style],
+ )
+
+ def update_enabled_workflow_type_ids(enabled_display_names_json):
+ enabled_display_names = json.loads(enabled_display_names_json)
+ if not hasattr(global_state, 'enabled_workflow_type_ids'):
+ global_state.enabled_workflow_type_ids = {}
+
+ enabled_workflow_type_ids = {
+ workflow_type_ids[workflow_type.display_name]: workflow_type.display_name in enabled_display_names
+ for workflow_type in workflow_types
+ }
+ global_state.enabled_workflow_type_ids.update(enabled_workflow_type_ids)
+
+ enabled_display_names_json.change(
+ fn=update_enabled_workflow_type_ids,
+ inputs=[enabled_display_names_json],
+ )
+
self.setup_infotext_updates(workflow_types, xxx2img)
return queue_front,
diff --git a/style.css b/style.css
index a313218..93aed80 100644
--- a/style.css
+++ b/style.css
@@ -24,7 +24,7 @@ iframe.comfyui-embedded-widget-display {
}
#script_txt2txt_comfyui_refresh_button {
- max-width: 20em;
- min-width: 20em;
+ max-width: 25em;
+ min-width: 25em;
height: 2.4em;
}