code: def textgenrnn_generate(
      model,
      vocab,
      indices_char,
      temperature=0.5,
      maxlen=40,
      meta_token="<s>",
      word_level=False,
      single_text=False,
      max_gen_length=300,
      interactive=False,
      top_n=3,
      prefix=None,
      synthesize=False,
      stop_tokens=[" ", "\n"],
  ):
      """
      Generates and returns a single text.
      """
  
      collapse_char = " " if word_level else ""
      end = False
  
      # If generating word level, must add spaces around each punctuation.
      # https://stackoverflow.com/a/3645946/9314418
      if word_level and prefix:
          punct = "!\"#$%&()*+,-./:;<=>?@[\]^_`{|}~\\n\\t'‘’“”’–—"
          prefix = re.sub("([{}])".format(punct), r" \1 ", prefix)
          prefix = re.sub(" {2,}", r" ", prefix)
          prefix_t = [x.lower() for x in prefix.split(" ")]
  
      if not word_level and prefix:
          prefix_t = list(prefix)
  
      if single_text:
          text = prefix_t if prefix else [""]
          max_gen_length += maxlen
      else:
          text = [meta_token] + prefix_t if prefix else [meta_token]
  
      if not isinstance(temperature, list):
          temperature = [temperature]
  
      if len(model.inputs) > 1:
          model = Model(
              inputs=model.inputs[0], outputs=model.outputs[1]
          )
  
      while not end and len(text) < max_gen_length:
          encoded_text = textgenrnn_encode_sequence(
              text[-maxlen:], vocab, maxlen
          )
          next_temperature = temperature[
              (len(text) - 1) % len(temperature)
          ]
  
          if not interactive:
              # auto-generate text without user intervention
              next_index = textgenrnn_sample(
                  model.predict(encoded_text, batch_size=1)[0],
                  next_temperature,
              )
              next_char = indices_char[next_index]
              text += [next_char]
              if next_char == meta_token or len(text) >= max_gen_length:
                  end = True
              gen_break = (
                  next_char in stop_tokens
                  or word_level
                  or len(stop_tokens) == 0
              )
              if synthesize and gen_break:
                  break
          else:
              # ask user what the next char/word should be
              options_index = textgenrnn_sample(
                  model.predict(encoded_text, batch_size=1)[0],
                  next_temperature,
                  interactive=interactive,
                  top_n=top_n,
              )
              options = [indices_char[idx] for idx in options_index]
              print(
                  "Controls:\n\ts: stop.\tx: backspace.\to: write your own."
              )
              print("\nOptions:")
  
              for i, option in enumerate(options, 1):
                  print("\t{}: {}".format(i, option))
  
              print(
                  "\nProgress: {}".format(collapse_char.join(text)[3:])
              )
              print("\nYour choice?")
              user_input = input("> ")
  
              try:
                  user_input = int(user_input)
                  next_char = options[user_input - 1]
                  text += [next_char]
              except ValueError:
                  if user_input == "s":
                      next_char = "<s>"
                      text += [next_char]
                  elif user_input == "o":
                      other = input("> ")
                      text += [other]
                  elif user_input == "x":
                      try:
                          del text[-1]
                      except IndexError:
                          pass
                  else:
                      print("That's not an option!")
  
      # if single text, ignore sequences generated w/ padding
      # if not single text, remove the <s> meta_tokens
      if single_text:
          text = text[maxlen:]
      else:
          text = text[1:]
          if meta_token in text:
              text.remove(meta_token)
  
      text_joined = collapse_char.join(text)
  
      # If word level, remove spaces around punctuation for cleanliness.
      if word_level:
          left_punct = "!%),.:;?@\]_}\\n\\t'"
          right_punct = "$(\[_\\n\\t'"
          punct = "\\n\\t"
  
          text_joined = re.sub(
              " ([{}]) ".format(punct), r"\1", text_joined
          )
          text_joined = re.sub(
              " ([{}])".format(left_punct), r"\1", text_joined
          )
          text_joined = re.sub(
              "([{}]) ".format(right_punct), r"\1", text_joined
          )
          text_joined = re.sub('" (.+?) "', r'"\1"', text_joined)
  
      return text_joined, end
  
imports: import csv
  import re
  from random import shuffle
  import numpy
  from tensorflow.keras import backend
  from tensorflow.keras.callbacks import Callback
  from tensorflow.keras.models import Model
  from tensorflow.keras.preprocessing import sequence
  from tqdm import trange
label_desc: Use image node_id 2 for calling a global function with example usage: textgenrnn_generate(model, vocab, indices_char, temperature, maxlen, meta_token, word_level, single_text, max_gen_length, interactive, top_n, prefix, synthesize, stop_tokens) and returns: text_joined,  end