Spaces:
Sleeping
Sleeping
| #!/usr/bin/env python3 | |
| """ | |
| Test script to verify GraphWiz Ireland deployment on HF Spaces | |
| """ | |
| import requests | |
| import time | |
| # Configuration | |
| SPACE_URL = "https://hirthickraj2015-graphwiz-ireland.hf.space" | |
| SPACE_API_URL = "https://huggingface.co/api/spaces/hirthickraj2015/graphwiz-ireland" | |
| DATASET_URL = "https://huggingface.co/api/datasets/hirthickraj2015/graphwiz-ireland-dataset" | |
| def check_space_status(): | |
| """Check if the Space is running""" | |
| print("=" * 60) | |
| print("π Checking HF Space Status") | |
| print("=" * 60) | |
| try: | |
| response = requests.get(SPACE_API_URL, timeout=10) | |
| if response.status_code == 200: | |
| data = response.json() | |
| runtime = data.get('runtime', {}) | |
| status = runtime.get('stage', 'unknown') | |
| print(f"β Space found: {data.get('id')}") | |
| print(f"β Status: {status}") | |
| print(f"β SDK: {data.get('sdk', 'unknown')}") | |
| if status == 'RUNNING': | |
| print("β Space is RUNNING!") | |
| return True | |
| elif status in ['BUILDING', 'STARTING_BUILD']: | |
| print("β³ Space is building... (this may take 10-15 minutes on first run)") | |
| return False | |
| else: | |
| print(f"β οΈ Unexpected status: {status}") | |
| return False | |
| else: | |
| print(f"β Could not fetch Space status (HTTP {response.status_code})") | |
| return False | |
| except Exception as e: | |
| print(f"β Error checking Space status: {e}") | |
| return False | |
| def check_dataset(): | |
| """Verify dataset repository exists""" | |
| print("\n" + "=" * 60) | |
| print("π Checking HF Dataset Repository") | |
| print("=" * 60) | |
| try: | |
| response = requests.get(DATASET_URL, timeout=10) | |
| if response.status_code == 200: | |
| data = response.json() | |
| print(f"β Dataset found: {data.get('id')}") | |
| print(f"β Downloads: {data.get('downloads', 0):,}") | |
| # Check for dataset files | |
| files_url = f"{DATASET_URL}/tree/main" | |
| files_response = requests.get(files_url, timeout=10) | |
| if files_response.status_code == 200: | |
| files = files_response.json() | |
| print(f"β Dataset files available: {len(files)} files") | |
| print("\nDataset files:") | |
| for file in files[:5]: # Show first 5 files | |
| size_mb = file.get('size', 0) / (1024 * 1024) | |
| print(f" - {file.get('path')} ({size_mb:.1f} MB)") | |
| if len(files) > 5: | |
| print(f" ... and {len(files) - 5} more files") | |
| print("β Dataset repository is accessible!") | |
| return True | |
| else: | |
| print(f"β Could not fetch dataset (HTTP {response.status_code})") | |
| return False | |
| except Exception as e: | |
| print(f"β Error checking dataset: {e}") | |
| return False | |
| def test_app_endpoint(): | |
| """Test if the app endpoint is responding""" | |
| print("\n" + "=" * 60) | |
| print("π Testing App Endpoint") | |
| print("=" * 60) | |
| try: | |
| print(f"Trying to connect to: {SPACE_URL}") | |
| response = requests.get(SPACE_URL, timeout=30) | |
| if response.status_code == 200: | |
| print("β App endpoint is responding!") | |
| print(f"β Status code: {response.status_code}") | |
| print(f"β Response size: {len(response.text)} bytes") | |
| # Check if it's the Streamlit app | |
| if 'streamlit' in response.text.lower() or 'graphwiz' in response.text.lower(): | |
| print("β Streamlit app detected!") | |
| return True | |
| else: | |
| print("β οΈ Response received but may not be the app yet") | |
| return False | |
| else: | |
| print(f"β οΈ App returned status code: {response.status_code}") | |
| if response.status_code == 503: | |
| print(" (503 = Service Unavailable - app may still be building)") | |
| return False | |
| except requests.exceptions.Timeout: | |
| print("β³ Connection timeout - app may still be starting up") | |
| return False | |
| except requests.exceptions.ConnectionError: | |
| print("β οΈ Could not connect - app may still be building") | |
| return False | |
| except Exception as e: | |
| print(f"β Error testing endpoint: {e}") | |
| return False | |
| def main(): | |
| """Run all verification checks""" | |
| print("\n" + "π" * 30) | |
| print("GraphWiz Ireland - Deployment Verification") | |
| print("π" * 30 + "\n") | |
| print("Space URL: https://huggingface.co/spaces/hirthickraj2015/graphwiz-ireland") | |
| print("Dataset URL: https://huggingface.co/datasets/hirthickraj2015/graphwiz-ireland-dataset") | |
| print() | |
| # Run checks | |
| space_ok = check_space_status() | |
| dataset_ok = check_dataset() | |
| app_ok = test_app_endpoint() | |
| # Summary | |
| print("\n" + "=" * 60) | |
| print("π Verification Summary") | |
| print("=" * 60) | |
| print(f"Space Status: {'β PASS' if space_ok else 'β³ BUILDING or β FAIL'}") | |
| print(f"Dataset Ready: {'β PASS' if dataset_ok else 'β FAIL'}") | |
| print(f"App Endpoint: {'β PASS' if app_ok else 'β³ BUILDING or β FAIL'}") | |
| if space_ok and dataset_ok and app_ok: | |
| print("\nπ All checks passed! Your app is deployed and running!") | |
| print(f"\nπ Visit: {SPACE_URL}") | |
| elif not space_ok or not app_ok: | |
| print("\nβ³ App is still building or starting up.") | |
| print(" First deployment can take 10-15 minutes.") | |
| print(" Run this script again in a few minutes.") | |
| else: | |
| print("\nβ οΈ Some checks failed. Please review the errors above.") | |
| print("\n" + "=" * 60) | |
| print("\nπ‘ Next Steps:") | |
| print("1. If building: Wait 5-10 minutes and run this script again") | |
| print("2. If running: Add GROQ_API_KEY secret in Space Settings") | |
| print("3. Visit the Space URL to test the app") | |
| print("4. Try asking: 'What is the capital of Ireland?'") | |
| print() | |
| if __name__ == "__main__": | |
| main() | |