Spaces:
Running on Zero
Running on Zero
Arjunvir Singh commited on
Commit ·
7d895f8
1
Parent(s): 1ed7c9f
Extend diagnose_runtime: whoami + Pro tier check
Browse files
app.py
CHANGED
|
@@ -518,10 +518,32 @@ def diagnose_runtime() -> dict:
|
|
| 518 |
import spaces # type: ignore
|
| 519 |
|
| 520 |
info["spaces_sdk_available"] = True
|
| 521 |
-
info["spaces_sdk_attrs"] = [a for a in dir(spaces) if not a.startswith("_")][:20]
|
| 522 |
except ImportError:
|
| 523 |
info["spaces_sdk_available"] = False
|
| 524 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 525 |
return info
|
| 526 |
|
| 527 |
|
|
|
|
| 518 |
import spaces # type: ignore
|
| 519 |
|
| 520 |
info["spaces_sdk_available"] = True
|
|
|
|
| 521 |
except ImportError:
|
| 522 |
info["spaces_sdk_available"] = False
|
| 523 |
|
| 524 |
+
# Authenticate the token against HF Hub to see which user it resolves to
|
| 525 |
+
# and whether Pro is recognized. This is the actual auth ZeroGPU does.
|
| 526 |
+
token_value = next((os.environ.get(v) for v in token_vars if os.environ.get(v)), None)
|
| 527 |
+
if token_value:
|
| 528 |
+
import urllib.request, json as _json
|
| 529 |
+
try:
|
| 530 |
+
req = urllib.request.Request(
|
| 531 |
+
"https://huggingface.co/api/whoami-v2",
|
| 532 |
+
headers={"Authorization": f"Bearer {token_value}"},
|
| 533 |
+
)
|
| 534 |
+
with urllib.request.urlopen(req, timeout=15) as resp:
|
| 535 |
+
whoami = _json.loads(resp.read().decode("utf-8"))
|
| 536 |
+
# Cherry-pick non-sensitive fields.
|
| 537 |
+
info["whoami_name"] = whoami.get("name")
|
| 538 |
+
info["whoami_type"] = whoami.get("type")
|
| 539 |
+
info["whoami_isPro"] = whoami.get("isPro")
|
| 540 |
+
info["whoami_canPay"] = whoami.get("canPay")
|
| 541 |
+
info["whoami_periodEnd"] = whoami.get("periodEnd")
|
| 542 |
+
info["whoami_auth_type"] = (whoami.get("auth") or {}).get("type")
|
| 543 |
+
info["whoami_auth_role"] = (whoami.get("auth") or {}).get("accessToken", {}).get("role")
|
| 544 |
+
except Exception as exc:
|
| 545 |
+
info["whoami_error"] = str(exc)
|
| 546 |
+
|
| 547 |
return info
|
| 548 |
|
| 549 |
|