Spaces:
Sleeping
Sleeping
Commit
Β·
e7341a0
1
Parent(s):
44fda73
This is frontend
Browse files- check_nids.py +64 -0
check_nids.py
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import requests
|
| 2 |
+
|
| 3 |
+
# Replace with your actual Space URL (remove the / at the end)
|
| 4 |
+
SPACE_URL = "https://codebaseai-ai-nids-backend.hf.space"
|
| 5 |
+
|
| 6 |
+
def run_health_check():
|
| 7 |
+
print(f"π Starting Health Check for: {SPACE_URL}")
|
| 8 |
+
print("-" * 50)
|
| 9 |
+
|
| 10 |
+
routes_to_test = [
|
| 11 |
+
"/api/logs/status",
|
| 12 |
+
"/api/model/active",
|
| 13 |
+
"/api/live",
|
| 14 |
+
"/api/predict",
|
| 15 |
+
"/api/reports"
|
| 16 |
+
]
|
| 17 |
+
|
| 18 |
+
print(f"π Testing {len(routes_to_test)} endpoints...")
|
| 19 |
+
|
| 20 |
+
for route in routes_to_test:
|
| 21 |
+
full_url = f"{SPACE_URL}{route}"
|
| 22 |
+
try:
|
| 23 |
+
# Note: Some routes might need POST, but GET is a good start to check existence
|
| 24 |
+
response = requests.get(full_url, timeout=5)
|
| 25 |
+
status_icon = "β
" if response.status_code < 400 else "β"
|
| 26 |
+
print(f"{status_icon} {response.status_code} - {route}")
|
| 27 |
+
except Exception as e:
|
| 28 |
+
print(f"β οΈ Error reaching {route}: {e}")
|
| 29 |
+
|
| 30 |
+
# 1. Test Root / System Info
|
| 31 |
+
try:
|
| 32 |
+
# Most of your routes are under /api
|
| 33 |
+
res = requests.get(f"{SPACE_URL}/api")
|
| 34 |
+
if res.status_code == 200:
|
| 35 |
+
print("β
API Root: ONLINE")
|
| 36 |
+
print(f" Response: {res.json().get('status', 'No status field')}")
|
| 37 |
+
else:
|
| 38 |
+
print(f"β API Root: FAILED (Status: {res.status_code})")
|
| 39 |
+
except Exception as e:
|
| 40 |
+
print(f"β API Root: UNREACHABLE ({e})")
|
| 41 |
+
|
| 42 |
+
# 2. Test Log Status
|
| 43 |
+
try:
|
| 44 |
+
res = requests.get(f"{SPACE_URL}/api/logs/status?model=bcc")
|
| 45 |
+
if res.status_code == 200:
|
| 46 |
+
print("β
Log System: OPERATIONAL")
|
| 47 |
+
print(f" BCC Stats: {res.json().get('by_class', {})}")
|
| 48 |
+
else:
|
| 49 |
+
print(f"β Log System: ERROR ({res.status_code})")
|
| 50 |
+
except Exception as e:
|
| 51 |
+
print(f"β Log System: FAILED ({e})")
|
| 52 |
+
|
| 53 |
+
# 3. Test Model Switch (Check if logic works)
|
| 54 |
+
try:
|
| 55 |
+
res = requests.get(f"{SPACE_URL}/api/model/active")
|
| 56 |
+
if res.status_code == 200:
|
| 57 |
+
print(f"β
Active Model: {res.json().get('active_model', 'unknown')}")
|
| 58 |
+
else:
|
| 59 |
+
print(f"β οΈ Model API: Non-standard response ({res.status_code})")
|
| 60 |
+
except Exception as e:
|
| 61 |
+
print(f"β Model API: FAILED ({e})")
|
| 62 |
+
|
| 63 |
+
if __name__ == "__main__":
|
| 64 |
+
run_health_check()
|