code: def _create_metadata_buffer(
      model_buffer: bytearray,
      general_md: Optional[metadata_info.GeneralMd] = None,
      input_md: Optional[List[metadata_info.TensorMd]] = None,
      output_md: Optional[List[metadata_info.TensorMd]] = None,
      input_process_units: Optional[
          List[metadata_fb.ProcessUnitT]
      ] = None,
      output_group_md: Optional[
          List[metadata_info.TensorGroupMd]
      ] = None,
      custom_metadata_md: Optional[
          List[metadata_info.CustomMetadataMd]
      ] = None,
  ) -> bytearray:
      """Creates a buffer of the metadata.
  
      Args:
        model_buffer: valid buffer of the model file.
        general_md: general information about the model.
        input_md: metadata information of the input tensors.
        output_md: metadata information of the output tensors.
        input_process_units: a lists of metadata of the input process units [1].
        output_group_md: a list of metadata of output tensor groups [2];
        custom_metadata_md: a lists of custom metadata.
        [1]:
          https://github.com/google/mediapipe/blob/f8af41b1eb49ff4bdad756ff19d1d36f486be614/mediapipe/tasks/metadata/metadata_schema.fbs#L655
        [2]:
          https://github.com/google/mediapipe/blob/f8af41b1eb49ff4bdad756ff19d1d36f486be614/mediapipe/tasks/metadata/metadata_schema.fbs#L677
  
      Returns:
        A buffer of the metadata.
  
      Raises:
        ValueError: if the tensor names from `input_md` and `output_md` do not
        match the tensor names read from the model.
      """
      # Create input metadata from `input_md`.
      if input_md:
          input_md = _pair_tensor_metadata(
              input_md,
              writer_utils.get_input_tensor_names(model_buffer),
          )
          input_metadata = [m.create_metadata() for m in input_md]
      else:
          num_input_tensors = writer_utils.get_subgraph(
              model_buffer
          ).InputsLength()
          input_metadata = [
              metadata_fb.TensorMetadataT()
          ] * num_input_tensors
  
      _fill_default_tensor_names(
          input_metadata,
          writer_utils.get_input_tensor_names(model_buffer),
      )
  
      # Create output metadata from `output_md`.
      if output_md:
          output_md = _pair_tensor_metadata(
              output_md,
              writer_utils.get_output_tensor_names(model_buffer),
          )
          output_metadata = [m.create_metadata() for m in output_md]
      else:
          num_output_tensors = writer_utils.get_subgraph(
              model_buffer
          ).OutputsLength()
          output_metadata = [
              metadata_fb.TensorMetadataT()
          ] * num_output_tensors
      _fill_default_tensor_names(
          output_metadata,
          writer_utils.get_output_tensor_names(model_buffer),
      )
  
      # Create the subgraph metadata.
      subgraph_metadata = metadata_fb.SubGraphMetadataT()
      subgraph_metadata.inputTensorMetadata = input_metadata
      subgraph_metadata.outputTensorMetadata = output_metadata
      if input_process_units:
          subgraph_metadata.inputProcessUnits = input_process_units
      if custom_metadata_md:
          subgraph_metadata.customMetadata = [
              m.create_metadata() for m in custom_metadata_md
          ]
      if output_group_md:
          subgraph_metadata.outputTensorGroups = [
              m.create_metadata() for m in output_group_md
          ]
  
      # Create the whole model metadata.
      if general_md is None:
          general_md = metadata_info.GeneralMd()
      model_metadata = general_md.create_metadata()
      model_metadata.subgraphMetadata = [subgraph_metadata]
  
      # Get the metadata flatbuffer.
      b = flatbuffers.Builder(0)
      b.Finish(
          model_metadata.Pack(b),
          metadata.MetadataPopulator.METADATA_FILE_IDENTIFIER,
      )
      return b.Output()
  
imports: import collections
  import csv
  import dataclasses
  import os
  import tempfile
  from typing import List, Optional, Tuple, Union
  import flatbuffers
  from mediapipe.tasks.metadata import metadata_schema_py_generated
  from mediapipe.tasks.python.metadata import metadata
  from mediapipe.tasks.python.metadata.metadata_writers import metadata_info
  from mediapipe.tasks.python.metadata.metadata_writers import writer_utils
label_desc: Use image node_id 3 for calling a global function with example usage: _create_metadata_buffer(model_buffer, general_md, input_md, output_md, input_process_units, output_group_md, custom_metadata_md) and returns: b