Instructions to use kmrabby/crisp with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use kmrabby/crisp with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("automatic-speech-recognition", model="kmrabby/crisp")# pip install -U transformers accelerate # Load model directly from transformers import AutoProcessor, AutoModelForSpeechSeq2Seq processor = AutoProcessor.from_pretrained("kmrabby/crisp") model = AutoModelForSpeechSeq2Seq.from_pretrained("kmrabby/crisp", device_map="auto") - Notebooks
- Google Colab
- Kaggle
add: handler
Browse files- handler.py +39 -0
handler.py
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import sys
|
| 3 |
+
import torch
|
| 4 |
+
|
| 5 |
+
from datasets import load_dataset
|
| 6 |
+
from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor, pipeline
|
| 7 |
+
from utils import adjust_pauses_for_hf_pipeline_output
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
| 12 |
+
torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
|
| 13 |
+
|
| 14 |
+
model_id = "nyrahealth/CrisperWhisper"
|
| 15 |
+
|
| 16 |
+
model = AutoModelForSpeechSeq2Seq.from_pretrained(
|
| 17 |
+
model_id, torch_dtype=torch_dtype, low_cpu_mem_usage=True, use_safetensors=True
|
| 18 |
+
)
|
| 19 |
+
model.to(device)
|
| 20 |
+
|
| 21 |
+
processor = AutoProcessor.from_pretrained(model_id)
|
| 22 |
+
|
| 23 |
+
pipe = pipeline(
|
| 24 |
+
"automatic-speech-recognition",
|
| 25 |
+
model=model,
|
| 26 |
+
tokenizer=processor.tokenizer,
|
| 27 |
+
feature_extractor=processor.feature_extractor,
|
| 28 |
+
chunk_length_s=30,
|
| 29 |
+
batch_size=16,
|
| 30 |
+
return_timestamps='word',
|
| 31 |
+
torch_dtype=torch_dtype,
|
| 32 |
+
device=device,
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
dataset = load_dataset("distil-whisper/librispeech_long", "clean", split="validation")
|
| 36 |
+
sample = dataset[0]["audio"]
|
| 37 |
+
hf_pipeline_output = pipe(sample)
|
| 38 |
+
crisper_whisper_result = adjust_pauses_for_hf_pipeline_output(hf_pipeline_output)
|
| 39 |
+
print(crisper_whisper_result)
|