Spaces:
Sleeping
Sleeping
| """ | |
| 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() | |