ihanif commited on
Commit
6960495
·
1 Parent(s): 9c43305

feat: create a gradio interface for Pashto ASR

Browse files
Files changed (2) hide show
  1. app.py +39 -0
  2. requirements.txt +1 -0
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import whisper
2
+ import gradio as gr
3
+
4
+ model = whisper.load_model("large")
5
+
6
+
7
+ def transcribe(audio):
8
+
9
+ # load audio and pad/trim it to fit 30 seconds
10
+ audio = whisper.load_audio(audio)
11
+ audio = whisper.pad_or_trim(audio)
12
+
13
+ # make log-Mel spectrogram and move to the same device as the model
14
+ mel = whisper.log_mel_spectrogram(audio).to(model.device)
15
+
16
+ # detect the spoken language
17
+ _, probs = model.detect_language(mel)
18
+
19
+ ps_prob = probs["ps"]
20
+
21
+ print(f"ستاسو د وینا د پښتو ژبې احتمال: {ps_prob}")
22
+ print(f"Detected language: {max(probs, key=probs.get)}")
23
+
24
+ # decode the audio
25
+ options = whisper.DecodingOptions(fp16=False, language="ps")
26
+ result = whisper.decode(model, mel, options)
27
+ return result.text
28
+
29
+
30
+ gr.Interface(
31
+ title='د لومړي ځل لپاره د پښتو اتوماتیک وینا پیژندنه (Pashto ASR)',
32
+ fn=transcribe,
33
+ inputs=[
34
+ gr.inputs.Audio(source="microphone", type="filepath")
35
+ ],
36
+ outputs=[
37
+ "textbox"
38
+ ],
39
+ live=True).launch()
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ git+https://github.com/openai/whisper.git