code: def http_get(
      url: str,
      temp_file: BinaryIO,
      *,
      proxies: Optional[Dict] = None,
      resume_size: float = 0,
      headers: Optional[Dict[str, str]] = None,
      expected_size: Optional[int] = None,
      displayed_filename: Optional[str] = None,
      _nb_retries: int = 5,
  ) -> None:
      """
      Download a remote file. Do not gobble up errors, and will return errors tailored to the Hugging Face Hub.
  
      If ConnectionError (SSLError) or ReadTimeout happen while streaming data from the server, it is most likely a
      transient error (network outage?). We log a warning message and try to resume the download a few times before
      giving up. The method gives up after 5 attempts if no new data has being received from the server.
  
      Args:
          url (`str`):
              The URL of the file to download.
          temp_file (`BinaryIO`):
              The file-like object where to save the file.
          proxies (`dict`, *optional*):
              Dictionary mapping protocol to the URL of the proxy passed to `requests.request`.
          resume_size (`float`, *optional*):
              The number of bytes already downloaded. If set to 0 (default), the whole file is download. If set to a
              positive number, the download will resume at the given position.
          headers (`dict`, *optional*):
              Dictionary of HTTP Headers to send with the request.
          expected_size (`int`, *optional*):
              The expected size of the file to download. If set, the download will raise an error if the size of the
              received content is different from the expected one.
          displayed_filename (`str`, *optional*):
              The filename of the file that is being downloaded. Value is used only to display a nice progress bar. If
              not set, the filename is guessed from the URL or the `Content-Disposition` header.
      """
      hf_transfer = None
      if HF_HUB_ENABLE_HF_TRANSFER:
          if resume_size != 0:
              warnings.warn(
                  "'hf_transfer' does not support `resume_size`: falling back to regular download method"
              )
          elif proxies is not None:
              warnings.warn(
                  "'hf_transfer' does not support `proxies`: falling back to regular download method"
              )
          else:
              try:
                  import hf_transfer  # type: ignore[no-redef]
              except ImportError:
                  raise ValueError(
                      "Fast download using 'hf_transfer' is enabled"
                      " (HF_HUB_ENABLE_HF_TRANSFER=1) but 'hf_transfer' package is not"
                      " available in your environment. Try `pip install hf_transfer`."
                  )
  
      initial_headers = headers
      headers = copy.deepcopy(headers) or {}
      if resume_size > 0:
          headers["Range"] = "bytes=%d-" % (resume_size,)
  
      r = _request_wrapper(
          method="GET",
          url=url,
          stream=True,
          proxies=proxies,
          headers=headers,
          timeout=HF_HUB_DOWNLOAD_TIMEOUT,
      )
      hf_raise_for_status(r)
      content_length = r.headers.get("Content-Length")
  
      # NOTE: 'total' is the total number of bytes to download, not the number of bytes in the file.
      #       If the file is compressed, the number of bytes in the saved file will be higher than 'total'.
      total = (
          resume_size + int(content_length)
          if content_length is not None
          else None
      )
  
      if displayed_filename is None:
          displayed_filename = url
          content_disposition = r.headers.get("Content-Disposition")
          if content_disposition is not None:
              match = HEADER_FILENAME_PATTERN.search(
                  content_disposition
              )
              if match is not None:
                  # Means file is on CDN
                  displayed_filename = match.groupdict()["filename"]
  
      # Truncate filename if too long to display
      if len(displayed_filename) > 40:
          displayed_filename = f"(…){displayed_filename[-40:]}"
  
      consistency_error_message = (
          f"Consistency check failed: file should be of size {expected_size} but has size"
          f" {{actual_size}} ({displayed_filename}).\nWe are sorry for the inconvenience. Please retry download and"
          " pass `force_download=True, resume_download=False` as argument.\nIf the issue persists, please let us"
          " know by opening an issue on https://github.com/huggingface/huggingface_hub."
      )
  
      # Stream file to buffer
      with tqdm(
          unit="B",
          unit_scale=True,
          total=total,
          initial=resume_size,
          desc=displayed_filename,
          disable=bool(logger.getEffectiveLevel() == logging.NOTSET),
      ) as progress:
          if (
              hf_transfer
              and total is not None
              and total > 5 * DOWNLOAD_CHUNK_SIZE
          ):
              supports_callback = (
                  "callback"
                  in inspect.signature(hf_transfer.download).parameters
              )
              if not supports_callback:
                  warnings.warn(
                      "You are using an outdated version of `hf_transfer`. "
                      "Consider upgrading to latest version to enable progress bars "
                      "using `pip install -U hf_transfer`."
                  )
              try:
                  hf_transfer.download(
                      url=url,
                      filename=temp_file.name,
                      max_files=HF_TRANSFER_CONCURRENCY,
                      chunk_size=DOWNLOAD_CHUNK_SIZE,
                      headers=headers,
                      parallel_failures=3,
                      max_retries=5,
                      **(
                          {"callback": progress.update}
                          if supports_callback
                          else {}
                      ),
                  )
              except Exception as e:
                  raise RuntimeError(
                      "An error occurred while downloading using `hf_transfer`. Consider"
                      " disabling HF_HUB_ENABLE_HF_TRANSFER for better error handling."
                  ) from e
              if not supports_callback:
                  progress.update(total)
              if (
                  expected_size is not None
                  and expected_size != os.path.getsize(temp_file.name)
              ):
                  raise EnvironmentError(
                      consistency_error_message.format(
                          actual_size=os.path.getsize(temp_file.name),
                      )
                  )
              return
          new_resume_size = resume_size
          try:
              for chunk in r.iter_content(
                  chunk_size=DOWNLOAD_CHUNK_SIZE
              ):
                  if chunk:  # filter out keep-alive new chunks
                      progress.update(len(chunk))
                      temp_file.write(chunk)
                      new_resume_size += len(chunk)
                      # Some data has been downloaded from the server so we reset the number of retries.
                      _nb_retries = 5
          except (requests.ConnectionError, requests.ReadTimeout) as e:
              # If ConnectionError (SSLError) or ReadTimeout happen while streaming data from the server, it is most likely
              # a transient error (network outage?). We log a warning message and try to resume the download a few times
              # before giving up. Tre retry mechanism is basic but should be enough in most cases.
              if _nb_retries <= 0:
                  logger.warning(
                      "Error while downloading from %s: %s\nMax retries exceeded.",
                      url,
                      str(e),
                  )
                  raise
              logger.warning(
                  "Error while downloading from %s: %s\nTrying to resume download...",
                  url,
                  str(e),
              )
              time.sleep(1)
              reset_sessions()  # In case of SSLError it's best to reset the shared requests.Session objects
              return http_get(
                  url=url,
                  temp_file=temp_file,
                  proxies=proxies,
                  resume_size=new_resume_size,
                  headers=initial_headers,
                  expected_size=expected_size,
                  _nb_retries=_nb_retries - 1,
              )
  
          if (
              expected_size is not None
              and expected_size != temp_file.tell()
          ):
              raise EnvironmentError(
                  consistency_error_message.format(
                      actual_size=temp_file.tell(),
                  )
              )
  
imports: import copy
  import fnmatch
  import inspect
  import io
  import json
  import os
  import re
  import shutil
  import stat
  import tempfile
  import time
  import uuid
  import warnings
  from contextlib import contextmanager
  from dataclasses import dataclass
  from functools import partial
  from pathlib import Path
  from typing import Any, BinaryIO, Dict, Generator, Literal, Optional, Tuple, Union
  from urllib.parse import quote, urlparse
  import requests
  from filelock import FileLock
  from huggingface_hub import constants
  from .None import __version__
  from .constants import DEFAULT_ETAG_TIMEOUT, DEFAULT_REQUEST_TIMEOUT, DEFAULT_REVISION, DOWNLOAD_CHUNK_SIZE, ENDPOINT, HF_HUB_CACHE, HF_HUB_DISABLE_SYMLINKS_WARNING, HF_HUB_DOWNLOAD_TIMEOUT, HF_HUB_ENABLE_HF_TRANSFER, HF_HUB_ETAG_TIMEOUT, HF_TRANSFER_CONCURRENCY, HUGGINGFACE_CO_URL_TEMPLATE, HUGGINGFACE_HEADER_X_LINKED_ETAG, HUGGINGFACE_HEADER_X_LINKED_SIZE, HUGGINGFACE_HEADER_X_REPO_COMMIT, HUGGINGFACE_HUB_CACHE, REPO_ID_SEPARATOR, REPO_TYPES, REPO_TYPES_URL_PREFIXES
  from .utils import EntryNotFoundError, FileMetadataError, GatedRepoError, LocalEntryNotFoundError, OfflineModeIsEnabled, RepositoryNotFoundError, RevisionNotFoundError, SoftTemporaryDirectory, build_hf_headers, get_fastai_version, get_fastcore_version, get_graphviz_version, get_jinja_version, get_pydot_version, get_session, get_tf_version, get_torch_version, hf_raise_for_status, is_fastai_available, is_fastcore_available, is_graphviz_available, is_jinja_available, is_pydot_available, is_tf_available, is_torch_available, logging, reset_sessions, tqdm, validate_hf_hub_args
  from .utils._deprecation import _deprecate_method
  from .utils._headers import _http_user_agent
  from .utils._runtime import _PY_VERSION
  from .utils._typing import HTTP_METHOD_T
  from .utils.insecure_hashlib import sha256
label_desc: Use image node_id 7 for calling a global function with example usage: http_get(url, temp_file) and returns: http_get