code: def get_text_input_js_callback(
      data_source: models.ColumnDataSource, legend: widgets.Div
  ) -> callbacks.CustomJS:
      """Creates the CustomJS callback that will be triggered upon query entry.
  
      The JavaScript callback in turn calls back to Python, specifically to a
      function with the name specified by TEXT_INPUT_PY_CALLBACK_NAME, via
      google.colab.kernel.invokeFunction. The Python callback should return a
      color_updates data structure consisting of a list of (box_index, hex_color)
      tuples.
  
      Args:
        data_source: Bokeh ColumnDataSource linked to bounding boxes. Must contain a
          field called "colors".
        legend: Div widget that will contain the query legend.
  
      Returns:
        Bokeh CustomJS callback object.
      """
      return callbacks.CustomJS(
          args=dict(data_source=data_source, legend=legend),
          code="""
            (async function() {
              const input = cb_obj.value_input.replace(/[^a-zA-Z0-9 ,_-]/g, '');
              const result = await google.colab.kernel.invokeFunction(
                '"""
          + TEXT_INPUT_PY_CALLBACK_NAME
          + """', [input], {});
              var result_text = result['data']['text/plain']
              // Need to strip enclosing quotes since invokeFunction returns str:
              result_text = result_text.substring(1, result_text.length-1);
              const result_json = JSON.parse(result_text);
  
              const color_updates = result_json['color_updates']
              const colors = data_source.data['colors']
              for (let i = 0; i < color_updates.length; i++) {
                    // Element 0 is the box index, element 1 is the hex color:
                    colors[color_updates[i][0]] = color_updates[i][1]
                }
              data_source.change.emit();
              legend.text = atob(result_json['legend_text_b64'])
            })();
            """,
      )
  
imports: import base64
  import functools
  import json
  from typing import Any, Mapping, Union
  from bokeh import models
  from bokeh.models import callbacks
  from bokeh.models import widgets
  import matplotlib
  import matplotlib.pyplot
  import numpy
  from scenic.model_lib.base_models import box_utils
  from scenic.projects.owl_vit.notebooks import inference
label_desc: Use image node_id 4 for calling a global function with example usage: get_text_input_js_callback(data_source, legend) and returns: callbacks