Spaces:
Sleeping
Sleeping
| import time | |
| import requests | |
| import sys | |
| API_URL = "https://loomisgitarrist-personal-coder-ai.hf.space" | |
| def check_status(): | |
| print(f"Checking status of {API_URL}...") | |
| # 1. Check Runtime Status API | |
| try: | |
| runtime_resp = requests.get(f"https://huggingface.co/api/spaces/Loomisgitarrist/personal-coder-ai/runtime") | |
| print(f"Runtime Info: {runtime_resp.text}") | |
| if "RUNNING" in runtime_resp.text: | |
| print(">>> SPACE IS RUNNING! <<<") | |
| return True | |
| elif "BUILD_ERROR" in runtime_resp.text: | |
| print("!!! BUILD ERROR DETECTED !!!") | |
| return False | |
| except Exception as e: | |
| print(f"Runtime check failed: {e}") | |
| # 2. Check Application Endpoint | |
| try: | |
| resp = requests.get(f"{API_URL}/") | |
| print(f"Root Endpoint Status: {resp.status_code}") | |
| if resp.status_code == 200: | |
| print("Root endpoint is reachable.") | |
| except Exception as e: | |
| print(f"Root check failed: {e}") | |
| return False | |
| if __name__ == "__main__": | |
| while True: | |
| is_running = check_status() | |
| if is_running: | |
| # Try a test prompt | |
| try: | |
| print("Attempting test prompt...") | |
| test_resp = requests.get(f"{API_URL}/ask", params={"prompt": "Hello"}) | |
| print(f"Test Prompt Response ({test_resp.status_code}): {test_resp.text}") | |
| if test_resp.status_code == 200: | |
| print("SUCCESS: API is fully functional.") | |
| break | |
| except Exception as e: | |
| print(f"Test prompt failed: {e}") | |
| print("Waiting 30 seconds...\n") | |
| time.sleep(30) | |