code: def get_from_cache(url: str, cache_dir: Path) -> Path:
      """Given a URL, look for the corresponding file in the local cache or download it.
  
      return: the path to the cached file.
      """
      cache_dir.mkdir(parents=True, exist_ok=True)
  
      filename = re.sub(r".+/", "", url)
      # get cache path to put the file
      cache_path = cache_dir / filename
      if cache_path.exists():
          return cache_path
  
      # make HEAD request to check ETag
      response = requests.head(
          url, headers={"User-Agent": "Flair"}, allow_redirects=True
      )
      if response.status_code != 200:
          raise OSError(
              f"HEAD request failed for url {url} with status code {response.status_code}."
          )
  
      # add ETag to filename if it exists
      # etag = response.headers.get("ETag")
  
      if not cache_path.exists():
          # Download to temporary file, then copy to cache dir once finished.
          # Otherwise you get corrupt cache entries if the download gets interrupted.
          fd, temp_filename = tempfile.mkstemp()
          logger.info(
              "%s not found in cache, downloading to %s",
              url,
              temp_filename,
          )
  
          # GET file object
          req = requests.get(
              url,
              stream=True,
              headers={"User-Agent": "Flair"},
              proxies=url_proxies,
          )
          content_length = req.headers.get("Content-Length")
          total = (
              int(content_length)
              if content_length is not None
              else None
          )
          progress = Tqdm.tqdm(
              unit="B", total=total, unit_scale=True, unit_divisor=1024
          )
          with open(temp_filename, "wb") as temp_file:
              for chunk in req.iter_content(chunk_size=1024):
                  if chunk:  # filter out keep-alive new chunks
                      progress.update(len(chunk))
                      temp_file.write(chunk)
  
          progress.close()
  
          logger.info(
              "copying %s to cache at %s", temp_filename, cache_path
          )
          shutil.copyfile(temp_filename, str(cache_path))
          logger.info("removing temp file %s", temp_filename)
          os.close(fd)
          os.remove(temp_filename)
  
      return cache_path
  
imports: import base64
  import functools
  import io
  import logging
  import mmap
  import os
  import re
  import shutil
  import tempfile
  import typing
  import warnings
  import zipfile
  from pathlib import Path
  from typing import Optional, Sequence, Tuple, Union, cast
  from urllib.parse import urlparse
  import boto3
  import requests
  import torch
  from botocore import UNSIGNED
  from botocore.config import Config
  from tqdm import tqdm
  import flair
label_desc: Use image node_id 9 for calling a global function with example usage: get_from_cache(url, cache_dir) and returns: cache_path, cache_path