code: def annotate_eval_result_metrics(
      model_card: model_card_module.ModelCard,
      eval_result: tfma.EvalResult,
  ):
      """Annotates model_card's PerformanceMetrics for every metric in eval_result.
  
      Args:
        model_card: The model card object.
        eval_result: A `tfma.EvalResult`.
  
      Raises:
        ValueError: if eval_result is improperly formatted.
      """
  
      def _parse_array_value(array: Dict[str, Any]) -> str:
          data_type = array["dataType"]
          if data_type in _TYPE_FIELD_MAP:
              type_field = _TYPE_FIELD_MAP[data_type]
              return ", ".join(
                  [str(value) for value in array[type_field]]
              )
          else:
              logging.warning(
                  "Received unexpected array %s", str(array)
              )
              return ""
  
      # NOTE: When multiple outputs are passed, each will be in it's own
      # output_name key. If that's the case add each output_name + metric
      # to the quantitative_analysis by namespacing by output_name.metric
      # to distinguish them
      output_names = set()
      for slicing_metric in eval_result.slicing_metrics:
          for output_name in slicing_metric[1]:
              output_names.add(output_name)
      for output_name in sorted(output_names):
          for (
              slice_repr,
              metrics_for_slice,
          ) in eval_result.get_metrics_for_all_slices(
              output_name=output_name
          ).items():
              # Parse the slice name
              if not isinstance(slice_repr, tuple):
                  raise ValueError(
                      f"Expected EvalResult slices to be tuples; found {type(slice_repr)}"
                  )
              slice_name = "_X_".join(f"{a}_{b}" for a, b in slice_repr)
              for (
                  metric_name,
                  metric_value,
              ) in metrics_for_slice.items():
                  # Parse the metric value
                  parsed_value = ""
                  if "doubleValue" in metric_value:
                      parsed_value = metric_value["doubleValue"]
                  elif "boundedValue" in metric_value:
                      parsed_value = metric_value["boundedValue"][
                          "value"
                      ]
                  elif "arrayValue" in metric_value:
                      parsed_value = _parse_array_value(
                          metric_value["arrayValue"]
                      )
                  else:
                      logging.warning(
                          "Expected doubleValue, boundedValue, or arrayValue; found %s",
                          metric_value.keys(),
                      )
                  if parsed_value:
                      metric_type = metric_name
                      if output_name:
                          metric_type = f"{output_name}.{metric_name}"
                      # Create the PerformanceMetric and append to the ModelCard
                      metric = model_card_module.PerformanceMetric(
                          type=metric_type,
                          value=str(parsed_value),
                          slice=slice_name,
                      )
                      model_card.quantitative_analysis.performance_metrics.append(
                          metric
                      )
  
imports: import enum
  import os
  from typing import Any, Dict, Iterable, List, Optional, Sequence, Union
  import attr
  import ml_metadata
  import tensorflow
  import tensorflow_model_analysis
  from absl import logging
  from ml_metadata.proto import metadata_store_pb2
  from tensorflow_metadata.proto.v0 import statistics_pb2
  from model_card_toolkit import model_card
label_desc: Use image node_id 12 for calling a global function with example usage: annotate_eval_result_metrics(model_card, eval_result) and returns: str, str