class_docstr: Parent class of gradio client
  To handle automatically refreshing client if detect gradio server changed
class_docstr_tok: ["Parent","class","of","gradio","client","To","handle","automatically","refreshing","client","if","detect","gradio","server","changed"]
code: def setup(self):
      src = self.src
  
      self.headers = build_hf_headers(
          token=self.hf_token,
          library_name="gradio_client",
          library_version=utils.__version__,
      )
      # self.headers.pop('authorization', None)  # else get illegal Bearer for old servers
      if src.startswith("http://") or src.startswith("https://"):
          _src = src if src.endswith("/") else src + "/"
      else:
          _src = self._space_name_to_src(src)
          if _src is None:
              raise ValueError(
                  f"Could not find Space: {src}. If it is a private Space, please provide an hf_token."
              )
          self.space_id = src
      self.src = _src
      state = self._get_space_state()
      if state == SpaceStage.BUILDING:
          if self.verbose:
              print("Space is still building. Please wait...")
          while self._get_space_state() == SpaceStage.BUILDING:
              time.sleep(2)  # so we don't get rate limited by the API
              pass
      if state in utils.INVALID_RUNTIME:
          raise ValueError(
              f"The current space is in the invalid state: {state}. "
              "Please contact the owner to fix this."
          )
      if self.verbose:
          print(f"Loaded as API: {self.src} ✔")
  
      if is_gradio_client_version7:
          if self.auth is not None:
              self._login(self.auth)
  
      self.api_url = urllib.parse.urljoin(self.src, utils.API_URL)
      if is_gradio_client_version7:
          self.sse_url = urllib.parse.urljoin(self.src, utils.SSE_URL)
          self.sse_data_url = urllib.parse.urljoin(
              self.src, utils.SSE_DATA_URL
          )
      self.ws_url = urllib.parse.urljoin(
          self.src.replace("http", "ws", 1), utils.WS_URL
      )
      self.upload_url = urllib.parse.urljoin(self.src, utils.UPLOAD_URL)
      self.reset_url = urllib.parse.urljoin(self.src, utils.RESET_URL)
      self.config = self._get_config()
      if is_gradio_client_version7:
          self.protocol: str = self.config.get("protocol", "ws")
          self.app_version = version.parse(
              self.config.get("version", "2.0")
          )
          self._info = self._get_api_info()
      self.session_hash = str(uuid.uuid4())
  
      if is_gradio_client_version7:
          from gradio_client.client import EndpointV3Compatibility
  
          endpoint_class = (
              Endpoint
              if self.protocol.startswith("sse")
              else EndpointV3Compatibility
          )
      else:
          endpoint_class = Endpoint
  
      if is_gradio_client_version7:
          self.endpoints = [
              endpoint_class(self, fn_index, dependency, self.protocol)
              for fn_index, dependency in enumerate(
                  self.config["dependencies"]
              )
          ]
      else:
          self.endpoints = [
              endpoint_class(self, fn_index, dependency)
              for fn_index, dependency in enumerate(
                  self.config["dependencies"]
              )
          ]
  
      # Create a pool of threads to handle the requests
      self.executor = concurrent.futures.ThreadPoolExecutor(
          max_workers=self.max_workers
      )
  
      # Disable telemetry by setting the env variable HF_HUB_DISABLE_TELEMETRY=1
      # threading.Thread(target=self._telemetry_thread).start()
  
      self.server_hash = self.get_server_hash()
  
      if is_gradio_client_version7:
          self.stream_open = False
          self.streaming_future: Future | None = None
          from gradio_client.utils import Message
  
          self.pending_messages_per_event: dict[
              str, list[Message | None]
          ] = {}
          self.pending_event_ids: set[str] = set()
  
      return self
  
imports: from __future__ import annotations
  import difflib
  import traceback
  import concurrent.futures
  import os
  import concurrent.futures
  import time
  import urllib.parse
  import uuid
  from concurrent.futures import Future
  from datetime import timedelta
  from enum import Enum
  from pathlib import Path
  from typing import Callable, Generator, Any, Union, List
  import ast
  from packaging import version
  from huggingface_hub import SpaceStage
  from huggingface_hub.utils import build_hf_headers
  from gradio_client import utils
  from importlib.metadata import distribution, PackageNotFoundError
  from gradio_client.client import Job, DEFAULT_TEMP_DIR, Endpoint
  from gradio_client import Client
label_desc: Use image node_id 4 for calling the GradioClient obj's underlying member method code with example usage: obj.setup() and returns: self