| | |
| | """ |
| | Check if the deployed Hugging Face Space API has the updated code |
| | """ |
| |
|
| | import requests |
| | import sys |
| |
|
| | def check_deployed_api(api_url): |
| | """Check if the deployed API has the health endpoint and shows correct version""" |
| | |
| | print("=" * 60) |
| | print("CHECKING DEPLOYED API") |
| | print("=" * 60) |
| | print(f"API URL: {api_url}") |
| | print() |
| | |
| | try: |
| | |
| | print("1. Checking /health endpoint...") |
| | response = requests.get(f"{api_url}/health", timeout=10) |
| | |
| | if response.status_code == 200: |
| | data = response.json() |
| | print(" β
API is online!") |
| | print(f" Status: {data.get('status')}") |
| | print(f" Storage: {data.get('storage')}") |
| | print(f" Supabase: {data.get('apis', {}).get('supabase')}") |
| | print() |
| | else: |
| | print(f" β Health check failed: HTTP {response.status_code}") |
| | return False |
| | |
| | |
| | print("2. Checking / endpoint for version...") |
| | response = requests.get(f"{api_url}/", timeout=10) |
| | |
| | if response.status_code == 200: |
| | data = response.json() |
| | print(" β
Root endpoint accessible!") |
| | print(f" Message: {data.get('message')}") |
| | print(f" Version: {data.get('version')}") |
| | print(f" Data Storage: {data.get('data_storage')}") |
| | print() |
| | else: |
| | print(f" β Root endpoint failed: HTTP {response.status_code}") |
| | |
| | |
| | print("3. Testing error handling (this should fail gracefully)...") |
| | print(" Sending invalid submission to check error messages...") |
| | |
| | |
| | test_data = { |
| | 'species_name': 'TEST_SPECIES', |
| | 'location': 'INVALID_LOCATION', |
| | 'species_type': 'plant' |
| | } |
| | |
| | response = requests.post( |
| | f"{api_url}/submit-new-species", |
| | data=test_data, |
| | timeout=10 |
| | ) |
| | |
| | if response.status_code == 400: |
| | error_data = response.json() |
| | print(" β
Error handling works!") |
| | print(f" Error message: {error_data.get('detail')}") |
| | |
| | |
| | if "Invalid location" in error_data.get('detail', ''): |
| | print(" β
NEW CODE DETECTED - Error messages are specific!") |
| | else: |
| | print(" β οΈ OLD CODE - Error messages are generic") |
| | else: |
| | print(f" Status: {response.status_code}") |
| | print(f" Response: {response.text[:200]}") |
| | |
| | print() |
| | print("=" * 60) |
| | print("β
API CHECK COMPLETE") |
| | print("=" * 60) |
| | print() |
| | print("Next steps:") |
| | print("1. If API is online but using old code:") |
| | print(" β Restart the Hugging Face Space") |
| | print("2. If API is offline:") |
| | print(" β Check Hugging Face Space logs for errors") |
| | print("3. Test with a real species submission from the frontend") |
| | print() |
| | |
| | return True |
| | |
| | except requests.exceptions.ConnectionError: |
| | print(" β Connection Error - Cannot reach the API") |
| | print(" β Check if the Hugging Face Space is running") |
| | print(" β Verify the API URL is correct") |
| | return False |
| | except requests.exceptions.Timeout: |
| | print(" β Timeout - API is not responding") |
| | print(" β The Space might be starting up (wait 2-3 minutes)") |
| | return False |
| | except Exception as e: |
| | print(f" β Error: {e}") |
| | return False |
| |
|
| | if __name__ == "__main__": |
| | |
| | api_url = input("Enter your Hugging Face Space API URL (e.g., https://YOUR-USERNAME-YOUR-SPACE.hf.space): ").strip() |
| | |
| | if not api_url: |
| | print("No URL provided. Using example...") |
| | api_url = "http://localhost:7860" |
| | |
| | |
| | api_url = api_url.rstrip('/') |
| | |
| | check_deployed_api(api_url) |
| |
|