Update README.md
Browse files
README.md
CHANGED
@@ -36,17 +36,30 @@ You can use the model with the Transformers library:
|
|
36 |
from transformers import WhisperForConditionalGeneration, WhisperProcessor
|
37 |
|
38 |
```python
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
39 |
processor = WhisperProcessor.from_pretrained("freds0/distil-whisper-large-v3-ptbr")
|
40 |
model = WhisperForConditionalGeneration.from_pretrained("freds0/distil-whisper-large-v3-ptbr")
|
41 |
|
42 |
-
#
|
43 |
-
|
44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
|
46 |
# Generate transcription
|
47 |
predicted_ids = model.generate(input_features)
|
48 |
transcription = processor.batch_decode(predicted_ids, skip_special_tokens=True)
|
49 |
-
print(transcription[0])
|
50 |
```
|
51 |
|
52 |
|
|
|
36 |
from transformers import WhisperForConditionalGeneration, WhisperProcessor
|
37 |
|
38 |
```python
|
39 |
+
from datasets import load_dataset
|
40 |
+
from transformers import WhisperProcessor, WhisperForConditionalGeneration
|
41 |
+
|
42 |
+
# Load the validation split of the Common Voice dataset for Portuguese
|
43 |
+
common_voice = load_dataset("mozilla-foundation/common_voice_11_0", "pt", split="validation")
|
44 |
+
|
45 |
+
# Load the pretrained model and processor
|
46 |
processor = WhisperProcessor.from_pretrained("freds0/distil-whisper-large-v3-ptbr")
|
47 |
model = WhisperForConditionalGeneration.from_pretrained("freds0/distil-whisper-large-v3-ptbr")
|
48 |
|
49 |
+
# Select a sample from the dataset
|
50 |
+
sample = common_voice[0] # You can change the index to select a different sample
|
51 |
+
|
52 |
+
# Get the audio array and sampling rate
|
53 |
+
audio_input = sample["audio"]["array"]
|
54 |
+
sampling_rate = sample["audio"]["sampling_rate"]
|
55 |
+
|
56 |
+
# Preprocess the audio
|
57 |
+
input_features = processor(audio_input, sampling_rate=sampling_rate, return_tensors="pt").input_features
|
58 |
|
59 |
# Generate transcription
|
60 |
predicted_ids = model.generate(input_features)
|
61 |
transcription = processor.batch_decode(predicted_ids, skip_special_tokens=True)
|
62 |
+
print("Transcription:", transcription[0])
|
63 |
```
|
64 |
|
65 |
|