Tlanextli commited on
Commit
c27a48e
·
1 Parent(s): f355e08

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -8
app.py CHANGED
@@ -3,20 +3,27 @@ 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
 
 
3
  from transformers import pipeline
4
 
5
  title = "Transcribe speech several languages"
6
+ device = "cuda:0" if torch.cuda.is_available() else "cpu"
7
 
8
+ asr_pipe_audio2Text_Ge = pipeline(task="automatic-speech-recognition", model="jonatasgrosman/wav2vec2-large-xlsr-53-german")
9
+ asr_pipe_whisper = pipeline(task="automatic-speech-recognition", model="openai/whisper-large", device=device)
10
 
11
+ #def transcribeFile(audio_path : str) -> str:
12
+ # transcription = asr_pipe_audio2Text_Ge(audio_path)
13
+ # return transcription["text"]
14
+
15
+ def translateAudio(audio_path):
16
+ translationOutput = asr_pipe_whisper(audio_path, max_new_tokens=256, generate_kwargs={"task":"translate"})
17
+ return translationOutput["text"]
18
 
19
  def transcribeFileMulti(inputlang, audio_path : str) -> str:
20
  if inputlang == "English":
21
+ transcription = asr_pipe_whisper(audio_path)
22
  elif inputlang == "German":
23
+ transcription = asr_pipe_audio2Text_Ge(audio_path)
24
+ translation = translateAudio(audio_path)
25
+ output = transcription + translation
26
+ return output #transcription["text"]
27
 
28
 
29