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)