code: def cached_path(
      url_or_filename,
      cache_dir=None,
      force_download=False,
      proxies=None,
      resume_download=False,
      user_agent=None,
      extract_compressed_file=False,
      force_extract=False,
      local_files_only=False,
  ):
      if cache_dir is None:
          cache_dir = TRANSFORMERS_CACHE
      if isinstance(url_or_filename, Path):
          url_or_filename = str(url_or_filename)
      if isinstance(cache_dir, Path):
          cache_dir = str(cache_dir)
  
      if is_remote_url(url_or_filename):
          filename = url_to_filename(url_or_filename)
          output_path = os.path.join(cache_dir, filename)
          if not os.path.isfile(output_path):
              assert download(
                  url_or_filename, cache_dir, filename
              ), f"failed to download {url_or_filename}"
      elif os.path.exists(url_or_filename):
          # File, and it exists.
          output_path = url_or_filename
      elif urlparse(url_or_filename).scheme == "":
          # File, but it doesn't exist.
          raise OSError(f"file {url_or_filename} not found")
      else:
          # Something unknown
          raise ValueError(
              f"unable to parse {url_or_filename} as a URL or as a local path"
          )
  
      if extract_compressed_file:
          if not is_zipfile(output_path) and not tarfile.is_tarfile(
              output_path
          ):
              return output_path
  
          # Path where we extract compressed archives
          # We avoid '.' in dir name and add "-extracted"
          # at the end: "./model.zip" => "./model-zip-extracted/"
          output_dir, output_file = os.path.split(output_path)
          output_extract_dir_name = (
              output_file.replace(".", "-") + "-extracted"
          )
          output_path_extracted = os.path.join(
              output_dir, output_extract_dir_name
          )
  
          if (
              os.path.isdir(output_path_extracted)
              and os.listdir(output_path_extracted)
              and not force_extract
          ):
              return output_path_extracted
  
          # Prevent parallel extractions
          lock_path = output_path + ".lock"
          with FileLock(lock_path):
              shutil.rmtree(output_path_extracted, ignore_errors=True)
              os.makedirs(output_path_extracted)
              if is_zipfile(output_path):
                  with ZipFile(output_path, "r") as zip_file:
                      zip_file.extractall(output_path_extracted)
                      zip_file.close()
              elif tarfile.is_tarfile(output_path):
                  tar_file = tarfile.open(output_path)
                  tar_file.extractall(output_path_extracted)
                  tar_file.close()
              else:
                  raise OSError(
                      f"Archive format of {output_path} could not be identified"
                  )
  
          return output_path_extracted
  
      return output_path
  
imports: import copy
  import json
  import os
  import pickle
  import shutil
  import tarfile
  from collections import OrderedDict
  from hashlib import sha256
  from pathlib import Path
  from urllib.parse import urlparse
  from zipfile import is_zipfile, ZipFile
  import numpy
  import requests
  from filelock import FileLock
  from mmf.utils.configuration import get_mmf_cache_dir
  from mmf.utils.download import download
  from omegaconf import OmegaConf
label_desc: Use image node_id 4 for calling a global function with example usage: cached_path(url_or_filename, cache_dir, force_download, proxies, resume_download, user_agent, extract_compressed_file, force_extract, local_files_only) and returns: output_path, output_path_extracted, output_path, output_path_extracted