Spaces:
Sleeping
Sleeping
File size: 3,502 Bytes
3ef0477 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
"""
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()
|