import requests import json import time import sys import os # Add root directory to sys.path for absolute imports sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) # Target URL (can be changed to your HF Space URL) BASE_URL = "http://localhost:7860" def run_checks(): print(f"--- Starting Pre-Submission Validation on {BASE_URL} ---") # 1. Check /tasks try: resp = requests.get(f"{BASE_URL}/tasks") if resp.status_code == 200: data = resp.json() print("[PASS] /tasks returned 200") if "action_schema" in data: print("[PASS] Action schema found in /tasks") else: print("[FAIL] Action schema missing from /tasks") else: print(f"[FAIL] /tasks returned {resp.status_code}") except Exception as e: print(f"[ERROR] Could not reach /tasks: {e}") # 2. Check /reset try: resp = requests.post(f"{BASE_URL}/reset") if resp.status_code == 200: print("[PASS] /reset returned 200 and initial state") else: print(f"[FAIL] /reset returned {resp.status_code}") except Exception as e: print(f"[ERROR] Could not reach /reset: {e}") # 3. Check /baseline try: print("Checking /baseline (this may take 20-30 seconds)...") resp = requests.get(f"{BASE_URL}/baseline") if resp.status_code == 200: data = resp.json() print(f"[PASS] /baseline returned 200. Final Grade: {data.get('final_grade', 'N/A')}") else: print(f"[FAIL] /baseline returned {resp.status_code}") except Exception as e: print(f"[ERROR] Could not reach /baseline: {e}") # 4. Check /grader try: resp = requests.get(f"{BASE_URL}/grader") if resp.status_code == 200: print("[PASS] /grader returned 200") else: print(f"[FAIL] /grader returned {resp.status_code}") except Exception as e: print(f"[ERROR] Could not reach /grader: {e}") print("\n--- Validation Complete ---") if __name__ == "__main__": run_checks()