fanaf91318
commited on
Commit
•
c1a936e
1
Parent(s):
a1033d9
Update README.md
Browse files
README.md
CHANGED
@@ -1,3 +1,38 @@
|
|
1 |
-
---
|
2 |
-
license: mit
|
3 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
license: mit
|
3 |
+
---
|
4 |
+
|
5 |
+
```
|
6 |
+
!pip install --upgrade bitsandbytes peft==0.5.0 transformers torch
|
7 |
+
|
8 |
+
from transformers import (
|
9 |
+
AutomaticSpeechRecognitionPipeline,
|
10 |
+
WhisperForConditionalGeneration,
|
11 |
+
WhisperTokenizer,
|
12 |
+
WhisperProcessor,
|
13 |
+
)
|
14 |
+
from peft import PeftModel, PeftConfig
|
15 |
+
import torch
|
16 |
+
|
17 |
+
peft_model_id = "aisha-org/faster-whisper-uz" # Use the same model ID as before.
|
18 |
+
language = "uz"
|
19 |
+
task = "transcribe"
|
20 |
+
peft_config = PeftConfig.from_pretrained(peft_model_id)
|
21 |
+
model = WhisperForConditionalGeneration.from_pretrained(
|
22 |
+
peft_config.base_model_name_or_path, load_in_8bit=True, device_map="auto"
|
23 |
+
)
|
24 |
+
|
25 |
+
model = PeftModel.from_pretrained(model, peft_model_id)
|
26 |
+
tokenizer = WhisperTokenizer.from_pretrained(peft_config.base_model_name_or_path, language=language, task=task)
|
27 |
+
processor = WhisperProcessor.from_pretrained(peft_config.base_model_name_or_path, language=language, task=task)
|
28 |
+
feature_extractor = processor.feature_extractor
|
29 |
+
forced_decoder_ids = processor.get_decoder_prompt_ids(language=language, task=task)
|
30 |
+
pipe = AutomaticSpeechRecognitionPipeline(model=model, tokenizer=tokenizer, feature_extractor=feature_extractor)
|
31 |
+
|
32 |
+
|
33 |
+
def transcribe(audio):
|
34 |
+
with torch.cuda.amp.autocast():
|
35 |
+
text = pipe(audio, generate_kwargs={"forced_decoder_ids": forced_decoder_ids}, max_new_tokens=255)["text"]
|
36 |
+
return text
|
37 |
+
transcribe('path/to/audio.wav')
|
38 |
+
```
|