Spaces:
Runtime error
Runtime error
| #!/usr/bin/env python3 | |
| """ | |
| Test script for Hugging Face Spaces deployment | |
| """ | |
| import requests | |
| import json | |
| import sys | |
| def test_health_check(base_url): | |
| """Test the health check endpoint""" | |
| try: | |
| response = requests.get(f"{base_url}/") | |
| print(f"Health check status: {response.status_code}") | |
| print(f"Response: {response.json()}") | |
| return response.status_code == 200 | |
| except Exception as e: | |
| print(f"Health check failed: {e}") | |
| return False | |
| def test_api_endpoint(base_url, api_key): | |
| """Test the main API endpoint""" | |
| try: | |
| url = f"{base_url}/api/v1/hackrx/run" | |
| headers = { | |
| "Content-Type": "application/json", | |
| "Authorization": f"Bearer {api_key}" | |
| } | |
| data = { | |
| "documents": "https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf", | |
| "questions": ["What is this document about?"] | |
| } | |
| response = requests.post(url, headers=headers, json=data) | |
| print(f"API test status: {response.status_code}") | |
| print(f"Response: {response.json()}") | |
| return response.status_code == 200 | |
| except Exception as e: | |
| print(f"API test failed: {e}") | |
| return False | |
| def main(): | |
| if len(sys.argv) < 2: | |
| print("Usage: python test_deployment.py <base_url> [api_key]") | |
| print("Example: python test_deployment.py https://your-space-name.hf.space your_api_key") | |
| sys.exit(1) | |
| base_url = sys.argv[1].rstrip('/') | |
| api_key = sys.argv[2] if len(sys.argv) > 2 else "test_token" | |
| print(f"Testing deployment at: {base_url}") | |
| print("=" * 50) | |
| # Test health check | |
| print("1. Testing health check...") | |
| health_ok = test_health_check(base_url) | |
| # Test API endpoint | |
| print("\n2. Testing API endpoint...") | |
| api_ok = test_api_endpoint(base_url, api_key) | |
| # Summary | |
| print("\n" + "=" * 50) | |
| print("DEPLOYMENT TEST SUMMARY") | |
| print("=" * 50) | |
| print(f"Health check: {'β PASS' if health_ok else 'β FAIL'}") | |
| print(f"API endpoint: {'β PASS' if api_ok else 'β FAIL'}") | |
| if health_ok and api_ok: | |
| print("\nπ Deployment is working correctly!") | |
| else: | |
| print("\nβ οΈ Some tests failed. Check the logs above for details.") | |
| if __name__ == "__main__": | |
| main() |