Update README.md
Browse files
README.md
CHANGED
@@ -8,4 +8,36 @@ language:
|
|
8 |
- th
|
9 |
library_name: transformers
|
10 |
pipeline_tag: automatic-speech-recognition
|
11 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
- th
|
9 |
library_name: transformers
|
10 |
pipeline_tag: automatic-speech-recognition
|
11 |
+
---
|
12 |
+
|
13 |
+
```python
|
14 |
+
from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor, pipeline
|
15 |
+
import torch
|
16 |
+
# MODEL_NAME = "whisper-large-v3-turbo-thai"
|
17 |
+
MODEL_NAME = "whis"
|
18 |
+
|
19 |
+
device = "cuda:0" if torch.cuda.is_available() else "cpu"
|
20 |
+
torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32
|
21 |
+
|
22 |
+
model = AutoModelForSpeechSeq2Seq.from_pretrained(
|
23 |
+
MODEL_NAME,
|
24 |
+
torch_dtype=torch_dtype,
|
25 |
+
# low_cpu_mem_usage=True,
|
26 |
+
# use_safetensors=True,
|
27 |
+
)
|
28 |
+
model.to(device)
|
29 |
+
processor = AutoProcessor.from_pretrained(MODEL_NAME)
|
30 |
+
|
31 |
+
whisper = pipeline(
|
32 |
+
"automatic-speech-recognition",
|
33 |
+
model=model,
|
34 |
+
tokenizer=processor.tokenizer,
|
35 |
+
feature_extractor=processor.feature_extractor,
|
36 |
+
max_new_tokens=128,
|
37 |
+
torch_dtype=torch_dtype,
|
38 |
+
device=device,
|
39 |
+
)
|
40 |
+
|
41 |
+
whisper("c.mp3",chunk_length_s=30,stride_length_s=5,batch_size=16,return_timestamps=True,generate_kwargs = {"language":"<|th|>"})
|
42 |
+
```
|
43 |
+
|