import requests import json import time import subprocess import sys # Start API in background print("Starting API...") api_process = subprocess.Popen([sys.executable, "src/inference/app.py"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) # Wait for startup time.sleep(5) url = "http://localhost:5000/predict" # Test Case 1: CT Advantage (3v1, high health) payload_ct_win = { "game_time": 60.0, "players": [ {"team_num": 3, "is_alive": True, "health": 100}, {"team_num": 3, "is_alive": True, "health": 100}, {"team_num": 3, "is_alive": True, "health": 90}, {"team_num": 2, "is_alive": True, "health": 50} ] } # Test Case 2: T Advantage (1v3) payload_t_win = { "game_time": 45.0, "players": [ {"team_num": 3, "is_alive": True, "health": 10}, {"team_num": 2, "is_alive": True, "health": 100}, {"team_num": 2, "is_alive": True, "health": 100}, {"team_num": 2, "is_alive": True, "health": 100} ] } def test_payload(name, payload): print(f"\n--- Testing {name} ---") try: response = requests.post(url, json=payload, timeout=2) print("Status Code:", response.status_code) if response.status_code == 200: print("Response:", json.dumps(response.json(), indent=2)) else: print("Error:", response.text) except Exception as e: print(f"Request failed: {e}") try: test_payload("CT Advantage Scenario", payload_ct_win) test_payload("T Advantage Scenario", payload_t_win) finally: print("\nStopping API...") api_process.terminate() try: outs, errs = api_process.communicate(timeout=2) print("API Output:", outs.decode()) print("API Errors:", errs.decode()) except: api_process.kill()