code: def handler(context, event):
      context.logger.info(f"Run model: {context.user_data.model}")
      data = event.body
  
      image = Image.open(io.BytesIO(base64.b64decode(data["image"])))
      image_np = np.asarray(image.convert("RGB"), dtype=np.uint8)
  
      flip_image = strtobool(
          os.environ.get("MONAI_LABEL_FLIP_INPUT_IMAGE", "true")
      )
      flip_points = strtobool(
          os.environ.get("MONAI_LABEL_FLIP_INPUT_POINTS", "true")
      )
      flip_output = strtobool(
          os.environ.get("MONAI_LABEL_FLIP_OUTPUT_POINTS", "false")
      )
  
      if flip_image:
          image_np = np.moveaxis(image_np, 0, 1)
  
      pos_points = data.get("pos_points")
      neg_points = data.get("neg_points")
      if flip_points:
          foreground = (
              np.flip(np.array(pos_points, int), 1).tolist()
              if pos_points
              else pos_points
          )
          background = (
              np.flip(np.array(neg_points, int), 1).tolist()
              if neg_points
              else neg_points
          )
      else:
          foreground = (
              np.array(pos_points, int).tolist()
              if pos_points
              else pos_points
          )
          background = (
              np.array(neg_points, int).tolist()
              if neg_points
              else neg_points
          )
  
      context.logger.info(
          f"Image: {image_np.shape}; Foreground: {foreground}; Background: {background}"
      )
  
      json_data = context.user_data.model_handler.infer(
          request={
              "model": context.user_data.model,
              "image": image_np,
              "foreground": foreground,
              "background": background,
              "output": "json",
          }
      )
  
      results = []
      prediction = json_data["params"].get("prediction")
      if prediction:
          context.logger.info(
              f"(Classification) Prediction: {prediction}"
          )
  
          # CVAT Limitation:: tag is not yet supported https://github.com/opencv/cvat/issues/4212
          # CVAT Limitation:: select highest score and create bbox to represent as tag
          e = None
          for element in prediction:
              if element["score"] > 0:
                  e = (
                      element
                      if e is None or element["score"] > e["score"]
                      else e
                  )
                  context.logger.info(f"New Max Element: {e}")
  
          context.logger.info(f"Final Element with Max Score: {e}")
          if e:
              results.append(
                  {
                      "label": e["label"],
                      "confidence": e["score"],
                      "type": "rectangle",
                      "points": [
                          0,
                          0,
                          image_np.shape[0] - 1,
                          image_np.shape[1] - 1,
                      ],
                  }
              )
          context.logger.info(f"(Classification) Results: {results}")
      else:
          interactor = strtobool(
              os.environ.get("INTERACTOR_MODEL", "false")
          )
          annotations = json_data["params"].get("annotations")
          for a in annotations:
              annotation = a.get("annotation", {})
              if not annotation:
                  continue
  
              elements = annotation.get("elements", [])
              for element in elements:
                  label = element["label"]
                  contours = element["contours"]
                  for contour in contours:
                      points = np.array(contour, int)
                      if flip_output:
                          points = np.flip(points, axis=None)
  
                      # CVAT limitation:: only one polygon result for interactor
                      if interactor and contour:
                          return context.Response(
                              body=json.dumps(points.tolist()),
                              headers={},
                              content_type="application/json",
                              status_code=200,
                          )
  
                      results.append(
                          {
                              "label": label,
                              "points": points.flatten().tolist(),
                              "type": "polygon",
                          }
                      )
  
      return context.Response(
          body=json.dumps(results),
          headers={},
          content_type="application/json",
          status_code=200,
      )
  
file_path: MONAILabel/plugins/cvat/main.py
imports: import base64
  import io
  import json
  import logging
  import os
  from distutils.util import strtobool
  import numpy
  from PIL import Image
  from monailabel.interfaces.utils.app import app_instance
label_desc: Use image node_id 2 for calling a global function with example usage: handler(context, event) and returns: context, context