code: def Filter(  # pylint: disable=invalid-name
      extracts: beam.pvalue.PCollection,
      include: Optional[Union[Iterable[str], Dict[str, Any]]] = None,
      exclude: Optional[Union[Iterable[str], Dict[str, Any]]] = None,
  ) -> beam.pvalue.PCollection:
      """Filters extracts to include/exclude specified keys.
  
      Args:
        extracts: PCollection of extracts.
        include: List or map of keys to include in output. If a map of keys is
          passed then the keys and sub-keys that exist in the map will be included
          in the output. An empty dict behaves as a wildcard matching all keys or
          the value itself. Since matching on feature values is not currently
          supported, an empty dict must be used to represent the leaf nodes.
          For example: {'key1': {'key1-subkey': {}}, 'key2': {}}.
        exclude: List or map of keys to exclude from output. If a map of keys is
          passed then the keys and sub-keys that exist in the map will be excluded
          from the output. An empty dict behaves as a wildcard matching all keys or
          the value itself. Since matching on feature values is not currently
          supported, an empty dict must be used to represent the leaf nodes.
          For example: {'key1': {'key1-subkey': {}}, 'key2': {}}.
  
      Returns:
        Filtered PCollection of Extracts.
  
      Raises:
        ValueError: If both include and exclude are used.
      """
      if include and exclude:
          raise ValueError(
              "only one of include or exclude should be used."
          )
  
      if not isinstance(include, dict):
          include = {k: {} for k in include or []}
      if not isinstance(exclude, dict):
          exclude = {k: {} for k in exclude or []}
  
      def filter_extracts(
          extracts: types.Extracts,
      ) -> types.Extracts:  # pylint: disable=invalid-name
          """Filters extracts."""
          if not include and not exclude:
              return extracts
          elif include:
              return util.include_filter(include, extracts)
          else:
              return util.exclude_filter(exclude, extracts)
  
      return extracts | beam.Map(filter_extracts)
  
imports: from typing import Any, Dict, Iterable, NamedTuple, Optional, Union
  import apache_beam
  from tensorflow_model_analysis.api import types
  from tensorflow_model_analysis.utils import util
label_desc: Use image node_id 1 for calling a global function with example usage: Filter(extracts, include, exclude) and returns: unknown, extracts, util, util