Tlanextli commited on
Commit
f355e08
1 Parent(s): ec5ebbb

Create app_multi_In.py

Browse files
Files changed (1) hide show
  1. app_multi_In.py +43 -0
app_multi_In.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import gradio as gr
3
+ from transformers import pipeline
4
+
5
+ title = "Transcribe speech several languages"
6
+
7
+ pipelineGE = pipeline(task="automatic-speech-recognition", model="jonatasgrosman/wav2vec2-large-xlsr-53-german")
8
+ pipelineEN = pipeline(task="automatic-speech-recognition", model="openai/whisper-large")
9
+
10
+ def transcribeFile(audio_path : str) -> str:
11
+ transcription = pipelineGE(audio_path)
12
+ return transcription["text"]
13
+
14
+ def transcribeFileMulti(inputlang, audio_path : str) -> str:
15
+ if inputlang == "English":
16
+ transcription = pipelineEN(audio_path)
17
+ elif inputlang == "German":
18
+ transcription = pipelineGE(audio_path)
19
+ return transcription["text"]
20
+
21
+
22
+
23
+ app1 = gr.Interface(
24
+ fn=transcribeFile,
25
+ inputs=gr.inputs.Audio(label="Upload audio file", type="filepath"),
26
+ outputs="text",
27
+ title=title
28
+ )
29
+
30
+
31
+ app2 = gr.Interface(
32
+ fn=transcribeFileMulti,
33
+ inputs=[gr.Radio(["English", "German"], value="German", label="Source Language", info="Select the language of the speech you want to transcribe"),
34
+ gr.Audio(source="microphone", type="filepath")],
35
+ outputs="text",
36
+ title=title
37
+ )
38
+
39
+
40
+ demo = gr.TabbedInterface([app1, app2], ["Audio File", "Microphone"])
41
+
42
+ if __name__ == "__main__":
43
+ demo.launch()