Spaces:
Sleeping
Sleeping
| """ | |
| Quick test script for the Whisper Uzbek STT API | |
| This script tests both local and remote API endpoints. | |
| """ | |
| import sys | |
| import os | |
| def test_local_api(): | |
| """Test the API when running locally""" | |
| from gradio_client import Client | |
| print("Testing local API (http://localhost:7860)...") | |
| try: | |
| client = Client("http://localhost:7860") | |
| print("β Connected to local server") | |
| # Test with a sample audio file if provided | |
| if len(sys.argv) > 1: | |
| audio_file = sys.argv[1] | |
| if os.path.exists(audio_file): | |
| print(f"β Testing with audio file: {audio_file}") | |
| result = client.predict(audio_file, api_name="/predict") | |
| print(f"\n{'='*60}") | |
| print("TRANSCRIPTION RESULT:") | |
| print(f"{'='*60}") | |
| print(result) | |
| print(f"{'='*60}\n") | |
| return True | |
| else: | |
| print(f"β Audio file not found: {audio_file}") | |
| return False | |
| else: | |
| print("βΉ No audio file provided for testing") | |
| print("Usage: python test_api.py <audio_file_path>") | |
| return True | |
| except Exception as e: | |
| print(f"β Error: {str(e)}") | |
| return False | |
| def test_remote_api(space_url): | |
| """Test the API on Hugging Face Spaces""" | |
| from gradio_client import Client | |
| print(f"\nTesting remote API ({space_url})...") | |
| try: | |
| client = Client(space_url) | |
| print("β Connected to remote Space") | |
| if len(sys.argv) > 1: | |
| audio_file = sys.argv[1] | |
| if os.path.exists(audio_file): | |
| print(f"β Testing with audio file: {audio_file}") | |
| result = client.predict(audio_file, api_name="/predict") | |
| print(f"\n{'='*60}") | |
| print("TRANSCRIPTION RESULT:") | |
| print(f"{'='*60}") | |
| print(result) | |
| print(f"{'='*60}\n") | |
| return True | |
| else: | |
| print(f"β Audio file not found: {audio_file}") | |
| return False | |
| else: | |
| print("βΉ No audio file provided for testing") | |
| return True | |
| except Exception as e: | |
| print(f"β Error: {str(e)}") | |
| return False | |
| def main(): | |
| print("="*60) | |
| print("Whisper Uzbek STT - API Test Script") | |
| print("="*60) | |
| print() | |
| # Test local API | |
| local_success = test_local_api() | |
| # Optionally test remote API | |
| print("\n" + "-"*60) | |
| test_remote = input("Do you want to test the remote API? (y/n): ").lower().strip() | |
| if test_remote == 'y': | |
| space_url = input("Enter your Space URL (e.g., username/space-name): ").strip() | |
| if space_url: | |
| remote_success = test_remote_api(space_url) | |
| else: | |
| print("β No Space URL provided") | |
| remote_success = False | |
| else: | |
| remote_success = None | |
| # Summary | |
| print("\n" + "="*60) | |
| print("TEST SUMMARY") | |
| print("="*60) | |
| print(f"Local API: {'β PASSED' if local_success else 'β FAILED'}") | |
| if remote_success is not None: | |
| print(f"Remote API: {'β PASSED' if remote_success else 'β FAILED'}") | |
| print("="*60) | |
| if __name__ == "__main__": | |
| try: | |
| from gradio_client import Client | |
| except ImportError: | |
| print("β Error: gradio-client is not installed") | |
| print("Install it with: pip install gradio-client") | |
| sys.exit(1) | |
| main() | |