added title, latent and masks, and ontimeout options
This commit is contained in:
@@ -31,8 +31,5 @@ If you do nothing, and the number of seconds specified in the timeout is exceede
|
||||
|
||||
## Future plans
|
||||
|
||||
- allow a choice on timeout of 'cancel' or 'pass all'
|
||||
- add a title (showing the title of the node)
|
||||
- add optional Latent and Mask inputs and outputs so that latents or masks associated with the images can also be filtered
|
||||
- a node that takes a single image as input, and when executed, activates the mask editor, then outputs an image and the on-the-fly mask
|
||||
- a node that takes an image and a string, and allows you to edit the string before passing it on
|
||||
+15
-6
@@ -20,8 +20,8 @@ async def cg_image_filter_message(request):
|
||||
return web.json_response({})
|
||||
|
||||
class ImageFilter(PreviewImage):
|
||||
RETURN_TYPES = ("IMAGE",)
|
||||
RETURN_NAMES = ("images",)
|
||||
RETURN_TYPES = ("IMAGE","LATENT","MASK")
|
||||
RETURN_NAMES = ("images","latents","masks")
|
||||
FUNCTION = "func"
|
||||
CATEGORY = "image_filter"
|
||||
OUTPUT_NODE = False
|
||||
@@ -33,7 +33,12 @@ class ImageFilter(PreviewImage):
|
||||
return {
|
||||
"required": {
|
||||
"images" : ("IMAGE", ),
|
||||
"timeout": ("INT", {"default": 60, "tooltip": "Timeout in seconds before all images are passed on."}),
|
||||
"timeout": ("INT", {"default": 60, "tooltip": "Timeout in seconds."}),
|
||||
"ontimeout": (["send none", "send all"]),
|
||||
},
|
||||
"optional": {
|
||||
"latents" : ("LATENT", {"tooltip": "Optional - if provided, will be output"}),
|
||||
"masks" : ("MASK", {"tooltip": "Optional - if provided, will be output"}),
|
||||
},
|
||||
"hidden": {
|
||||
"prompt": "PROMPT",
|
||||
@@ -46,18 +51,22 @@ class ImageFilter(PreviewImage):
|
||||
def IS_CHANGED(cls, **kwargs):
|
||||
return float("NaN")
|
||||
|
||||
def func(self, images, timeout, uid, **kwargs):
|
||||
def func(self, images, timeout, ontimeout, uid, latents=None, masks=None, **kwargs):
|
||||
urls:list[str] = self.save_images(images=images, **kwargs)['ui']['images']
|
||||
PromptServer.instance.send_sync("cg-image-filter-images", {"uid": uid, "urls":urls})
|
||||
|
||||
ImageFilter.data = None
|
||||
end_time = time.monotonic() + timeout
|
||||
while(time.monotonic() < end_time and ImageFilter.data is None): time.sleep(1)
|
||||
response = ImageFilter.data or ''
|
||||
response = ImageFilter.data or ('' if ontimeout=='send none' else ",".join(list(str(x) for x in range(len(images)))))
|
||||
ImageFilter.data = None
|
||||
|
||||
images_to_return = list(int(x) for x in response.split(",") if x)
|
||||
|
||||
if len(images_to_return) == 0: raise InterruptProcessingException()
|
||||
|
||||
images = torch.stack(list(images[i] for i in images_to_return))
|
||||
latents = {"samples": torch.stack(list(latents['samples'][i] for i in images_to_return))} if latents is not None else None
|
||||
masks = torch.stack(list(masks[i] for i in images_to_return)) if masks is not None else None
|
||||
|
||||
return (torch.stack(list(images[i] for i in images_to_return)), )
|
||||
return (images, latents, masks)
|
||||
@@ -12,6 +12,15 @@
|
||||
left:5%;
|
||||
height:90%;
|
||||
top:5%;
|
||||
display: grid;
|
||||
align-content: space-evenly;
|
||||
}
|
||||
|
||||
.cg_popup .title {
|
||||
position: absolute;
|
||||
left: 40%;
|
||||
top: 2%;
|
||||
font-size: larger;
|
||||
}
|
||||
|
||||
.cg_popup .buttons {
|
||||
|
||||
@@ -35,10 +35,12 @@ var click_sends = null
|
||||
var send_button = null
|
||||
var cancel_button = null
|
||||
var active = false
|
||||
var title_bar = null
|
||||
|
||||
function create_popup() {
|
||||
popup = create('span', 'cg_popup hidden', document.body)
|
||||
const grid = create('span', 'grid', popup)
|
||||
title_bar = create('span', 'title', popup)
|
||||
const buttons = create('span', 'buttons', popup)
|
||||
click_sends = create('input', 'control', buttons, {type:"checkbox", id:"click_sends"})
|
||||
create('label', 'control_text', buttons, {for:"click_sends", innerText:"click to send"})
|
||||
@@ -112,6 +114,7 @@ function receive_images(details) {
|
||||
if (app.graph._nodes_by_id[detail.uid].type=="Image Filter") {
|
||||
active = true
|
||||
if (!popup) create_popup()
|
||||
title_bar.innerText = app.graph._nodes_by_id[detail.uid].title ?? "Image Filter"
|
||||
|
||||
picked.clear()
|
||||
if (detail.urls.length==1) picked.add('0')
|
||||
|
||||
Reference in New Issue
Block a user