code: def get_tf_env(
      environment: Union[
          py_environment.PyEnvironment, tf_environment.TFEnvironment
      ]
  ) -> tf_environment.TFEnvironment:
      """Ensures output is a tf_environment, wrapping py_environments if needed."""
      if environment is None:
          raise ValueError("`environment` cannot be None")
      if isinstance(environment, py_environment.PyEnvironment):
          tf_env = tf_py_environment.TFPyEnvironment(environment)
      elif isinstance(environment, tf_environment.TFEnvironment):
          tf_env = environment
      else:
          raise ValueError(
              "`environment` %s must be an instance of "
              "`tf_environment.TFEnvironment` or `py_environment.PyEnvironment`."
              % environment
          )
      return tf_env
  
file_path: agents/tf_agents/environments/utils.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from typing import Optional, Union
  import numpy
  from tf_agents.environments import py_environment
  from tf_agents.environments import tf_environment
  from tf_agents.environments import tf_py_environment
  from tf_agents.policies import random_py_policy
  from tf_agents.specs import array_spec
  from tf_agents.typing import types
label_desc: Use image node_id 1 for calling a global function with example usage: get_tf_env(environment) and returns: tf_env