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
File size: 1,085 Bytes
0c676b3 79c6149 0c676b3 79c6149 0c676b3 fb260b1 79c6149 0c676b3 79c6149 0c676b3 79c6149 4e7ae38 79c6149 0c676b3 79c6149 0c676b3 79c6149 | 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 | 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"]} |