code: def cached_path(
      url_or_filename: str, cache_dir: str = None, name=None
  ) -> Path:
      r"""
      给定一个 url，尝试通过 url 中解析出来的文件名字 filename 到 ``{cache_dir}/{name}/{filename}`` 下寻找这个文件或文件夹：
  
      1. 如果 ``cache_dir`` 为 ``None``，则默认为 ``~/.fastNLP/``；
      2. 如果 ``name=None`` ，则没有中间的 {name} 这一层结构。
  
      如果有该文件，就直接返回路径；如果没有该文件，则尝试用传入的 url 下载，并将文件放入 ``cache_dir`` 中。
  
      :param url_or_filename: 文件的下载 url 或者文件名称。
      :param cache_dir: 文件的缓存文件夹。如果为 ``None``，将使 ``"~/.fastNLP`` 这个默认路径
      :param name: 中间一层的名称。如 embedding, dataset
      :return:
      """
      if cache_dir is None:
          data_cache = Path(get_cache_path())
      else:
          data_cache = cache_dir
  
      if name:
          data_cache = os.path.join(data_cache, name)
  
      parsed = urlparse(url_or_filename)
  
      if parsed.scheme in ("http", "https"):
          # URL, so get it from the cache (downloading if necessary)
          return get_from_cache(url_or_filename, Path(data_cache))
      elif (
          parsed.scheme == ""
          and Path(os.path.join(data_cache, url_or_filename)).exists()
      ):
          # File, and it exists.
          return Path(os.path.join(data_cache, url_or_filename))
      elif parsed.scheme == "":
          # File, but it doesn't exist.
          raise FileNotFoundError(
              "file {} not found in {}.".format(
                  url_or_filename, data_cache
              )
          )
      else:
          # Something unknown
          raise ValueError(
              "unable to parse {} as a URL or as a local path".format(
                  url_or_filename
              )
          )
  
imports: import os
  import re
  import shutil
  import tempfile
  from pathlib import Path
  from urllib.parse import urlparse
  import requests
  from requests import HTTPError
  from fastNLP.core.log import logger
  from rich.progress import Progress, BarColumn, DownloadColumn, TimeRemainingColumn, TimeElapsedColumn
label_desc: Use image node_id 1 for calling a global function with example usage: cached_path(url_or_filename, cache_dir, name) and returns: get_from_cache, Path