Spaces:
Sleeping
Sleeping
| # status_check.py | |
| from typing import Optional, Tuple | |
| import os | |
| import requests | |
| from urllib.parse import urlparse | |
| def resolve_endpoint() -> Optional[str]: | |
| uri = (os.environ.get("HF_ENDPOINT_URI") or "").strip() | |
| if not uri: | |
| return None | |
| p = urlparse(uri) | |
| if p.scheme not in {"http", "https"} or not p.netloc: | |
| # treat bad values like “localhost:8000” (no scheme) as missing | |
| return None | |
| return uri | |
| def is_endpoint_healthy(uri: str, timeout: float = 5.0) -> Tuple[bool, str]: | |
| if not uri: | |
| return False, "No endpoint URI configured." | |
| try: | |
| r = requests.post(uri, json={"inputs": "ping"}, timeout=timeout) | |
| return (True, "OK") if r.ok else (False, f"HTTP {r.status_code}") | |
| except requests.exceptions.RequestException as e: | |
| return False, f"{type(e).__name__}" | |