Spaces:
Sleeping
Sleeping
File size: 1,327 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 |
"""
Example Python client for using the Whisper Uzbek STT API
"""
from gradio_client import Client
import sys
def transcribe_audio(audio_file_path, space_url):
"""
Transcribe audio file using the Whisper API
Args:
audio_file_path: Path to the audio file
space_url: URL of the Hugging Face Space (e.g., "username/space-name")
Returns:
str: Transcribed text
"""
try:
print(f"Connecting to {space_url}...")
client = Client(space_url)
print(f"Uploading and transcribing {audio_file_path}...")
result = client.predict(
audio_file_path,
api_name="/predict"
)
return result
except Exception as e:
print(f"Error: {str(e)}")
return None
def main():
# Example usage
SPACE_URL = "YOUR_USERNAME/whisper-uzbek-stt" # Replace with your Space URL
if len(sys.argv) < 2:
print("Usage: python api_example.py <audio_file_path>")
print("Example: python api_example.py sample.mp3")
sys.exit(1)
audio_file = sys.argv[1]
result = transcribe_audio(audio_file, SPACE_URL)
if result:
print("\n" + "="*50)
print("TRANSCRIPTION:")
print("="*50)
print(result)
print("="*50)
if __name__ == "__main__":
main()
|