jhj0517 commited on
Commit
fbc1421
·
1 Parent(s): 32ef602
Files changed (2) hide show
  1. app.py +1 -1
  2. modules/whisper/whisper_base.py +43 -43
app.py CHANGED
@@ -160,7 +160,7 @@ class App:
160
  diarization_device=dd_diarization_device)
161
 
162
  btn_run.click(fn=self.whisper_inf.transcribe_file,
163
- inputs=params + whisper_params.as_list(),
164
  outputs=[tb_indicator, files_subtitles])
165
  dd_model.change(fn=self.on_change_models, inputs=[dd_model], outputs=[cb_translate])
166
 
 
160
  diarization_device=dd_diarization_device)
161
 
162
  btn_run.click(fn=self.whisper_inf.transcribe_file,
163
+ inputs=params,
164
  outputs=[tb_indicator, files_subtitles])
165
  dd_model.change(fn=self.on_change_models, inputs=[dd_model], outputs=[cb_translate])
166
 
modules/whisper/whisper_base.py CHANGED
@@ -131,7 +131,7 @@ class WhisperBase(ABC):
131
  file_format: str,
132
  add_timestamp: bool,
133
  progress=gr.Progress(),
134
- *whisper_params,
135
  ):
136
  """
137
  Write subtitle file from Files
@@ -157,48 +157,48 @@ class WhisperBase(ABC):
157
  Output file path to return to gr.Files()
158
  """
159
  print("transcrption started: ")
160
- try:
161
- files_info = {}
162
- for file in files:
163
- print("run started: ")
164
- transcribed_segments, time_for_task = self.run(
165
- file.name,
166
- progress,
167
- *whisper_params,
168
- )
169
- print("run finished: ")
170
-
171
- file_name, file_ext = os.path.splitext(os.path.basename(file.name))
172
- file_name = safe_filename(file_name)
173
- subtitle, file_path = self.generate_and_write_file(
174
- file_name=file_name,
175
- transcribed_segments=transcribed_segments,
176
- add_timestamp=add_timestamp,
177
- file_format=file_format,
178
- output_dir=self.output_dir
179
- )
180
- print("generated sub finished: ")
181
- files_info[file_name] = {"subtitle": subtitle, "time_for_task": time_for_task, "path": file_path}
182
-
183
- total_result = ''
184
- total_time = 0
185
- for file_name, info in files_info.items():
186
- total_result += '------------------------------------\n'
187
- total_result += f'{file_name}\n\n'
188
- total_result += f'{info["subtitle"]}'
189
- total_time += info["time_for_task"]
190
-
191
- result_str = f"Done in {self.format_time(total_time)}! Subtitle is in the outputs folder.\n\n{total_result}"
192
- result_file_path = [info['path'] for info in files_info.values()]
193
-
194
- return [result_str, result_file_path]
195
-
196
- except Exception as e:
197
- print(f"Error transcribing file: {e}")
198
- finally:
199
- self.release_cuda_memory()
200
- if not files:
201
- self.remove_input_files([file.name for file in files])
202
 
203
  @spaces.GPU(duration=120)
204
  def transcribe_mic(self,
 
131
  file_format: str,
132
  add_timestamp: bool,
133
  progress=gr.Progress(),
134
+ #*whisper_params,
135
  ):
136
  """
137
  Write subtitle file from Files
 
157
  Output file path to return to gr.Files()
158
  """
159
  print("transcrption started: ")
160
+ # try:
161
+ # files_info = {}
162
+ # for file in files:
163
+ # print("run started: ")
164
+ # transcribed_segments, time_for_task = self.run(
165
+ # file.name,
166
+ # progress,
167
+ # *whisper_params,
168
+ # )
169
+ # print("run finished: ")
170
+ #
171
+ # file_name, file_ext = os.path.splitext(os.path.basename(file.name))
172
+ # file_name = safe_filename(file_name)
173
+ # subtitle, file_path = self.generate_and_write_file(
174
+ # file_name=file_name,
175
+ # transcribed_segments=transcribed_segments,
176
+ # add_timestamp=add_timestamp,
177
+ # file_format=file_format,
178
+ # output_dir=self.output_dir
179
+ # )
180
+ # print("generated sub finished: ")
181
+ # files_info[file_name] = {"subtitle": subtitle, "time_for_task": time_for_task, "path": file_path}
182
+ #
183
+ # total_result = ''
184
+ # total_time = 0
185
+ # for file_name, info in files_info.items():
186
+ # total_result += '------------------------------------\n'
187
+ # total_result += f'{file_name}\n\n'
188
+ # total_result += f'{info["subtitle"]}'
189
+ # total_time += info["time_for_task"]
190
+ #
191
+ # result_str = f"Done in {self.format_time(total_time)}! Subtitle is in the outputs folder.\n\n{total_result}"
192
+ # result_file_path = [info['path'] for info in files_info.values()]
193
+ #
194
+ # return [result_str, result_file_path]
195
+ #
196
+ # except Exception as e:
197
+ # print(f"Error transcribing file: {e}")
198
+ # finally:
199
+ # self.release_cuda_memory()
200
+ # if not files:
201
+ # self.remove_input_files([file.name for file in files])
202
 
203
  @spaces.GPU(duration=120)
204
  def transcribe_mic(self,