paulbauriegel commited on
Commit
e77e1d8
·
1 Parent(s): 3146b8d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -8
app.py CHANGED
@@ -7,18 +7,13 @@ import whisperx
7
 
8
  model = WhisperModel('large-v2', device="cuda", compute_type="float16")
9
 
10
- def speech_to_text(mic=None, file=None, lang=None):
11
  if mic is not None:
12
  audio = mic
13
  elif file is not None:
14
  audio = file
15
  else:
16
  raise gr.Error("You must either provide a mic recording or a file")
17
-
18
- if lang is None or lang == '':
19
- lang = None
20
-
21
- task = 'transcribe' if lang is None else 'translate'
22
  print(lang, task)
23
 
24
  time_start = time.time()
@@ -73,11 +68,11 @@ with gr.Blocks(title='Whisper Demo', theme=theme) as demo:
73
  translate_btn = gr.Button("Translate audio")
74
  trans_df = gr.DataFrame(label="Transcription dataframe", row_count=(0, "dynamic"), max_rows = 10, wrap=True, overflow_row_behaviour='paginate')
75
  sys_info = gr.Markdown("")
76
- transcribe_btn.click(speech_to_text,
77
  [audio_in, file_in, drop_down],
78
  [trans_df, sys_info]
79
  )
80
- translate_btn.click(speech_to_text,
81
  [audio_in, file_in, drop_down],
82
  [trans_df, sys_info])
83
 
 
7
 
8
  model = WhisperModel('large-v2', device="cuda", compute_type="float16")
9
 
10
+ def speech_to_text(mic=None, file=None, lang=None, task='transcribe'):
11
  if mic is not None:
12
  audio = mic
13
  elif file is not None:
14
  audio = file
15
  else:
16
  raise gr.Error("You must either provide a mic recording or a file")
 
 
 
 
 
17
  print(lang, task)
18
 
19
  time_start = time.time()
 
68
  translate_btn = gr.Button("Translate audio")
69
  trans_df = gr.DataFrame(label="Transcription dataframe", row_count=(0, "dynamic"), max_rows = 10, wrap=True, overflow_row_behaviour='paginate')
70
  sys_info = gr.Markdown("")
71
+ transcribe_btn.click(lambda x, y: speech_to_text(x, y, None, 'transcribe'),
72
  [audio_in, file_in, drop_down],
73
  [trans_df, sys_info]
74
  )
75
+ translate_btn.click(lambda x, y, z: speech_to_text(x, y, None, 'translate'),
76
  [audio_in, file_in, drop_down],
77
  [trans_df, sys_info])
78