Spaces:
Sleeping
Sleeping
File size: 2,261 Bytes
e7341a0 |
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 |
import requests
# Replace with your actual Space URL (remove the / at the end)
SPACE_URL = "https://codebaseai-ai-nids-backend.hf.space"
def run_health_check():
print(f"π Starting Health Check for: {SPACE_URL}")
print("-" * 50)
routes_to_test = [
"/api/logs/status",
"/api/model/active",
"/api/live",
"/api/predict",
"/api/reports"
]
print(f"π Testing {len(routes_to_test)} endpoints...")
for route in routes_to_test:
full_url = f"{SPACE_URL}{route}"
try:
# Note: Some routes might need POST, but GET is a good start to check existence
response = requests.get(full_url, timeout=5)
status_icon = "β
" if response.status_code < 400 else "β"
print(f"{status_icon} {response.status_code} - {route}")
except Exception as e:
print(f"β οΈ Error reaching {route}: {e}")
# 1. Test Root / System Info
try:
# Most of your routes are under /api
res = requests.get(f"{SPACE_URL}/api")
if res.status_code == 200:
print("β
API Root: ONLINE")
print(f" Response: {res.json().get('status', 'No status field')}")
else:
print(f"β API Root: FAILED (Status: {res.status_code})")
except Exception as e:
print(f"β API Root: UNREACHABLE ({e})")
# 2. Test Log Status
try:
res = requests.get(f"{SPACE_URL}/api/logs/status?model=bcc")
if res.status_code == 200:
print("β
Log System: OPERATIONAL")
print(f" BCC Stats: {res.json().get('by_class', {})}")
else:
print(f"β Log System: ERROR ({res.status_code})")
except Exception as e:
print(f"β Log System: FAILED ({e})")
# 3. Test Model Switch (Check if logic works)
try:
res = requests.get(f"{SPACE_URL}/api/model/active")
if res.status_code == 200:
print(f"β
Active Model: {res.json().get('active_model', 'unknown')}")
else:
print(f"β οΈ Model API: Non-standard response ({res.status_code})")
except Exception as e:
print(f"β Model API: FAILED ({e})")
if __name__ == "__main__":
run_health_check() |