code: def cached_path(
      url_or_filename: Union[str, Path],
      cache_dir: Union[str, Path] = None,
  ) -> str:
      """
      Given something that might be a URL (or might be a local path),
      determine which. If it's a URL, download the file and cache it, and
      return the path to the cached file. If it's already a local path,
      make sure the file exists and then return the path.
      """
      if cache_dir is None:
          cache_dir = PYTORCH_PRETRAINED_BERT_CACHE
      if isinstance(url_or_filename, Path):
          url_or_filename = str(url_or_filename)
      if isinstance(cache_dir, Path):
          cache_dir = str(cache_dir)
  
      parsed = urlparse(url_or_filename)
  
      if parsed.scheme in ("http", "https", "s3"):
          # URL, so get it from the cache (downloading if necessary)
          return get_from_cache(url_or_filename, cache_dir)
      elif os.path.exists(url_or_filename):
          # File, and it exists.
          return url_or_filename
      elif parsed.scheme == "":
          # File, but it doesn't exist.
          raise FileNotFoundError(
              "file {} not found".format(url_or_filename)
          )
      else:
          # Something unknown
          raise ValueError(
              "unable to parse {} as a URL or as a local path".format(
                  url_or_filename
              )
          )
  
imports: import os
  import logging
  import shutil
  import tempfile
  import json
  from urllib.parse import urlparse
  from pathlib import Path
  from typing import Optional, Tuple, Union, IO, Callable, Set
  from hashlib import sha256
  from functools import wraps
  from tqdm import tqdm
  import boto3
  from botocore.exceptions import ClientError
  import requests
label_desc: Use image node_id 3 for calling a global function with example usage: cached_path(url_or_filename, cache_dir) and returns: get_from_cache, url_or_filename