code: def create_handler(
      flags_dict: Dict[str, Any]
  ) -> base_handler.BaseHandler:
      """Retrieve handler from the environment using the --engine flag.
  
      Args:
        flags_dict: A dictionary containing the flags of a command.
  
      Raises:
        RuntimeError: When engine is not supported by TFX.
  
      Returns:
        Corresponding Handler object.
      """
      engine = flags_dict[labels.ENGINE_FLAG]
      packages_list = str(
          subprocess.check_output(["pip", "freeze", "--local"])
      )
      if engine == "airflow":
          if labels.AIRFLOW_PACKAGE_NAME not in packages_list:
              sys.exit("Airflow not found.")
          from tfx.tools.cli.handler import (
              airflow_handler,
          )  # pylint: disable=g-import-not-at-top
  
          return airflow_handler.AirflowHandler(flags_dict)
      elif engine == "kubeflow":
          if labels.KUBEFLOW_PACKAGE_NAME not in packages_list:
              sys.exit("Kubeflow not found.")
          from tfx.tools.cli.handler import (
              kubeflow_handler,
          )  # pylint: disable=g-import-not-at-top
  
          return kubeflow_handler.KubeflowHandler(flags_dict)
      elif engine == "beam":
          from tfx.tools.cli.handler import (
              beam_handler,
          )  # pylint: disable=g-import-not-at-top
  
          return beam_handler.BeamHandler(flags_dict)
      elif engine == "local":
          from tfx.tools.cli.handler import (
              local_handler,
          )  # pylint: disable=g-import-not-at-top
  
          return local_handler.LocalHandler(flags_dict)
      elif engine == "vertex":
          if labels.KUBEFLOW_PACKAGE_NAME not in packages_list:
              sys.exit("`kfp` python pacakge is required for Vertex.")
          from tfx.tools.cli.handler import (
              vertex_handler,
          )  # pylint: disable=g-import-not-at-top
  
          return vertex_handler.VertexHandler(flags_dict)
      elif engine == "auto":
          return detect_handler(flags_dict)
      else:
          raise RuntimeError(
              "Engine {} is not supported.".format(engine)
          )
  
file_path: tfx/tfx/tools/cli/handler/handler_factory.py
imports: import subprocess
  import sys
  from typing import Any, Dict
  import click
  from tfx.tools.cli import labels
  from tfx.tools.cli import pip_utils
  from tfx.tools.cli.handler import base_handler
label_desc: Use image node_id 2 for calling a global function with example usage: create_handler(flags_dict) and returns: airflow_handler, kubeflow_handler, beam_handler, local_handler, vertex_handler, detect_handler