Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
improve security on hf token check
Browse files
backend/tasks/get_available_model_provider.py
CHANGED
@@ -333,9 +333,8 @@ def test_models(verbose=True):
|
|
333 |
if not hf_token.startswith("hf_"):
|
334 |
print("⚠️ WARNING: Your HF_TOKEN does not start with 'hf_' which is unusual. Please verify its format.")
|
335 |
|
336 |
-
#
|
337 |
-
|
338 |
-
masked_token = hf_token[:visible_chars] + "*" * (len(hf_token) - visible_chars * 2) + hf_token[-visible_chars:]
|
339 |
|
340 |
# Vérifier la validité du token en testant directement l'API d'inférence
|
341 |
import requests
|
@@ -344,7 +343,7 @@ def test_models(verbose=True):
|
|
344 |
test_model = "gpt2"
|
345 |
api_url = f"https://api-inference.huggingface.co/models/{test_model}"
|
346 |
|
347 |
-
print(f"Testing token
|
348 |
|
349 |
headers = {"Authorization": f"Bearer {hf_token}"}
|
350 |
payload = {"inputs": "Hello, how are you?"}
|
|
|
333 |
if not hf_token.startswith("hf_"):
|
334 |
print("⚠️ WARNING: Your HF_TOKEN does not start with 'hf_' which is unusual. Please verify its format.")
|
335 |
|
336 |
+
# Ne montrer aucun caractère du token, juste indiquer sa présence
|
337 |
+
masked_token = "••••••••••"
|
|
|
338 |
|
339 |
# Vérifier la validité du token en testant directement l'API d'inférence
|
340 |
import requests
|
|
|
343 |
test_model = "gpt2"
|
344 |
api_url = f"https://api-inference.huggingface.co/models/{test_model}"
|
345 |
|
346 |
+
print(f"Testing token with inference API on public model {test_model}...")
|
347 |
|
348 |
headers = {"Authorization": f"Bearer {hf_token}"}
|
349 |
payload = {"inputs": "Hello, how are you?"}
|
backend/tests/check_hf_token.py
CHANGED
@@ -69,9 +69,8 @@ def check_token_via_inference_api(token=None, verbose=True):
|
|
69 |
results["error_message"] = "No token provided"
|
70 |
return results
|
71 |
|
72 |
-
#
|
73 |
-
|
74 |
-
masked_token = token[:visible_chars] + "*" * (len(token) - visible_chars * 2) + token[-visible_chars:]
|
75 |
results["token"] = masked_token
|
76 |
|
77 |
print(info(f"Token à vérifier: {masked_token}"))
|
|
|
69 |
results["error_message"] = "No token provided"
|
70 |
return results
|
71 |
|
72 |
+
# Ne montrer aucun caractère du token, juste indiquer sa présence
|
73 |
+
masked_token = "••••••••••"
|
|
|
74 |
results["token"] = masked_token
|
75 |
|
76 |
print(info(f"Token à vérifier: {masked_token}"))
|