code: def _capture_imported_modules(model_uri, flavor):
      """Runs `_capture_modules.py` in a subprocess and captures modules imported during the model
      loading procedure.
      If flavor is `transformers`, `_capture_transformers_modules.py` is run instead.
  
      Args:
          model_uri: The URI of the model.
          flavor: The flavor name of the model.
  
      Returns:
          A list of captured modules.
  
      """
      local_model_path = _download_artifact_from_uri(model_uri)
  
      process_timeout = MLFLOW_REQUIREMENTS_INFERENCE_TIMEOUT.get()
  
      # Run `_capture_modules.py` to capture modules imported during the loading procedure
      with tempfile.TemporaryDirectory() as tmpdir:
          output_file = os.path.join(tmpdir, "imported_modules.txt")
          # Pass the main environment variables to the subprocess for environment variable mapping
          main_env = os.environ.copy()
          # Reset the path variable from the main process so that the subprocess retains all
          # main process configuration that a user has.
          # See: ``https://github.com/mlflow/mlflow/issues/6905`` for context on minio configuration
          # resolution in a subprocess based on PATH entries.
          main_env["PATH"] = "/usr/sbin:/sbin:" + main_env["PATH"]
  
          if flavor == mlflow.transformers.FLAVOR_NAME:
              # Lazily import `_capture_transformers_module` here to avoid circular imports.
              from mlflow.utils import _capture_transformers_modules
  
              for module_to_throw in ["tensorflow", "torch"]:
                  try:
                      _run_command(
                          [
                              sys.executable,
                              _capture_transformers_modules.__file__,
                              "--model-path",
                              local_model_path,
                              "--flavor",
                              flavor,
                              "--output-file",
                              output_file,
                              "--sys-path",
                              json.dumps(sys.path),
                              "--module-to-throw",
                              module_to_throw,
                          ],
                          timeout_seconds=process_timeout,
                          env=main_env,
                      )
                      with open(output_file) as f:
                          return f.read().splitlines()
  
                  except MlflowException:
                      pass
  
          # Lazily import `_capture_module` here to avoid circular imports.
          from mlflow.utils import _capture_modules
  
          _run_command(
              [
                  sys.executable,
                  _capture_modules.__file__,
                  "--model-path",
                  local_model_path,
                  "--flavor",
                  flavor,
                  "--output-file",
                  output_file,
                  "--sys-path",
                  json.dumps(sys.path),
              ],
              timeout_seconds=process_timeout,
              env=main_env,
          )
  
          with open(output_file) as f:
              return f.read().splitlines()
  
imports: import json
  import logging
  import os
  import re
  import subprocess
  import sys
  import tempfile
  from collections import namedtuple
  from itertools import chain, filterfalse
  from pathlib import Path
  from threading import Timer
  from typing import NamedTuple, Optional
  import importlib_metadata
  import pkg_resources
  from packaging.requirements import Requirement
  from packaging.version import InvalidVersion, Version
  import mlflow
  from mlflow.environment_variables import MLFLOW_REQUIREMENTS_INFERENCE_TIMEOUT
  from mlflow.exceptions import MlflowException
  from mlflow.tracking.artifact_utils import _download_artifact_from_uri
  from mlflow.utils.autologging_utils.versioning import _strip_dev_version_suffix
  from mlflow.utils.databricks_utils import is_in_databricks_runtime
label_desc: Use image node_id 16 for calling a global function with example usage: _capture_imported_modules(model_uri, flavor) and returns: f, f