File size: 1,704 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
55
56
from huggingface_hub import HfApi
import time
import os
import requests

def check_space_status():
    api = HfApi()
    space_name = "nananie143/Agentic_llm"
    
    try:
        # First try direct API request
        response = requests.get(
            f"https://huggingface.co/api/spaces/{space_name}/runtime",
            headers={"Authorization": f"Bearer {os.environ['HUGGINGFACE_TOKEN']}"}
        )
        print(f"\nAPI Response Status: {response.status_code}")
        if response.ok:
            data = response.json()
            print(f"Space Info: {data}")
            return data.get("stage")
            
        # Fallback to HF API
        space_info = api.space_info(space_name)
        print(f"\nSpace Info via HF API: {space_info}")
        
        if hasattr(space_info, 'runtime'):
            status = space_info.runtime.stage
            print(f"Status: {status}")
            return status
        
        print("No status information available")
        return None
        
    except Exception as e:
        print(f"Error checking status: {e}")
        return None

print("Starting Space status check...")
print("Will check every 30 seconds until the Space is running...")

while True:
    status = check_space_status()
    print(f"Current status: {status}")
    
    if status == "RUNNING":
        print("\nSpace is now running! ")
        print(f"Access your Space at: https://huggingface.co/spaces/nananie143/Agentic_llm")
        break
    elif status == "FAILED":
        print("\nSpace build failed! Please check the logs for details.")
        break
    elif status is None:
        print("\nCouldn't determine status. Will try again...")
    
    time.sleep(30)