Spaces:
Sleeping
Sleeping
| import requests | |
| import time | |
| # The URL of your Hugging Face Space | |
| API_URL = "https://loomisgitarrist-personal-coder-ai.hf.space" | |
| def test_api(): | |
| print(f"Testing API at: {API_URL}") | |
| # 0. Reset Memory (Ensure clean state) | |
| print("0. Resetting Memory...") | |
| try: | |
| reset_response = requests.get(f"{API_URL}/reset", timeout=10) | |
| if reset_response.status_code == 200: | |
| print("β Memory Reset Successful") | |
| else: | |
| print(f"β οΈ Memory Reset Failed: {reset_response.status_code}") | |
| except Exception as e: | |
| print(f"β οΈ Memory Reset Error: {e}") | |
| # 1. Check UI | |
| print("\n1. Checking UI availability...") | |
| try: | |
| ui_response = requests.get(API_URL, timeout=10) | |
| if ui_response.status_code == 200 and "<html" in ui_response.text.lower(): | |
| print("β UI is Live and serving HTML!") | |
| else: | |
| print(f"β UI check failed: Status {ui_response.status_code}") | |
| except Exception as e: | |
| print(f"β UI check error: {e}") | |
| # 2. Check API & Memory | |
| endpoint = f"{API_URL}/ask" | |
| print(f"\n2. Testing API & Memory at: {endpoint}") | |
| # Step A: Establish Context | |
| prompt1 = "My name is Captain Loomis." | |
| print(f"Step A: Sending prompt: '{prompt1}'...") | |
| try: | |
| response1 = requests.get(endpoint, params={"prompt": prompt1}, timeout=30) | |
| if response1.status_code == 200: | |
| print(f"β Response 1: {response1.json()['generated_text']}") | |
| else: | |
| print(f"β Error 1: {response1.status_code} - {response1.text}") | |
| return | |
| except Exception as e: | |
| print(f"β Error: {e}") | |
| return | |
| # Step B: Test Memory | |
| prompt2 = "What is my name?" | |
| print(f"\nStep B: Sending prompt: '{prompt2}' (Checking memory)...") | |
| try: | |
| response2 = requests.get(endpoint, params={"prompt": prompt2}, timeout=30) | |
| if response2.status_code == 200: | |
| answer = response2.json()['generated_text'] | |
| print(f"β Response 2: {answer}") | |
| if "Loomis" in answer: | |
| print("\nπ SUCCESS: The AI remembered your name!") | |
| else: | |
| print("\nβ οΈ WARNING: The AI might have forgotten. Memory check inconclusive.") | |
| else: | |
| print(f"β Error 2: {response2.status_code} - {response2.text}") | |
| except Exception as e: | |
| print(f"β Error: {e}") | |
| if __name__ == "__main__": | |
| test_api() | |