code: def exec_with_return(code, module):
      """
      like exec() but can return values
      https://stackoverflow.com/a/52361938/5862977
      """
      code_ast = ast.parse(code)
  
      init_ast = copy.deepcopy(code_ast)
      init_ast.body = code_ast.body[:-1]
  
      last_ast = copy.deepcopy(code_ast)
      last_ast.body = code_ast.body[-1:]
  
      exec(compile(init_ast, "<ast>", "exec"), module.__dict__)
      if type(last_ast.body[0]) == ast.Expr:
          return eval(
              compile(
                  convertExpr2Expression(last_ast.body[0]),
                  "<ast>",
                  "eval",
              ),
              module.__dict__,
          )
      else:
          exec(compile(last_ast, "<ast>", "exec"), module.__dict__)
  
file_path: stable-diffusion-webui/scripts/custom_code.py
imports: import modules.scripts
  import gradio
  import ast
  import copy
  from modules.processing import Processed
  from modules.shared import cmd_opts
label_desc: Use image node_id 2 for calling a global function with example usage: exec_with_return(code, module) and returns: eval