Spaces:
Running
Running
x-ip-token for Zero-GPU; retry HF Space connection only once
Browse files
app.py
CHANGED
@@ -997,17 +997,21 @@ def synthandreturn(text, request: gr.Request):
|
|
997 |
# log_text(text)
|
998 |
print("[debug] Using", mdl1, mdl2)
|
999 |
def predict_and_update_result(text, model, result_storage, request:gr.Request):
|
1000 |
-
|
1001 |
-
|
|
|
|
|
|
|
|
|
1002 |
# 3 attempts
|
1003 |
attempt_count = 0
|
1004 |
-
while attempt_count <
|
1005 |
try:
|
1006 |
if model in AVAILABLE_MODELS:
|
1007 |
if '/' in model:
|
1008 |
# Use public HF Space
|
1009 |
#if (model not in hf_clients):
|
1010 |
-
hf_clients[model] = Client(model, hf_token=hf_token, headers=
|
1011 |
mdl_space = hf_clients[model]
|
1012 |
|
1013 |
# print(f"{model}: Fetching endpoints of HF Space")
|
@@ -1065,6 +1069,7 @@ def synthandreturn(text, request: gr.Request):
|
|
1065 |
time.sleep(3)
|
1066 |
|
1067 |
# Fetch and store client again
|
|
|
1068 |
#hf_clients[model] = Client(model, hf_token=hf_token)
|
1069 |
|
1070 |
if attempt_count > 2:
|
|
|
997 |
# log_text(text)
|
998 |
print("[debug] Using", mdl1, mdl2)
|
999 |
def predict_and_update_result(text, model, result_storage, request:gr.Request):
|
1000 |
+
|
1001 |
+
hf_headers = {}
|
1002 |
+
try:
|
1003 |
+
hf_headers = {"X-IP-Token": request.headers['x-ip-token']}
|
1004 |
+
except:
|
1005 |
+
pass
|
1006 |
# 3 attempts
|
1007 |
attempt_count = 0
|
1008 |
+
while attempt_count < 2:
|
1009 |
try:
|
1010 |
if model in AVAILABLE_MODELS:
|
1011 |
if '/' in model:
|
1012 |
# Use public HF Space
|
1013 |
#if (model not in hf_clients):
|
1014 |
+
hf_clients[model] = Client(model, hf_token=hf_token, headers=hf_headers)
|
1015 |
mdl_space = hf_clients[model]
|
1016 |
|
1017 |
# print(f"{model}: Fetching endpoints of HF Space")
|
|
|
1069 |
time.sleep(3)
|
1070 |
|
1071 |
# Fetch and store client again
|
1072 |
+
hf_headers = {}
|
1073 |
#hf_clients[model] = Client(model, hf_token=hf_token)
|
1074 |
|
1075 |
if attempt_count > 2:
|