code: def substitute_template(template, values):
      """Instantiate a kernel template using `values`."""
      text = template
      changed = True
      while changed:
          changed = False
          for key, value in values.items():
              regex = f"\\$\\{{{key}\\}}"
              newtext = re.sub(regex, value, text)
              if newtext != text:
                  changed = True
              text = newtext
      return text
  
imports: import re
  import enum
  from enum import auto
label_desc: Use image node_id 1 for calling a global function with example usage: substitute_template(template, values) and returns: text