File size: 2,100 Bytes
dcb2a99
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import requests
import os
import time
from datetime import datetime
import sys

def check_space():
    url = "https://huggingface.co/api/spaces/nananie143/Agentic_llm"
    headers = {"Authorization": f"Bearer {os.environ['HUGGINGFACE_TOKEN']}"}
    
    try:
        response = requests.get(url, headers=headers)
        if response.ok:
            data = response.json()
            runtime = data.get('runtime', {})
            stage = runtime.get('stage', 'UNKNOWN')
            hardware = runtime.get('hardware', {})
            domains = runtime.get('domains', [{}])[0]
            
            status_time = datetime.now().strftime('%H:%M:%S')
            sys.stdout.write(f"\n[{status_time}] Space Status:\n")
            sys.stdout.write(f"Stage: {stage}\n")
            sys.stdout.write(f"Hardware: {hardware.get('current', 'Not assigned')} (requested: {hardware.get('requested', 'None')})\n")
            sys.stdout.write(f"Domain: {domains.get('domain', 'Not assigned')} (status: {domains.get('stage', 'Unknown')})\n")
            sys.stdout.flush()
            
            if stage == "RUNNING":
                sys.stdout.write("\n🚀 Space is now running!\n")
                sys.stdout.write(f"Access your Space at: https://{domains.get('domain', 'nananie143-agentic-llm.hf.space')}\n")
                sys.stdout.flush()
                return True
            elif stage == "FAILED":
                sys.stdout.write("\n❌ Space build failed!\n")
                sys.stdout.flush()
                return True
            
            return False
            
    except Exception as e:
        sys.stdout.write(f"\n[{datetime.now().strftime('%H:%M:%S')}] Error checking status: {e}\n")
        sys.stdout.flush()
        return False

sys.stdout.write("\nStarting automatic Space status check...\n")
sys.stdout.write("Will check every 2 minutes until the Space is running or fails...\n")
sys.stdout.write("Press Ctrl+C to stop checking\n\n")
sys.stdout.flush()

while True:
    should_stop = check_space()
    if should_stop:
        break
    time.sleep(120)  # Wait 2 minutes