#!/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()