graphwiz-ireland / test_deployment.py
hirthickraj2015's picture
Fix dependency version conflict + add version checker
ec7f58f
raw
history blame
6.1 kB
#!/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()