Spaces:
Sleeping
Sleeping
Make resolve_endpoint return None for blank values
Browse files- status_check.py +11 -2
status_check.py
CHANGED
|
@@ -3,10 +3,19 @@
|
|
| 3 |
from typing import Optional, Tuple
|
| 4 |
import os
|
| 5 |
import requests
|
|
|
|
| 6 |
|
|
|
|
| 7 |
def resolve_endpoint() -> Optional[str]:
|
| 8 |
-
|
| 9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
def is_endpoint_healthy(uri: str, timeout: float = 5.0) -> Tuple[bool, str]:
|
| 12 |
if not uri:
|
|
|
|
| 3 |
from typing import Optional, Tuple
|
| 4 |
import os
|
| 5 |
import requests
|
| 6 |
+
from urllib.parse import urlparse
|
| 7 |
|
| 8 |
+
|
| 9 |
def resolve_endpoint() -> Optional[str]:
|
| 10 |
+
uri = (os.environ.get("HF_ENDPOINT_URI") or "").strip()
|
| 11 |
+
if not uri:
|
| 12 |
+
return None
|
| 13 |
+
p = urlparse(uri)
|
| 14 |
+
if p.scheme not in {"http", "https"} or not p.netloc:
|
| 15 |
+
# treat bad values like “localhost:8000” (no scheme) as missing
|
| 16 |
+
return None
|
| 17 |
+
return uri
|
| 18 |
+
|
| 19 |
|
| 20 |
def is_endpoint_healthy(uri: str, timeout: float = 5.0) -> Tuple[bool, str]:
|
| 21 |
if not uri:
|