femifoly commited on
Commit
09f23d1
·
1 Parent(s): 328c63b

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +35 -0
  2. requirements.txt +2 -0
app.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from googletrans import Translator
3
+ from transformers import pipeline
4
+
5
+ pipe = pipeline(model="Nikolajvestergaard/Japanese_Fine_Tuned_Whisper_Model")
6
+
7
+ def translate_and_transcribe(audio):
8
+ translator = Translator()
9
+
10
+ # Transcribe Japanese audio to text
11
+ transcription = pipe(audio)["text"]
12
+
13
+ # Translate the transcription to English
14
+ result = translator.translate(transcription, dest='en')
15
+ translation = result.text
16
+
17
+ # Get the pronunciation of the transcription in Japanese
18
+ pronunciation = translator.translate(transcription, dest='ja').pronunciation
19
+
20
+ return transcription, pronunciation, translation
21
+
22
+ input_audio = gr.inputs.Audio(label="Upload your Japanese speech here. Try to say 'Kon'nichiwa', 'Arigatō' or perhaps 'Sayōnara'", source="microphone", type="filepath")
23
+ output_textbox1 = gr.outputs.Textbox(label="Transcription")
24
+ output_textbox2 = gr.outputs.Textbox(label="Pronunciation")
25
+ output_textbox3 = gr.outputs.Textbox(label="Translation")
26
+
27
+ iface = gr.Interface(
28
+ fn=translate_and_transcribe,
29
+ inputs=input_audio,
30
+ outputs=[output_textbox1, output_textbox2, output_textbox3],
31
+ title="Japanese Automatic Speech Recognition, Pronunciation and Translation",
32
+ description="Record Japanese speech to get its pronunciation and translate it to English. All done by using a fine-tuned version of the tiny Whisper model which is connected to a Google Translate API"
33
+ )
34
+
35
+ iface.launch()
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ googletrans==4.0.0-rc1
2
+ gradio