Pendrokar commited on
Commit
2e114a1
1 Parent(s): 9ba8b9d

save Gradio Clients to var

Browse files
Files changed (1) hide show
  1. app.py +6 -5
app.py CHANGED
@@ -1023,15 +1023,16 @@ def synthandreturn(text, request: gr.Request):
1023
  hf_headers = {"X-IP-Token": request.headers['x-ip-token']}
1024
  except:
1025
  pass
1026
- # 3 attempts
 
1027
  attempt_count = 0
1028
  while attempt_count < 2:
1029
  try:
1030
  if model in AVAILABLE_MODELS:
1031
  if '/' in model:
1032
  # Use public HF Space
1033
- #if (model not in hf_clients):
1034
- hf_clients[model] = Client(model, hf_token=hf_token, headers=hf_headers)
1035
  mdl_space = hf_clients[model]
1036
 
1037
  # print(f"{model}: Fetching endpoints of HF Space")
@@ -1085,12 +1086,12 @@ def synthandreturn(text, request: gr.Request):
1085
  attempt_count += 1
1086
  print(repr(e))
1087
  print(f"{model}: Unable to call API (attempt: {attempt_count})")
1088
- # sleep for three seconds
1089
  time.sleep(3)
1090
 
1091
  # Fetch and store client again
1092
  hf_headers = {}
1093
- #hf_clients[model] = Client(model, hf_token=hf_token)
1094
 
1095
  if attempt_count > 2:
1096
  raise gr.Error(f"{model}: Failed to call model")
 
1023
  hf_headers = {"X-IP-Token": request.headers['x-ip-token']}
1024
  except:
1025
  pass
1026
+
1027
+ # 2 attempts
1028
  attempt_count = 0
1029
  while attempt_count < 2:
1030
  try:
1031
  if model in AVAILABLE_MODELS:
1032
  if '/' in model:
1033
  # Use public HF Space
1034
+ if (model not in hf_clients):
1035
+ hf_clients[model] = Client(model, hf_token=hf_token, headers=hf_headers)
1036
  mdl_space = hf_clients[model]
1037
 
1038
  # print(f"{model}: Fetching endpoints of HF Space")
 
1086
  attempt_count += 1
1087
  print(repr(e))
1088
  print(f"{model}: Unable to call API (attempt: {attempt_count})")
1089
+ # sleep for three seconds to avoid spamming the server with requests
1090
  time.sleep(3)
1091
 
1092
  # Fetch and store client again
1093
  hf_headers = {}
1094
+ hf_clients[model] = Client(model, hf_token=hf_token)
1095
 
1096
  if attempt_count > 2:
1097
  raise gr.Error(f"{model}: Failed to call model")