Add text filter with extras

This commit is contained in:
Chris
2025-01-30 16:32:37 +11:00
parent a36a74ee7b
commit 490a558003
3 changed files with 49 additions and 2 deletions
+2 -1
View File
@@ -5,7 +5,7 @@
@description: A custom node that pauses the flow while you choose which image or images to pass on to the rest of the workflow. Simplified and improved version of cg-image-picker.
"""
from .image_filter import ImageFilter, TextImageFilter, MaskImageFilter
from .image_filter import ImageFilter, TextImageFilter, MaskImageFilter, TextImageFilterWithExtras
VERSION = "1.0.1"
WEB_DIRECTORY = "./js"
@@ -13,6 +13,7 @@ WEB_DIRECTORY = "./js"
NODE_CLASS_MAPPINGS= {
"Image Filter": ImageFilter,
"Text Image Filter": TextImageFilter,
"Text Image Filter with Extras": TextImageFilterWithExtras,
"Mask Image Filter": MaskImageFilter
}
+34
View File
@@ -114,6 +114,40 @@ class TextImageFilter(PreviewImage):
return (image, response)
class TextImageFilterWithExtras(PreviewImage):
RETURN_TYPES = ("IMAGE","STRING","STRING","STRING","STRING")
RETURN_NAMES = ("image","text","extra1","extra2","extra3")
FUNCTION = "func"
CATEGORY = "image_filter"
OUTPUT_NODE = False
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"image" : ("IMAGE", ),
"text" : ("STRING", {"default":""}),
"extra1" : ("STRING", {"default":""}),
"extra2" : ("STRING", {"default":""}),
"extra3" : ("STRING", {"default":""}),
"timeout": ("INT", {"default": 60, "tooltip": "Timeout in seconds."}),
},
"hidden": HIDDEN,
}
@classmethod
def IS_CHANGED(cls, **kwargs):
return float("NaN")
def func(self, image, text, extra1, extra2, extra3, timeout, uid, **kwargs):
urls:list[str] = self.save_images(images=image, **kwargs)['ui']['images']
PromptServer.instance.send_sync("cg-image-filter-images", {"uid": uid, "urls":urls, "text":text, "extras":[extra1, extra2, extra3]})
response = wait(timeout)
response = response.split(",") if response else [""]*4
return (image, *response)
class MaskImageFilter(PreviewImage, LoadImage):
RETURN_TYPES = ("IMAGE","MASK")
RETURN_NAMES = ("image","mask")
+13 -1
View File
@@ -18,6 +18,7 @@ class Popup extends HTMLSpanElement {
this.click_sends_label = create('label', 'control_text', this.click_sends_pane, {for:"click_sends", innerText:"click to send"})
this.send_button = create('button', 'control', this.buttons, {innerText:"Send (S)"} )
this.cancel_button = create('button', 'control', this.buttons, {innerText:"Cancel (X)"} )
this.extras = create('span', 'extras', this.buttons)
this.send_button.addEventListener( 'click', this.send_current_state.bind(this) )
this.cancel_button.addEventListener('click', this.send_cancel.bind(this) )
@@ -29,7 +30,12 @@ class Popup extends HTMLSpanElement {
_send_response(msg) {
const body = new FormData();
body.append('response', msg);
var response = msg
if (this.n_extras) {
response = [response]
Array.from(this.extras.children).forEach((e)=>{ response.push(e.value) })
}
body.append('response', response);
api.fetchApi("/cg-image-filter-message", { method: "POST", body, });
this.close()
}
@@ -84,6 +90,12 @@ class Popup extends HTMLSpanElement {
}
handle_urls(detail) {
this.n_extras = detail.extras ? detail.extras.length : 0
this.extras.innerHTML = ''
for (let i=0; i<this.n_extras; i++) {
const extra = create('input', 'extra', this.extras, {value:detail.extras[i]})
}
this.doing_text = (detail.text != null)
this.n_images = detail.urls?.length