iiBLACKii commited on
Commit
50976d6
1 Parent(s): 67119f9

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +36 -1
README.md CHANGED
@@ -39,8 +39,43 @@ This is the model card of a 🤗 transformers model that has been pushed on the
39
 
40
  ### Direct Use
41
 
42
- <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
 
 
 
43
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  [More Information Needed]
45
 
46
  ### Downstream Use [optional]
 
39
 
40
  ### Direct Use
41
 
42
+ ```python
43
+ import torch
44
+ import librosa
45
+ from transformers import AutoProcessor, AutoModelForSpeechSeq2Seq
46
 
47
+ processor = AutoProcessor.from_pretrained("iiBLACKii/Gujarati_VDB_Fine_Tune")
48
+ model = AutoModelForSpeechSeq2Seq.from_pretrained("iiBLACKii/Gujarati_VDB_Fine_Tune")
49
+
50
+ device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
51
+ model.to(device)
52
+
53
+ def preprocess_audio(file_path, sampling_rate=16000):
54
+ audio_array, sr = librosa.load(file_path, sr=None)
55
+ if sr != sampling_rate:
56
+ audio_array = librosa.resample(audio_array, orig_sr=sr, target_sr=sampling_rate)
57
+ return audio_array
58
+
59
+ def transcribe_and_translate_audio(audio_path):
60
+ audio_array = preprocess_audio(audio_path)
61
+
62
+ input_features = processor(audio_array, return_tensors="pt", sampling_rate=16000).input_features
63
+
64
+ input_features = input_features.to(device)
65
+
66
+ with torch.no_grad():
67
+ predicted_ids = model.generate(input_features, max_length=400, num_beams=5)
68
+
69
+ transcription_or_translation = processor.batch_decode(predicted_ids, skip_special_tokens=True)
70
+ return transcription_or_translation[0]
71
+
72
+ if __name__ == "__main__":
73
+ audio_file_path = "" # .wav file path
74
+ print("Transcribing and Translating audio...")
75
+ result = transcribe_and_translate_audio(audio_file_path)
76
+ print(f"Result: {result}")
77
+
78
+ ```
79
  [More Information Needed]
80
 
81
  ### Downstream Use [optional]