Spaces:
Running
Running
save Gradio Clients to var
Browse files
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 |
-
|
|
|
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 |
-
|
1034 |
-
|
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 |
-
|
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")
|