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"]
docstr: Ensure every client call is independent
  Also ensure map between api_name and fn_index is updated in case server changed (e.g. restarted with new code)
  Returns:
docstr_tok: ["Ensure","every","client","call","is","independent","Also","ensure","map","between","api_name","and","fn_index","is","updated","in","case","server","changed","(","e.g",".","restarted","with","new","code",")","Returns",":"]
code: def refresh_client(self):
      """
      Ensure every client call is independent
      Also ensure map between api_name and fn_index is updated in case server changed (e.g. restarted with new code)
      Returns:
      """
      if self.config is None:
          self.setup()
  
      kwargs = self.kwargs.copy()
      kwargs.pop("h2ogpt_key", None)
      kwargs.pop("persist", None)
      kwargs.pop("check_hash", None)
      kwargs.pop("check_model_name", None)
      ntrials = 3
      client = None
      for trial in range(0, ntrials + 1):
          try:
              client = Client(*self.args, **kwargs)
          except ValueError as e:
              if trial >= ntrials:
                  raise
              else:
                  if self.verbose:
                      print(
                          "Trying refresh %d/%d %s"
                          % (trial, ntrials - 1, str(e))
                      )
                  trial += 1
                  time.sleep(10)
      if client is None:
          raise RuntimeError("Failed to get new client")
      session_hash0 = self.session_hash if self.persist else None
      for k, v in client.__dict__.items():
          setattr(self, k, v)
      if session_hash0:
          # keep same system hash in case server API only changed and not restarted
          self.session_hash = session_hash0
      if self.verbose:
          print(
              "Hit refresh_client(): %s %s"
              % (self.session_hash, session_hash0)
          )
      # ensure server hash also updated
      self.server_hash = self.get_server_hash()
  
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 7 for calling the GradioClient obj's underlying member method code with example usage: obj.refresh_client() without return types