| import os |
| import sys |
| from huggingface_hub import HfApi |
|
|
| def observe_space_runtime(space_name: str = "Demo", hf_token: str = None): |
| token = hf_token or os.getenv("HF_TOKEN") |
| api = HfApi(token=token) |
|
|
| try: |
| user_info = api.whoami(token=token) |
| username = user_info['name'] |
| except Exception as e: |
| print(f"[!] Auth Error: {e}") |
| return |
|
|
| repo_id = f"{username}/{space_name}" |
| print(f"[*] Observing Space Runtime for: '{repo_id}'...") |
|
|
| try: |
| runtime = api.get_space_runtime(repo_id=repo_id) |
| print("--------------------------------------------------") |
| print(f"[*] Stage: {runtime.stage}") |
| print(f"[*] Hardware: {runtime.hardware or 'Allocating...'}") |
| print(f"[*] Requested: {runtime.requested_hardware}") |
| print(f"[*] Raw Status: {runtime.raw if hasattr(runtime, 'raw') else 'N/A'}") |
| print("--------------------------------------------------") |
| except Exception as e: |
| print(f"[!] Error fetching runtime metadata: {e}") |
|
|
| if __name__ == "__main__": |
| token = os.getenv("HF_TOKEN") |
| space_name = sys.argv[1] if len(sys.argv) > 1 else "Demo" |
| observe_space_runtime(space_name, hf_token=token) |
|
|