code: def upload_demo_to_space(
      demo_name: str,
      space_id: str,
      hf_token: str,
      gradio_version: str | None,
      gradio_wheel_url: str | None = None,
  ):
      """Upload a demo in the demo directory to a huggingface space.
      Parameters:
          demo_name: The name of the demo to upload.
          space_id: The id of the space to upload the demo to.
          hf_token: HF api token. Need to have permission to write to space_id for this to work.
          gradio_version: If not None, will set the gradio version in the created Space to the given version.
          gradio_wheel_url: If not None, will install the version of gradio using the wheel url in the created Space.
      """
  
      with tempfile.TemporaryDirectory() as tmpdir:
          demo_path = pathlib.Path(GRADIO_DEMO_DIR, demo_name)
          shutil.copytree(demo_path, tmpdir, dirs_exist_ok=True)
          readme = pathlib.Path(tmpdir, "README.md")
          readme_content = f"""
                              ---
                              title: {space_id.split("/")[-1]} 
                              emoji: 🔥
                              colorFrom: indigo
                              colorTo: indigo
                              sdk: gradio
                              sdk_version: {gradio_version}
                              app_file: run.py
                              pinned: false
                              hf_oauth: true
                              ---
                              """
          readme.open("w").write(textwrap.dedent(readme_content))
  
          if gradio_wheel_url:
              requirements_path = os.path.join(
                  tmpdir, "requirements.txt"
              )
              if not os.path.exists(requirements_path):
                  with open(os.path.join(requirements_path), "w") as f:
                      f.write(gradio_wheel_url)
              else:
                  with open(os.path.join(requirements_path), "r") as f:
                      content = f.read()
                  with open(os.path.join(requirements_path), "w") as f:
                      f.seek(0, 0)
                      f.write(gradio_wheel_url + "\n" + content)
  
          api = huggingface_hub.HfApi()
          huggingface_hub.create_repo(
              space_id,
              space_sdk="gradio",
              repo_type="space",
              token=hf_token,
              exist_ok=True,
          )
          api.upload_folder(
              token=hf_token,
              repo_id=space_id,
              repo_type="space",
              folder_path=tmpdir,
              path_in_repo="",
          )
      return f"https://huggingface.co/spaces/{space_id}"
  
file_path: gradio/scripts/upload_website_demos.py
imports: from __future__ import annotations
  import argparse
  import json
  import os
  import pathlib
  import shutil
  import tempfile
  import textwrap
  import huggingface_hub
label_desc: Use image node_id 1 for calling a global function with example usage: upload_demo_to_space(demo_name, space_id, hf_token, gradio_version, gradio_wheel_url) and returns: str, space_id