code: def from_spaces(
      space_name: str, hf_token: str | None, alias: str | None, **kwargs
  ) -> Blocks:
      space_url = f"https://huggingface.co/spaces/{space_name}"
  
      print(f"Fetching Space from: {space_url}")
  
      headers = {}
      if hf_token is not None:
          headers["Authorization"] = f"Bearer {hf_token}"
  
      iframe_url = (
          httpx.get(
              f"https://huggingface.co/api/spaces/{space_name}/host",
              headers=headers,
          )
          .json()
          .get("host")
      )
  
      if iframe_url is None:
          raise ValueError(
              f"Could not find Space: {space_name}. If it is a private or gated Space, please provide your Hugging Face access token (https://huggingface.co/settings/tokens) as the argument for the `hf_token` parameter."
          )
  
      r = httpx.get(iframe_url, headers=headers)
  
      result = re.search(
          r"window.gradio_config = (.*?);[\s]*</script>", r.text
      )  # some basic regex to extract the config
      try:
          config = json.loads(result.group(1))  # type: ignore
      except AttributeError as ae:
          raise ValueError(
              f"Could not load the Space: {space_name}"
          ) from ae
      if (
          "allow_flagging" in config
      ):  # Create an Interface for Gradio 2.x Spaces
          return from_spaces_interface(
              space_name, config, alias, hf_token, iframe_url, **kwargs
          )
      else:  # Create a Blocks for Gradio 3.x Spaces
          if kwargs:
              warnings.warn(
                  "You cannot override parameters for this Space by passing in kwargs. "
                  "Instead, please load the Space as a function and use it to create a "
                  "Blocks or Interface locally. You may find this Guide helpful: "
                  "https://gradio.app/using_blocks_like_functions/"
              )
          return from_spaces_blocks(space=space_name, hf_token=hf_token)
  
imports: from __future__ import annotations
  import json
  import os
  import re
  import tempfile
  import warnings
  from pathlib import Path
  from typing import TYPE_CHECKING, Callable
  import httpx
  from gradio_client import Client
  from gradio_client import utils
  from gradio_client.client import Endpoint
  from gradio_client.documentation import document, set_documentation_group
  from packaging import version
  import gradio
  from gradio import components, utils
  from gradio.context import Context
  from gradio.exceptions import Error, GradioVersionIncompatibleError, ModelNotFoundError, TooManyRequestsError
  from gradio.external_utils import cols_to_rows, encode_to_base64, get_tabular_examples, postprocess_label, rows_to_cols, streamline_spaces_interface
  from gradio.processing_utils import extract_base64_data, save_base64_to_cache, to_binary
label_desc: Use image node_id 6 for calling a global function with example usage: from_spaces(space_name, hf_token, alias) and returns: from_spaces_interface, from_spaces_blocks