code: def create_dsa_annotations_json(json_data, loglevel="INFO"):
      logger.setLevel(loglevel.upper())
  
      total_count = 0
      label_json = tempfile.NamedTemporaryFile(suffix=".json").name
      with open(label_json, "w") as fp:
          fp.write("{\n")
          fp.write(' "name": "{}",\n'.format(json_data["name"]))
          fp.write(' "elements": [\n')
  
          for tid, res in enumerate(json_data["annotations"]):
              logger.debug(f"Adding annotations for tile: {tid}")
              if not res:
                  continue
  
              annotation = res.get("annotation")
              if not annotation:
                  continue
  
              color_map = annotation.get("labels")
              elements = annotation.get("elements", [])
              for element in elements:
                  label = element["label"]
                  color = to_rgb(color_map.get(label))
  
                  logger.info(
                      f"Adding Contours for label: {label}; color: {color}; color_map: {color_map}"
                  )
  
                  contours = element["contours"]
                  for contour in contours:
                      points = []
                      for point in contour:
                          points.append([point[0], point[1], 0])
  
                      if total_count > 0:
                          fp.write(",\n")
  
                      annotation_style = {
                          "group": label,
                          "type": "polyline",
                          "lineColor": color,
                          "lineWidth": 2.0,
                          "closed": True,
                          "points": points,
                          "label": {"value": label},
                      }
                      fp.write(f"  {json.dumps(annotation_style)}")
                      total_count += 1
  
          fp.write(" ],\n")  # close elements
          fp.write(
              ' "description": {}\n'.format(
                  json.dumps(
                      json.dumps(
                          {
                              "model": json_data.get("model"),
                              "desc": json_data.get("description"),
                              "location": json_data.get("location"),
                              "size": json_data.get("size"),
                              "count": total_count,
                              "latencies": json_data.get("latencies"),
                          }
                      )
                  )
              )
          )
          fp.write("}")  # end of root
  
      logger.info(f"Total Elements: {total_count}")
      return label_json, total_count
  
imports: import json
  import logging
  import tempfile
  from monailabel.utils.others.label_colors import to_hex, to_rgb
label_desc: Use image node_id 1 for calling a global function with example usage: create_dsa_annotations_json(json_data, loglevel) and returns: label_json,  total_count