text: import importlib
  
  
  class InvalidTaskName(Exception):
      pass
  
  
  def name_to_task_class(task_file: str):
      name = task_file.replace('.py', '')
      class_name = ''.join([w[0].upper() + w[1:] for w in name.split('_')])
      try:
          mod = importlib.import_module("rlbench.tasks.%s" % name)
          mod = importlib.reload(mod)
      except ModuleNotFoundError as e:
          raise InvalidTaskName(
              "The task file '%s' does not exist or cannot be compiled."
              % name) from e
      try:
          task_class = getattr(mod, class_name)
      except AttributeError as e:
          raise InvalidTaskName(
              "Cannot find the class name '%s' in the file '%s'."
              % (class_name, name)) from e
      return task_class
  