code: def load_detector(
      filepath: Union[str, os.PathLike],
      enable_unsafe_loading: bool = False,
      **kwargs,
  ) -> Union[Detector, ConfigurableDetector]:
      """
      Load outlier, drift or adversarial detector.
  
      Parameters
      ----------
      filepath
          Load directory.
      enable_unsafe_loading
          Sets allow_pickle=True when a np.ndarray is loaded from a .npy file referenced in the detector config. Needed
          if you have to load objects.
          Only applied if the filepath is config.toml or a directory containing a config.toml.
          It has security implications: https://nvd.nist.gov/vuln/detail/cve-2019-6446.
  
      Returns
      -------
      Loaded outlier or adversarial detector object.
      """
      filepath = Path(filepath)
      # If reference is a 'config.toml' itself, pass to new load function
      if filepath.name == "config.toml":
          return _load_detector_config(
              filepath, enable_unsafe_loading=enable_unsafe_loading
          )
  
      # Otherwise, if a directory, look for meta.dill, meta.pickle or config.toml inside it
      elif filepath.is_dir():
          files = [
              str(f.name) for f in filepath.iterdir() if f.is_file()
          ]
          if "config.toml" in files:
              return _load_detector_config(
                  filepath.joinpath("config.toml"),
                  enable_unsafe_loading=enable_unsafe_loading,
              )
          elif "meta.dill" in files:
              return load_detector_legacy(filepath, ".dill", **kwargs)
          elif "meta.pickle" in files:
              return load_detector_legacy(filepath, ".pickle", **kwargs)
          else:
              raise ValueError(
                  f"Neither meta.dill, meta.pickle or config.toml exist in {filepath}."
              )
  
      # No other file types are accepted, so if not dir raise error
      else:
          raise ValueError(
              "load_detector accepts only a filepath to a directory, or a config.toml file."
          )
  
imports: import logging
  import os
  from functools import partial
  from importlib import import_module
  from pathlib import Path
  from typing import Any, Callable, Optional, Union, Type, TYPE_CHECKING
  import dill
  import numpy
  import toml
  from transformers import AutoTokenizer
  from alibi_detect.saving.registry import registry
  from alibi_detect.saving._tensorflow import load_detector_legacy, load_embedding_tf, load_kernel_config_tf, load_model_tf, load_optimizer_tf, prep_model_and_emb_tf, get_tf_dtype
  from alibi_detect.saving._pytorch import load_embedding_pt, load_kernel_config_pt, load_model_pt, load_optimizer_pt, prep_model_and_emb_pt, get_pt_dtype
  from alibi_detect.saving._keops import load_kernel_config_ke
  from alibi_detect.saving._sklearn import load_model_sk
  from alibi_detect.saving.validate import validate_config
  from alibi_detect.base import Detector, ConfigurableDetector, StatefulDetectorOnline
  from alibi_detect.utils.frameworks import has_tensorflow, has_pytorch, Framework
  from alibi_detect.saving.schemas import supported_models_tf, supported_models_torch
  from alibi_detect.utils.missing_optional_dependency import import_optional
label_desc: Use image node_id 1 for calling a global function with example usage: load_detector(filepath, enable_unsafe_loading) and returns: _load_detector_config, _load_detector_config, load_detector_legacy, load_detector_legacy