Download test_api.py from alkasima/alkvoice: direct link, hf CLI and curl.
- Browser
- Download file 1.89 kB
-
https://huggingface.co/spaces/alkasima/alkvoice/resolve/main/test_api.py
- Command line
-
hf download hf://spaces/alkasima/alkvoice/test_api.py
-
curl -L -o test_api.py https://huggingface.co/spaces/alkasima/alkvoice/resolve/main/test_api.py
1.89 kB
| # Test the API locally before deploying | |
| import requests | |
| import sys | |
| def test_api(base_url="http://localhost:7860"): | |
| print("🧪 Testing AI Voice Enhancer API\n") | |
| print(f"Base URL: {base_url}\n") | |
| # Test 1: Root endpoint | |
| print("1️⃣ Testing GET / ...") | |
| try: | |
| response = requests.get(f"{base_url}/") | |
| print(f" Status: {response.status_code}") | |
| print(f" Response: {response.json()}\n") | |
| except Exception as e: | |
| print(f" ❌ Error: {e}\n") | |
| return False | |
| # Test 2: Health check | |
| print("2️⃣ Testing GET /health ...") | |
| try: | |
| response = requests.get(f"{base_url}/health") | |
| print(f" Status: {response.status_code}") | |
| print(f" Response: {response.json()}\n") | |
| except Exception as e: | |
| print(f" ❌ Error: {e}\n") | |
| return False | |
| # Test 3: Enhancement endpoint (without file) | |
| print("3️⃣ Testing POST /enhance (validation) ...") | |
| try: | |
| response = requests.post(f"{base_url}/enhance") | |
| print(f" Status: {response.status_code}") | |
| if response.status_code == 422: | |
| print(f" ✅ Validation working correctly\n") | |
| else: | |
| print(f" Response: {response.text}\n") | |
| except Exception as e: | |
| print(f" ❌ Error: {e}\n") | |
| print("✅ All basic tests passed!") | |
| print("\n📝 To test audio enhancement:") | |
| print(" 1. Run: python api.py") | |
| print(" 2. Upload a test audio file via frontend") | |
| print(" OR use:") | |
| print(f' curl -X POST "{base_url}/enhance" -F "file=@test.wav" -F "speech_level=80" -F "background_level=85" -o output.wav') | |
| return True | |
| if __name__ == "__main__": | |
| # Check if custom URL provided | |
| url = sys.argv[1] if len(sys.argv) > 1 else "http://localhost:7860" | |
| test_api(url) | |