code: def detect_handler(
      flags_dict: Dict[str, Any]
  ) -> base_handler.BaseHandler:
      """Detect handler from the environment.
  
      Details:
        When the engine flag is set to 'auto', this method first finds all the
        packages in the local environment. The environment is first checked
        for multiple orchestrators and if true the user must rerun the command with
        required engine. If only one orchestrator is present, the engine is set to
        that.
  
      Args:
        flags_dict: A dictionary containing the flags of a command.
  
      Returns:
        Corrosponding Handler object.
      """
      packages_list = pip_utils.get_package_names()
      if (labels.AIRFLOW_PACKAGE_NAME in packages_list) and (
          labels.KUBEFLOW_PACKAGE_NAME in packages_list
      ):
          sys.exit(
              "Multiple orchestrators found. Choose one using --engine flag."
          )
      if labels.AIRFLOW_PACKAGE_NAME in packages_list:
          click.echo("Detected Airflow.")
          click.echo(
              "Use --engine flag if you intend to use a different orchestrator."
          )
          flags_dict[labels.ENGINE_FLAG] = "airflow"
          from tfx.tools.cli.handler import (
              airflow_handler,
          )  # pylint: disable=g-import-not-at-top
  
          return airflow_handler.AirflowHandler(flags_dict)
      elif labels.KUBEFLOW_PACKAGE_NAME in packages_list:
          click.echo("Detected Kubeflow.")
          click.echo(
              "Use --engine flag if you intend to use a different orchestrator."
          )
          flags_dict[labels.ENGINE_FLAG] = "kubeflow"
          from tfx.tools.cli.handler import (
              kubeflow_handler,
          )  # pylint: disable=g-import-not-at-top
  
          return kubeflow_handler.KubeflowHandler(flags_dict)
      else:
          click.echo("Detected Local.")
          click.echo(
              "Use --engine flag if you intend to use a different orchestrator."
          )
          flags_dict[labels.ENGINE_FLAG] = "local"
          from tfx.tools.cli.handler import (
              local_handler,
          )  # pylint: disable=g-import-not-at-top
  
          return local_handler.LocalHandler(flags_dict)
  
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 1 for calling a global function with example usage: detect_handler(flags_dict) and returns: airflow_handler, kubeflow_handler, local_handler