Funbi commited on
Commit
304db69
·
1 Parent(s): 593e412

Add application file

Browse files
Files changed (2) hide show
  1. app.py +48 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import whisper
2
+
3
+ model = whisper.load_model("base")
4
+
5
+ from transformers import pipeline
6
+ en_fr_translator = pipeline("translation_en_to_fr")
7
+
8
+ import gradio as gr
9
+ import time
10
+
11
+ def transcribe(audio):
12
+
13
+ #time.sleep(3)
14
+ # load audio and pad/trim it to fit 30 seconds
15
+ audio = whisper.load_audio(audio)
16
+ audio = whisper.pad_or_trim(audio)
17
+
18
+ # make log-Mel spectrogram and move to the same device as the model
19
+ mel = whisper.log_mel_spectrogram(audio).to(model.device)
20
+
21
+ # detect the spoken language
22
+ _, probs = model.detect_language(mel)
23
+ lang=(f"Detected language: {max(probs, key=probs.get)}")
24
+
25
+
26
+
27
+
28
+
29
+ # decode the audio
30
+ options = whisper.DecodingOptions()
31
+ result = whisper.decode(model, mel, options)
32
+ word= result.text
33
+ trans = en_fr_translator(word)
34
+ Trans = trans[0]['translation_text']
35
+ result=f"{lang}\n{word}\n\nFrench translation: {Trans}"
36
+ return result
37
+
38
+
39
+ gr.Interface(
40
+ title = 'OpenAI Whisper ASR Gradio Web UI',
41
+ fn=transcribe,
42
+ inputs=[
43
+ gr.inputs.Audio(source="microphone", type="filepath")
44
+ ],
45
+ outputs=[
46
+ "textbox"
47
+ ],
48
+ live=True).launch()
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ git+https://github.com/openai/whisper.git
2
+ transformers