Spaces:
Running
Running
| import time | |
| import requests | |
| import sys | |
| def test_server(): | |
| base_url = "http://127.0.0.1:8000" | |
| print("β³ Waiting for server to start...") | |
| # Retry logic to wait for server | |
| for i in range(10): | |
| try: | |
| response = requests.get(f"{base_url}/") | |
| if response.status_code == 200: | |
| print("Server detected!") | |
| break | |
| except requests.exceptions.ConnectionError: | |
| time.sleep(1) | |
| print(f"Attempt {i+1}/10: Server not ready yet...") | |
| else: | |
| print("β Error: Server failed to start within 10 seconds.") | |
| sys.exit(1) | |
| # 1. Health Check (Root Endpoint) | |
| print("\nπ Checking Root Endpoint (/) ...") | |
| try: | |
| response = requests.get(f"{base_url}/") | |
| print(f"Status Code: {response.status_code}") | |
| print(f"Response: {response.json()}") | |
| if response.status_code != 200: | |
| print("β Root endpoint check failed!") | |
| sys.exit(1) | |
| except Exception as e: | |
| print(f"β unexpected error on root check: {e}") | |
| sys.exit(1) | |
| # 2. Docs Check (/docs) | |
| print("\nπ Checking Docs Endpoint (/docs) ...") | |
| try: | |
| response = requests.get(f"{base_url}/docs") | |
| print(f"Status Code: {response.status_code}") | |
| if response.status_code == 200: | |
| print("β API Documentation is accessible.") | |
| else: | |
| print(f"β Docs endpoint check failed! Status: {response.status_code}") | |
| sys.exit(1) | |
| except Exception as e: | |
| print(f"β unexpected error on docs check: {e}") | |
| sys.exit(1) | |
| print("\nβ Server is Healthy!") | |
| # 3. Analyze Trends Check (/analyze-trends/{niche}) | |
| print("\nπ Checking Trend Spotter (/analyze-trends/cats) ...") | |
| try: | |
| response = requests.get(f"{base_url}/analyze-trends/cats") | |
| print(f"Status Code: {response.status_code}") | |
| print(f"Response: {response.json()}") | |
| if response.status_code == 200: | |
| print("β Trend Spotter is working!") | |
| else: | |
| print("β Trend Spotter check failed!") | |
| sys.exit(1) | |
| except Exception as e: | |
| print(f"β unexpected error on trend spotter check: {e}") | |
| sys.exit(1) | |
| # 4. Visionary Agent Check (/generate-design) | |
| print("\nπ Checking Visionary Agent (/generate-design) ...") | |
| try: | |
| payload = {"slogan": "Gravity Check", "niche": "Science"} | |
| response = requests.post(f"{base_url}/generate-design", json=payload) | |
| print(f"Status Code: {response.status_code}") | |
| print(f"Response: {response.json()}") | |
| if response.status_code == 200: | |
| print("β Visionary is working!") | |
| else: | |
| print("β Visionary check failed!") | |
| sys.exit(1) | |
| except Exception as e: | |
| print(f"β unexpected error on visionary check: {e}") | |
| sys.exit(1) | |
| # 5. Manager Agent Check (/run-batch) | |
| print("\nπ Checking Manager Agent (/run-batch) ...") | |
| try: | |
| import os | |
| payload = {"niche": "Coffee"} | |
| response = requests.post(f"{base_url}/run-batch", json=payload) | |
| print(f"Status Code: {response.status_code}") | |
| print(f"Response: {response.json()}") | |
| if response.status_code == 200: | |
| filename = response.json().get("filename") | |
| results_path = os.path.join("results", filename) | |
| if os.path.exists(results_path): | |
| print(f"β Manager is working! CSV created at: {results_path}") | |
| else: | |
| print(f"β Batch ran but file not found: {results_path}") | |
| sys.exit(1) | |
| else: | |
| print("β Manager check failed!") | |
| sys.exit(1) | |
| except Exception as e: | |
| print(f"β unexpected error on manager check: {e}") | |
| sys.exit(1) | |
| if __name__ == "__main__": | |
| test_server() | |