raghuhasan commited on
Commit
6b0968a
·
verified ·
1 Parent(s): 6232e41

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -0
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ from transformers import pipeline
4
+
5
+ # Load Whisper small pipeline
6
+ device = 0 if torch.cuda.is_available() else -1
7
+ asr = pipeline(
8
+ "automatic-speech-recognition",
9
+ model="openai/whisper-small",
10
+ chunk_length_s=30,
11
+ device=device,
12
+ )
13
+
14
+ def transcribe(audio):
15
+ if audio is None:
16
+ return "Please upload or record audio"
17
+ text = asr(audio)["text"]
18
+ return text
19
+
20
+ demo = gr.Interface(
21
+ fn=transcribe,
22
+ inputs=gr.Audio(sources=["microphone", "upload"], type="filepath"),
23
+ outputs="text",
24
+ title="Whisper Small ASR",
25
+ description="Upload or record audio and get text transcription with OpenAI Whisper Small."
26
+ )
27
+
28
+ if __name__ == "__main__":
29
+ demo.launch()