hackergeek98 commited on
Commit
0c24b79
·
verified ·
1 Parent(s): 2615cde

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +41 -41
README.md CHANGED
@@ -13,44 +13,44 @@ library_name: transformers
13
  ---
14
  how to use the model in colab:
15
 
16
- #start
17
- pip install torch torchaudio transformers librosa gradio
18
- from transformers import WhisperProcessor, WhisperForConditionalGeneration
19
- import torch
20
-
21
- #Load your fine-tuned Whisper model and processor
22
- model_name = "hackergeek98/tinyyyy_whisper"
23
- processor = WhisperProcessor.from_pretrained(model_name)
24
- model = WhisperForConditionalGeneration.from_pretrained(model_name)
25
-
26
- #Force the model to transcribe in Persian
27
- model.config.forced_decoder_ids = processor.get_decoder_prompt_ids(language="fa", task="transcribe")
28
-
29
- #Move model to GPU if available
30
- device = "cuda" if torch.cuda.is_available() else "cpu"
31
- model.to(device)
32
- import librosa
33
-
34
- def transcribe_audio(audio_file):
35
- # Load audio file using librosa (supports multiple formats)
36
- audio_data, sampling_rate = librosa.load(audio_file, sr=16000) # Resample to 16kHz
37
-
38
- # Preprocess the audio
39
- inputs = processor(audio_data, sampling_rate=sampling_rate, return_tensors="pt").input_features.to(device)
40
-
41
- # Generate transcription
42
- with torch.no_grad():
43
- predicted_ids = model.generate(inputs)
44
-
45
- # Decode the transcription
46
- transcription = processor.batch_decode(predicted_ids, skip_special_tokens=True)[0]
47
- return transcription
48
- from google.colab import files
49
-
50
- #Upload an audio file
51
- uploaded = files.upload()
52
- audio_file = list(uploaded.keys())[0]
53
-
54
- #Transcribe the audio
55
- transcription = transcribe_audio(audio_file)
56
- print("Transcription:", transcription)
 
13
  ---
14
  how to use the model in colab:
15
 
16
+ #start
17
+ pip install torch torchaudio transformers librosa gradio
18
+ from transformers import WhisperProcessor, WhisperForConditionalGeneration
19
+ import torch
20
+
21
+ #Load your fine-tuned Whisper model and processor
22
+ model_name = "hackergeek98/tinyyyy_whisper"
23
+ processor = WhisperProcessor.from_pretrained(model_name)
24
+ model = WhisperForConditionalGeneration.from_pretrained(model_name)
25
+
26
+ #Force the model to transcribe in Persian
27
+ model.config.forced_decoder_ids = processor.get_decoder_prompt_ids(language="fa", task="transcribe")
28
+
29
+ #Move model to GPU if available
30
+ device = "cuda" if torch.cuda.is_available() else "cpu"
31
+ model.to(device)
32
+ import librosa
33
+
34
+ def transcribe_audio(audio_file):
35
+ # Load audio file using librosa (supports multiple formats)
36
+ audio_data, sampling_rate = librosa.load(audio_file, sr=16000) # Resample to 16kHz
37
+
38
+ # Preprocess the audio
39
+ inputs = processor(audio_data, sampling_rate=sampling_rate, return_tensors="pt").input_features.to(device)
40
+
41
+ # Generate transcription
42
+ with torch.no_grad():
43
+ predicted_ids = model.generate(inputs)
44
+
45
+ # Decode the transcription
46
+ transcription = processor.batch_decode(predicted_ids, skip_special_tokens=True)[0]
47
+ return transcription
48
+ from google.colab import files
49
+
50
+ #Upload an audio file
51
+ uploaded = files.upload()
52
+ audio_file = list(uploaded.keys())[0]
53
+
54
+ #Transcribe the audio
55
+ transcription = transcribe_audio(audio_file)
56
+ print("Transcription:", transcription)