"""Monitor HF Space health for 1 hour after deployment.""" import requests import time import datetime SPACE_URL = "https://mrwabbit-catalyst-cloud.hf.space/" CHECK_INTERVAL = 120 # seconds (every 2 minutes) TOTAL_DURATION = 3600 # 1 hour start = time.time() checks = 0 failures = 0 print(f"[{datetime.datetime.now():%H:%M:%S}] Starting HF Space monitoring for 1 hour...") print(f"URL: {SPACE_URL}") print(f"Check interval: {CHECK_INTERVAL}s") print("-" * 60) while time.time() - start < TOTAL_DURATION: checks += 1 elapsed = int(time.time() - start) try: r = requests.get(SPACE_URL, timeout=30) status = r.status_code ok = 200 <= status < 400 if ok: print(f"[{datetime.datetime.now():%H:%M:%S}] Check #{checks} ({elapsed//60}m): OK (HTTP {status})") else: failures += 1 print(f"[{datetime.datetime.now():%H:%M:%S}] Check #{checks} ({elapsed//60}m): FAIL (HTTP {status})") except Exception as e: failures += 1 print(f"[{datetime.datetime.now():%H:%M:%S}] Check #{checks} ({elapsed//60}m): ERROR ({e})") time.sleep(CHECK_INTERVAL) print("-" * 60) print(f"Monitoring complete. {checks} checks, {failures} failures.") if failures == 0: print("RESULT: Space is HEALTHY - no issues detected in 1 hour.") else: print(f"RESULT: {failures} failures detected - investigate!")