LAP-DEV commited on
Commit
c6ec656
·
verified ·
1 Parent(s): a3bea99

Update modules/whisper/whisper_base.py

Browse files
Files changed (1) hide show
  1. modules/whisper/whisper_base.py +15 -14
modules/whisper/whisper_base.py CHANGED
@@ -220,6 +220,7 @@ class WhisperBase(ABC):
220
  model = whisper.load_model("base")
221
 
222
  files_info = {}
 
223
  for file in files:
224
 
225
  ## Detect language
@@ -240,16 +241,16 @@ class WhisperBase(ABC):
240
  *whisper_params,
241
  )
242
 
243
- # file_name, file_ext = os.path.splitext(os.path.basename(file))
244
- # subtitle, file_path = self.generate_and_write_file(
245
- # file_name=file_name,
246
- # transcribed_segments=transcribed_segments,
247
- # add_timestamp=add_timestamp,
248
- # file_format=file_format,
249
- # output_dir=self.output_dir
250
- # )
251
- #
252
- # files_info[file_name] = {"subtitle": subtitle, "time_for_task": time_for_task, "path": file_path, "lang": file_language}
253
 
254
  ## Add output file as txt
255
  file_name, file_ext = os.path.splitext(os.path.basename(file))
@@ -260,7 +261,7 @@ class WhisperBase(ABC):
260
  file_format="txt",
261
  output_dir=self.output_dir
262
  )
263
- files_info[file_name+"_txt"] = {"subtitle": subtitle, "time_for_task": time_for_task, "path": file_path, "lang": file_language}
264
 
265
  ## Add output file as srt
266
  file_name, file_ext = os.path.splitext(os.path.basename(file))
@@ -271,7 +272,7 @@ class WhisperBase(ABC):
271
  file_format="srt",
272
  output_dir=self.output_dir
273
  )
274
- files_info[file_name+"_srt"] = {"subtitle": subtitle, "time_for_task": time_for_task, "path": file_path, "lang": file_language}
275
 
276
  total_result = ''
277
  total_info = ''
@@ -282,12 +283,12 @@ class WhisperBase(ABC):
282
  #total_info += f'{info["lang"]}'
283
  total_info += f"Language {info['lang']} detected"
284
  # Just get first line:
285
- break
286
 
287
  #result_str = f"Processing of file '{file_name}{file_ext}' done in {self.format_time(total_time)}:\n\n{total_result}"
288
  total_info += f"\nTranscription process done in {self.format_time(total_time)}"
289
  result_str = total_result
290
- result_file_path = [info['path'] for info in files_info.values()]
291
 
292
  return [result_str, result_file_path, total_info]
293
 
 
220
  model = whisper.load_model("base")
221
 
222
  files_info = {}
223
+ files_to_download = {}
224
  for file in files:
225
 
226
  ## Detect language
 
241
  *whisper_params,
242
  )
243
 
244
+ file_name, file_ext = os.path.splitext(os.path.basename(file))
245
+ subtitle, file_path = self.generate_and_write_file(
246
+ file_name=file_name,
247
+ transcribed_segments=transcribed_segments,
248
+ add_timestamp=add_timestamp,
249
+ file_format=file_format,
250
+ output_dir=self.output_dir
251
+ )
252
+
253
+ files_info[file_name] = {"subtitle": subtitle, "time_for_task": time_for_task, "path": file_path, "lang": file_language}
254
 
255
  ## Add output file as txt
256
  file_name, file_ext = os.path.splitext(os.path.basename(file))
 
261
  file_format="txt",
262
  output_dir=self.output_dir
263
  )
264
+ files_to_download[file_name+"_txt"] = {"subtitle": subtitle, "time_for_task": time_for_task, "path": file_path, "lang": file_language}
265
 
266
  ## Add output file as srt
267
  file_name, file_ext = os.path.splitext(os.path.basename(file))
 
272
  file_format="srt",
273
  output_dir=self.output_dir
274
  )
275
+ files_to_download[file_name+"_srt"] = {"subtitle": subtitle, "time_for_task": time_for_task, "path": file_path, "lang": file_language}
276
 
277
  total_result = ''
278
  total_info = ''
 
283
  #total_info += f'{info["lang"]}'
284
  total_info += f"Language {info['lang']} detected"
285
  # Just get first line:
286
+ #break
287
 
288
  #result_str = f"Processing of file '{file_name}{file_ext}' done in {self.format_time(total_time)}:\n\n{total_result}"
289
  total_info += f"\nTranscription process done in {self.format_time(total_time)}"
290
  result_str = total_result
291
+ result_file_path = [info['path'] for info in files_to_download.values()]
292
 
293
  return [result_str, result_file_path, total_info]
294