Spaces:
Paused
Paused
File size: 2,887 Bytes
1d28c11 |
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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
"""
WidgeTDC Cortex - Runtime Log Monitor
Monitors HF Space logs in real-time to verify system health
"""
import time
import requests
from huggingface_hub import HfApi
# Configuration
SPACE_NAME = "widgetdc-cortex"
USERNAME = "Kraft102"
REPO_ID = f"{USERNAME}/{SPACE_NAME}"
SPACE_URL = f"https://{USERNAME.lower()}-{SPACE_NAME}.hf.space"
print("=" * 70)
print(" WIDGETTDC CORTEX - RUNTIME LOG MONITOR")
print("=" * 70)
print()
# Initialize API
api = HfApi()
def check_build_status():
"""Check if Space is running"""
try:
runtime = api.get_space_runtime(repo_id=REPO_ID)
return runtime.stage, runtime.hardware
except Exception as e:
return "UNKNOWN", None
def test_health_endpoint():
"""Test /health endpoint"""
try:
response = requests.get(f"{SPACE_URL}/health", timeout=10)
return response.status_code == 200, response.json() if response.status_code == 200 else None
except Exception as e:
return False, str(e)
def monitor_runtime():
"""Monitor runtime status and logs"""
print("[1/4] Checking Space status...")
stage, hardware = check_build_status()
print(f" Stage: {stage}")
print(f" Hardware: {hardware}")
print()
if stage == "RUNNING":
print("✅ Space is RUNNING!")
print()
print("[2/4] Testing health endpoint...")
healthy, data = test_health_endpoint()
if healthy:
print(f"✅ Health check PASSED!")
print(f" Response: {data}")
else:
print(f"❌ Health check FAILED!")
print(f" Error: {data}")
print()
print("[3/4] Testing API endpoints...")
# Test MCP route
try:
response = requests.post(
f"{SPACE_URL}/api/mcp/route",
json={"method": "initialize", "params": {}},
timeout=10
)
print(f" MCP Route: {response.status_code}")
except Exception as e:
print(f" MCP Route: ERROR - {e}")
print()
print("[4/4] System Health Summary:")
print(" 🟢 Space: RUNNING")
print(f" {'🟢' if healthy else '🔴'} Health: {'OK' if healthy else 'FAILED'}")
print(f" 🔵 URL: {SPACE_URL}")
elif stage == "BUILDING":
print("⏳ Space is still BUILDING...")
print(" Run this script again in 1-2 minutes")
elif stage == "BUILD_ERROR":
print("❌ Space has BUILD_ERROR!")
print(" Check logs at:")
print(f" https://huggingface.co/spaces/{REPO_ID}/logs")
else:
print(f"⚠️ Unknown status: {stage}")
if __name__ == "__main__":
monitor_runtime()
print()
print("=" * 70)
print(" MONITORING COMPLETE")
print("=" * 70)
|