File size: 1,223 Bytes
f1760b4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
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)