Murali Chandran commited on
Commit
f7ecc76
·
1 Parent(s): d014ad6

Add Gradio demo

Browse files
Files changed (2) hide show
  1. app.py +28 -0
  2. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ import torchaudio
4
+ from transformers import WhisperProcessor, WhisperForConditionalGeneration
5
+
6
+ MODEL_ID = "codeninja3d/whisper-small-ls100"
7
+
8
+ processor = WhisperProcessor.from_pretrained(MODEL_ID)
9
+ model = WhisperForConditionalGeneration.from_pretrained(MODEL_ID)
10
+ model = model.to("cuda" if torch.cuda.is_available() else "cpu")
11
+
12
+ def transcribe(audio):
13
+ speech, sr = torchaudio.load(audio)
14
+ inputs = processor(speech.squeeze(), sampling_rate=sr, return_tensors="pt").to(model.device)
15
+ pred_ids = model.generate(**inputs)
16
+ text = processor.batch_decode(pred_ids, skip_special_tokens=True)[0]
17
+ return text
18
+
19
+ demo = gr.Interface(
20
+ fn=transcribe,
21
+ inputs=gr.Audio(sources=["upload", "microphone"], type="filepath"),
22
+ outputs="text",
23
+ title="Whisper Small LS100 - Fine-tuned Model",
24
+ description="Upload or record an English audio sample (16 kHz recommended) to get a transcription."
25
+ )
26
+
27
+ if __name__ == "__main__":
28
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ torch
2
+ torchaudio
3
+ transformers>=4.45
4
+ gradio>=4.0