From 4f9c3ed310e326fe98cb7caf96a308de42fd2566 Mon Sep 17 00:00:00 2001 From: Tasha Upchurch Date: Wed, 14 Jun 2023 16:00:50 -0400 Subject: [PATCH] better functional integration --- functional.py | 22 ++++++++++++++++------ image.py | 14 ++++---------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/functional.py b/functional.py index 7ae153e..1ce9f45 100644 --- a/functional.py +++ b/functional.py @@ -1,5 +1,6 @@ import hashlib +_list = {"list": ("LIST",)} _func = {"func": ("FUNC",)} _text = {"code": ("STRING", {"multiline": True, "default": "y=x()"})} @@ -44,10 +45,13 @@ class FuncRender: @classmethod def INPUT_TYPES(cls): - use = required(both(_func, _text)) + use = both( + required( + both(_func, _text)), + optional(_list) + ) return use - - RETURN_TYPES = ("FLOAT", "STRING", "INT",) + RETURN_TYPES = ("FLOAT", "STRING", "INT", "LIST") FUNCTION = "func" CATEGORY = "ETK/func" @@ -69,7 +73,7 @@ class FuncRender: self.globals = globals self.locals = locals - return (locals["y_float"], locals["y_string"], locals["y_int"],) + return (locals["y_float"], locals["y_string"], locals["y_int"],locals["y_list"],) class FuncRenderImage: @@ -80,17 +84,23 @@ class FuncRenderImage: @classmethod def INPUT_TYPES(cls): - use = required(both(_func, _text)) + use = both( + required( + both(_func, _text)), + optional(_list) + ) return use RETURN_TYPES = ("IMAGE",) FUNCTION = "func" CATEGORY = "ETK/func" + OUTPUT_NODE = True - def func(self, func: callable, code): + def func(self, func, code, **kwargs): globals = self.globals locals = self.locals locals["x"] = func + locals["x_list"] = kwargs.get("list", None) # code should do something like: # func like : lambda x:["what"]*x # code like : 'f=[x for x in x(2)]' diff --git a/image.py b/image.py index a9634f1..fe417f0 100644 --- a/image.py +++ b/image.py @@ -274,16 +274,10 @@ class TinyTxtToImg: image = VAEDecode.decode(None, self.vae, samples)[0] image = image.detach().cpu() - - return (image, lambda: self.tinytxt2img(prompt, - neg_prompt, - name, - overrides, - clip_encoder, - token_normalization, - weight_interpretation, - FUNC - ) + self.FUNC = TinyTxtToImg.tinytxt2img + self.ARGS = (prompt, neg_prompt, name, overrides, clip_encoder, token_normalization, weight_interpretation, FUNC) + return (image, + self ,)