code: def _image_conditioning_py_callback(
      geometry_dict: Mapping[str, Union[float, str]],
      *,
      model: inference.Model,
      query_image: np.ndarray,
      target_image: np.ndarray,
  ) -> str:
      """Updates image conditioning predictions when box is drawn."""
      # Note: Bokeh's y coords are swapped compared to TensorFlow:
      box = (
          geometry_dict["y1"],
          geometry_dict["x0"],
          geometry_dict["y0"],
          geometry_dict["x1"],
      )
      query_embedding, best_box_ind = model.embed_image_query(
          query_image, box
      )
      _, _, query_image_boxes = model.embed_image(query_image)
  
      # TODO(mjlm): Implement multi-query image-conditioned detection.
      num_queries = 1
      top_query_ind, scores = model.get_scores(
          target_image, query_embedding[None, ...], num_queries=1
      )
  
      # Apply non-maximum suppression:
      if IMAGE_COND_NMS_IOU_THRESHOLD < 1.0:
          _, _, target_image_boxes = model.embed_image(target_image)
          target_boxes_yxyx = box_utils.box_cxcywh_to_yxyx(
              target_image_boxes, np
          )
          for i in np.argsort(-scores):
              if not scores[i]:
                  # This box is already suppressed, continue:
                  continue
              ious = box_utils.box_iou(
                  target_boxes_yxyx[None, [i], :],
                  target_boxes_yxyx[None, :, :],
                  np_backbone=np,
              )[0][0, 0]
              ious[i] = -1.0  # Mask self-IoU.
              scores[ious > IMAGE_COND_NMS_IOU_THRESHOLD] = 0.0
  
      # Compute box display alphas based on prediction scores:
      alphas = np.zeros_like(scores)
      for i in range(num_queries):
          # Select scores for boxes matching the current query:
          query_mask = top_query_ind == i
          query_scores = scores[query_mask]
          if not query_scores.size:
              continue
  
          # Box alpha is scaled such that the best box for a query has alpha 1.0 and
          # the worst box for which this query is still the top query has alpha 0.1.
          # All other boxes will either belong to a different query, or will not be
          # shown.
          max_score = np.max(query_scores) + 1e-6
          query_alphas = (query_scores - (max_score * 0.1)) / (
              max_score * 0.9
          )
          query_alphas[query_alphas < IMAGE_COND_MIN_CONF] = 0.0
          query_alphas = np.clip(query_alphas, 0.0, 1.0)
          alphas[query_mask] = query_alphas
  
      # Construct color_updates structure for Bokeh:
      color_updates = []
      for i, (query_ind, alpha) in enumerate(
          zip(top_query_ind, alphas)
      ):
          color_updates.append(
              (i, _get_query_color(query_ind, float(alpha)))
          )
  
      cx, cy, w, h = (float(c) for c in query_image_boxes[best_box_ind])
      selected_box = {"x": cx, "y": cy, "w": w, "h": h}
  
      return json.dumps(
          {
              "color_updates": color_updates,
              "selected_box": selected_box,
          }
      )
  
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 5 for calling a global function with example usage: _image_conditioning_py_callback(geometry_dict) and returns: json