Spaces:
Paused
Paused
| """ | |
| Quick API Test Script | |
| Test the FastAPI server locally or on HF | |
| """ | |
| import requests | |
| import sys | |
| # Change this to your HF Space URL or local | |
| #API_URL = "akpande2/Aurator_Coaching" # For local testing | |
| API_URL = "https://akpande2-aurator-coaching.hf.space" # For HF testing | |
| def test_health(): | |
| """Test health endpoint""" | |
| print("Testing /api/health...") | |
| response = requests.get(f"{API_URL}/api/health") | |
| print(f"Status: {response.status_code}") | |
| print(f"Response: {response.json()}\n") | |
| return response.status_code == 200 | |
| def test_analyze(audio_file_path): | |
| """Test analyze endpoint""" | |
| print(f"Testing /api/analyze with {audio_file_path}...") | |
| with open(audio_file_path, 'rb') as f: | |
| files = {'audio_file': f} | |
| data = {'avatar_gender': 'male'} | |
| response = requests.post( | |
| f"{API_URL}/api/analyze", | |
| files=files, | |
| data=data, | |
| timeout=60 | |
| ) | |
| print(f"Status: {response.status_code}") | |
| if response.status_code == 200: | |
| result = response.json() | |
| print(f"Success: {result['success']}") | |
| print(f"Overall Score: {result['data']['overall_score']}") | |
| print(f"Processing Time: {result['processing_time_ms']}ms") | |
| print(f"Tips Count: {len(result['data']['coaching']['tips'])}") | |
| print(f"Tips Audio: {result['data']['coaching']['tips_audio_url']}") | |
| print(f"Improved Audio: {result['data']['coaching']['improved_audio_url']}") | |
| else: | |
| print(f"Error: {response.text}") | |
| return response.status_code == 200 | |
| if __name__ == "__main__": | |
| print("="*60) | |
| print("API TEST SCRIPT") | |
| print("="*60 + "\n") | |
| # Test health | |
| if not test_health(): | |
| print("❌ Health check failed!") | |
| sys.exit(1) | |
| print("✅ Health check passed!\n") | |
| # Test analyze (provide your audio file) | |
| if len(sys.argv) > 1: | |
| audio_file = sys.argv[1] | |
| if test_analyze(audio_file): | |
| print("\n✅ Analysis test passed!") | |
| else: | |
| print("\n❌ Analysis test failed!") | |
| else: | |
| print("ℹ️ To test analysis: python test_api.py your_audio.wav") | |