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

HF client: reattach headers on retry

Browse files
Files changed (1) hide show
  1. app.py +6 -6
app.py CHANGED
@@ -339,7 +339,7 @@ OVERRIDE_INPUTS = {
339
  },
340
  }
341
 
342
- hf_clients = {}
343
  # cache audio samples for quick voting
344
  cached_samples: List[Sample] = []
345
  voting_users = {
@@ -1059,9 +1059,10 @@ def synthandreturn(text, request: gr.Request):
1059
  end_parameters = _get_param_examples(
1060
  endpoints['unnamed_endpoints'][str(fn_index)]['parameters']
1061
  )
1062
-
 
1063
  space_inputs = _override_params(end_parameters, model)
1064
-
1065
  # force text
1066
  space_inputs[HF_SPACES[model]['text_param_index']] = text
1067
 
@@ -1090,8 +1091,7 @@ def synthandreturn(text, request: gr.Request):
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")
@@ -1596,5 +1596,5 @@ with gr.Blocks(theme=theme, css="footer {visibility: hidden}textbox{resize:none}
1596
 
1597
 
1598
  demo\
1599
- .queue(api_open=False, default_concurrency_limit=3)\
1600
  .launch(show_api=False, show_error=True)
 
339
  },
340
  }
341
 
342
+ hf_clients: Tuple[Client] = {}
343
  # cache audio samples for quick voting
344
  cached_samples: List[Sample] = []
345
  voting_users = {
 
1059
  end_parameters = _get_param_examples(
1060
  endpoints['unnamed_endpoints'][str(fn_index)]['parameters']
1061
  )
1062
+
1063
+ # override some or all default parameters
1064
  space_inputs = _override_params(end_parameters, model)
1065
+
1066
  # force text
1067
  space_inputs[HF_SPACES[model]['text_param_index']] = text
1068
 
 
1091
  time.sleep(3)
1092
 
1093
  # Fetch and store client again
1094
+ hf_clients[model] = Client(model, hf_token=hf_token, headers=hf_headers)
 
1095
 
1096
  if attempt_count > 2:
1097
  raise gr.Error(f"{model}: Failed to call model")
 
1596
 
1597
 
1598
  demo\
1599
+ .queue(api_open=False, default_concurrency_limit=4)\
1600
  .launch(show_api=False, show_error=True)