#!/usr/bin/env python3 """ Monitor HF Space deployment until it's running and working """ import requests import time import sys SPACE_API_URL = "https://huggingface.co/api/spaces/hirthickraj2015/graphwiz-ireland" SPACE_URL = "https://hirthickraj2015-graphwiz-ireland.hf.space" MAX_WAIT_TIME = 900 # 15 minutes max CHECK_INTERVAL = 30 # Check every 30 seconds def check_status(): """Check current status and return (status, is_ready)""" try: # Check Space API response = requests.get(SPACE_API_URL, timeout=10) if response.status_code == 200: data = response.json() runtime = data.get('runtime', {}) status = runtime.get('stage', 'unknown') # Check if running if status == 'RUNNING': # Also verify endpoint responds correctly try: app_response = requests.get(SPACE_URL, timeout=30) if app_response.status_code == 200: return status, True except: pass return status, False return 'error', False except Exception as e: return f'error: {e}', False def main(): """Monitor deployment until ready or timeout""" print("🍀 Monitoring GraphWiz Ireland deployment...") print(f"Space: https://huggingface.co/spaces/hirthickraj2015/graphwiz-ireland") print(f"Will check every {CHECK_INTERVAL}s for up to {MAX_WAIT_TIME//60} minutes\n") start_time = time.time() last_status = None while True: elapsed = time.time() - start_time if elapsed > MAX_WAIT_TIME: print(f"\n❌ Timeout after {MAX_WAIT_TIME//60} minutes") print("Please check the Space logs for errors:") print("https://huggingface.co/spaces/hirthickraj2015/graphwiz-ireland/logs") sys.exit(1) status, is_ready = check_status() # Show status update if changed if status != last_status: timestamp = time.strftime("%H:%M:%S") print(f"[{timestamp}] Status: {status}") last_status = status if is_ready: print(f"\n✅ Deployment successful! (took {int(elapsed)}s)") print(f"\n🎉 App is running at: {SPACE_URL}") return True # Show progress sys.stdout.write(f"\r⏳ Waiting... ({int(elapsed)}s elapsed)") sys.stdout.flush() time.sleep(CHECK_INTERVAL) if __name__ == "__main__": try: success = main() sys.exit(0 if success else 1) except KeyboardInterrupt: print("\n\nMonitoring cancelled by user") sys.exit(1)