hackergeek98 commited on
Commit
92cc3f4
·
verified ·
1 Parent(s): b3e6cf8

Update README.md

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