Automatic Speech Recognition
Transformers
PyTorch
TensorBoard
Vietnamese
whisper
Generated from Trainer
Eval Results (legacy)
Instructions to use vphu123/whisper-endpoint with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use vphu123/whisper-endpoint with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("automatic-speech-recognition", model="vphu123/whisper-endpoint")# pip install -U transformers accelerate # Load model directly from transformers import AutoProcessor, AutoModelForSpeechSeq2Seq processor = AutoProcessor.from_pretrained("vphu123/whisper-endpoint") model = AutoModelForSpeechSeq2Seq.from_pretrained("vphu123/whisper-endpoint", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Download handler.py from vphu123/whisper-endpoint: direct link, hf CLI and curl.
- Browser
- Download file 1.09 kB
-
https://huggingface.co/vphu123/whisper-endpoint/resolve/main/handler.py
- Command line
-
hf download hf://vphu123/whisper-endpoint/handler.py
-
curl -L -o handler.py https://huggingface.co/vphu123/whisper-endpoint/resolve/main/handler.py
1.09 kB
| from typing import Dict, Any | |
| import torch | |
| from transformers import pipeline | |
| from transformers.pipelines.audio_utils import ffmpeg_read | |
| class EndpointHandler: | |
| def __init__(self, asr_model_path: str = "vphu123/whisper-endpoint"): | |
| device = 0 if torch.cuda.is_available() else "cpu" | |
| self.pipe = pipeline( | |
| task="automatic-speech-recognition", | |
| model=asr_model_path, | |
| chunk_length_s=30, | |
| device=device, | |
| max_new_tokens = 10000, | |
| ) | |
| self.pipe.model.config.forced_decoder_ids = self.pipe.tokenizer.get_decoder_prompt_ids(language="vi", task="transcribe") | |
| def __call__(self, data: Dict[str, bytes]) -> Dict[str, str]: | |
| # process input | |
| inputs = data.pop("inputs", data) | |
| audio_nparray = ffmpeg_read(inputs, 16000) | |
| audio_tensor= torch.from_numpy(audio_nparray) | |
| # Process the audio data with the ASR pipeline | |
| result = self.pipe(audio_nparray) | |
| # Convert the transcription to JSON | |
| return {"text": result["text"]} |