Abstract Syntax Trees Evaluated Restricted Run (ASTERR) is a Python Script executor for ComfyUI. [w/Warning:ASTERR runs Python Code from a Web Interface! It is highly recommended to run this in a closed-off environment, as it could have potential security risks.]
Abstract Syntax Trees Evaluated Restricted Run (ASTERR) is a Python Script executor for ComfyUI
[!WARNING] ASTERR runs Python Code from a Web Interface! It is highly recommended to run this in a closed-off environment, as it could have potential security risks.
Clone the reposity to ComfyUI/custom_nodes
and restart ComfyUI if running.
The default configuration specifies a maximum recursion limit of 100 for loops and nested operations. The allowed modules list is empty, and uses the internal default allowed imports.
DEFAULT CONFIG:
{
"recursion_limit": 100,
"allowed_modules": []
}
You can added allowed modules by their name, and optionally plus their submodule. For exmaple to allow PIL import and it's submodules you could either do
"allowed_modules": ["PIL", "PIL.Image", "PIL.ImageFilter"]
And so on, or you could do
"allowed_modules": ["PIL.*"]
To live dangerously and allow any imports like a og boss, you can use:
"allowed_modules": ["*"]
ASTERR Script
Nodescript
(STRING
): The script to process. Can be converted to input to provide custom text string input.trigger_run_01
(INT
): 0
or 1
INT
that defines whether the script should run or not.a
through k
(*
): Arbitrary input (STRING
, INT
, FLOAT
, IMAGE
, MODEL
, etc) to pass as a variable to the execution namespace.[!WARNING] Be sure to expect and handle the data you input. If
a
is aIMAGE
tensor input, we need to handle the batched tensor ASTERR will receive accordingly.
preset_script
(COMBO
): List of .py
scripts located in ASTERR/scripts
for preset execution. This will override the script
input.always_run
(COMBO
): false
or true
on whether to always run the script (similar to trigger on run, but a constant state). If false, it will only run when a change has been made.prmpt
and extra_pnginfo
vars which can be used to investigate, fetch data. In the case of extra_pnginfo
you can overwrite the variable with an updated version of the extra_pnginfo
(dict
) to return with the node to the executor.Save ASTERR Script
NodeSave a ASTERR script which would then be available under ASTERR/scripts
and the preset_scripts
menu in the ASTERR Script node.
script_string
(STRING
): Script content string input. This string is saved to a python script file under ASTERR/scripts
script_name
(STRING
): Script name to use, does not include the extension.overwrite_script
(COMBO
): false
or true
on whether to overwrite the script that already exists on disk.Preset scripts allow you to pre-define functions to pick from and run any time. Scripts are saved a .py
files (so editing is familiar).
asterr_result
var can be used to define the result to return to the node.extra_pnginfo
can be used and overwritten to return edited extra_pnginfoa
(IMAGE
) propotionally with b
(INT
) as max size of the result.# Inside functions, we must import our modules as they are scoped from the main script
# tensor2pil() and pil2tensor() are built-in methods to help with `IMAGE` input
# a = image (tensor batched image)
# b = max size (INT)
def resizeImage(image, max_size):
import PIL
width, height = image.size
new_width, new_height = width, height
if width > max_size or height > max_size:
ratio = min(max_size / width, max_size / height)
new_width = int(width * ratio)
new_height = int(height * ratio)
elif max_size > max(width, height):
ratio = max_size / max(width, height)
new_width = int(width * ratio)
new_height = int(height * ratio)
resized_image = image.resize((new_width, new_height))
return resized_image
# We define the result to return to the node with the `asterr_result` var
asterr_result = pil2tensor(resizeImage(tensor2pil(a), b))