IRISLAB commited on
Commit
4246b22
1 Parent(s): 3fa666e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -2
app.py CHANGED
@@ -27,7 +27,7 @@ class App:
27
  if whisper_type in ["faster_whisper", "faster-whisper"]:
28
  whisper_inf = FasterWhisperInference()
29
  whisper_inf.model_dir = self.args.faster_whisper_model_dir
30
- if whisper_type in ["whisper"]:
31
  whisper_inf = WhisperInference()
32
  whisper_inf.model_dir = self.args.whisper_model_dir
33
  else:
@@ -50,6 +50,15 @@ class App:
50
  else:
51
  return gr.Checkbox(visible=True, value=False, label="Translate to English?", interactive=True)
52
 
 
 
 
 
 
 
 
 
 
53
  def launch(self):
54
  with self.app:
55
  with gr.Row():
@@ -117,7 +126,7 @@ class App:
117
  window_size_sample=nb_window_size_sample,
118
  speech_pad_ms=nb_speech_pad_ms)
119
 
120
- btn_run.click(fn=self.whisper_inf.transcribe_file,
121
  inputs=params + whisper_params.to_list(),
122
  outputs=[tb_indicator, files_subtitles])
123
  btn_openfolder.click(fn=lambda: self.open_folder("outputs"), inputs=None, outputs=None)
 
27
  if whisper_type in ["faster_whisper", "faster-whisper"]:
28
  whisper_inf = FasterWhisperInference()
29
  whisper_inf.model_dir = self.args.faster_whisper_model_dir
30
+ elif whisper_type in ["whisper"]:
31
  whisper_inf = WhisperInference()
32
  whisper_inf.model_dir = self.args.whisper_model_dir
33
  else:
 
50
  else:
51
  return gr.Checkbox(visible=True, value=False, label="Translate to English?", interactive=True)
52
 
53
+ def transcribe_file_wrapper(self, file, file_format, timestamp, *whisper_params):
54
+ try:
55
+ result, output_file = self.whisper_inf.transcribe_file(file, file_format, timestamp, *whisper_params)
56
+ if not os.path.exists(output_file):
57
+ raise FileNotFoundError(f"Output file {output_file} does not exist.")
58
+ return result, output_file
59
+ except Exception as e:
60
+ return str(e), None
61
+
62
  def launch(self):
63
  with self.app:
64
  with gr.Row():
 
126
  window_size_sample=nb_window_size_sample,
127
  speech_pad_ms=nb_speech_pad_ms)
128
 
129
+ btn_run.click(fn=self.transcribe_file_wrapper,
130
  inputs=params + whisper_params.to_list(),
131
  outputs=[tb_indicator, files_subtitles])
132
  btn_openfolder.click(fn=lambda: self.open_folder("outputs"), inputs=None, outputs=None)