Update modules/whisper/whisper_base.py
Browse files- modules/whisper/whisper_base.py +21 -29
modules/whisper/whisper_base.py
CHANGED
|
@@ -296,6 +296,9 @@ class WhisperBase(ABC):
|
|
| 296 |
file_count_total = 0
|
| 297 |
process_multiple = False
|
| 298 |
files = ""
|
|
|
|
|
|
|
|
|
|
| 299 |
|
| 300 |
if input_multi == "Audio":
|
| 301 |
files = files_audio
|
|
@@ -411,36 +414,25 @@ class WhisperBase(ABC):
|
|
| 411 |
|
| 412 |
# Add filename & info as first line
|
| 413 |
title_line = ""
|
| 414 |
-
tabbed_space =
|
| 415 |
-
if
|
| 416 |
-
if
|
| 417 |
-
|
| 418 |
-
title_line += f'{tabbed_space}
|
| 419 |
-
title_line += f'
|
| 420 |
-
if
|
| 421 |
-
|
| 422 |
-
|
| 423 |
-
|
| 424 |
-
temp_subtitle = info["subtitle"].rstrip("\n")
|
| 425 |
-
temp_subtitle = temp_subtitle.replace("\t","□")
|
| 426 |
-
temp_subtitle = temp_subtitle.replace("\n","■")
|
| 427 |
-
total_result += title_line+temp_subtitle
|
| 428 |
-
|
| 429 |
total_time += info["time_for_task"]
|
| 430 |
|
| 431 |
time_end = datetime.now()
|
|
|
|
| 432 |
#total_info += f"Total processing time:\t{self.format_time((time_end-time_start).total_seconds())}"
|
| 433 |
-
|
| 434 |
-
|
| 435 |
-
|
| 436 |
-
|
| 437 |
-
if diarize_speakers:
|
| 438 |
-
if total_info != "": total_info += "\n"
|
| 439 |
-
total_info += "Diarization:\tEnabled"
|
| 440 |
-
if total_info != "": total_info += "\n\n"
|
| 441 |
-
total_info += f"Processed {file_count} {'file' if file_count == 1 else 'files'} in {self.format_time((time_end-time_start).total_seconds())}"
|
| 442 |
-
|
| 443 |
-
result_str = self.transform_text_to_list(total_result,"□","■") #Transform to gr.Dataframe format
|
| 444 |
result_file_path = [info['path'] for info in files_to_download.values()]
|
| 445 |
|
| 446 |
return [result_str,result_file_path,total_info]
|
|
@@ -636,12 +628,12 @@ class WhisperBase(ABC):
|
|
| 636 |
gc.collect()
|
| 637 |
|
| 638 |
@staticmethod
|
| 639 |
-
def transform_text_to_list(inputdata: str
|
| 640 |
outputdata = []
|
| 641 |
-
temp_inputdata =
|
| 642 |
for temp_line in temp_inputdata:
|
| 643 |
temp_line_list = []
|
| 644 |
-
temp_line_items = temp_line.split(
|
| 645 |
for temp_line_item in temp_line_items:
|
| 646 |
temp_line_list.append(temp_line_item)
|
| 647 |
outputdata.append(temp_line_list)
|
|
|
|
| 296 |
file_count_total = 0
|
| 297 |
process_multiple = False
|
| 298 |
files = ""
|
| 299 |
+
|
| 300 |
+
char_tab = "#TAB#"
|
| 301 |
+
char_newline = "#NEWLINE#"
|
| 302 |
|
| 303 |
if input_multi == "Audio":
|
| 304 |
files = files_audio
|
|
|
|
| 414 |
|
| 415 |
# Add filename & info as first line
|
| 416 |
title_line = ""
|
| 417 |
+
tabbed_space = char_tab*3
|
| 418 |
+
if add_timestamp_preview: title_line += char_tab
|
| 419 |
+
if diarize_speakers: title_line += char_tab
|
| 420 |
+
title_line += f'{tabbed_space}Media file:{char_tab}{info["input_source_file"]}'
|
| 421 |
+
title_line += f'{char_newline}{tabbed_space}Language:{char_tab}{info["lang"]} (probability {info["lang_prob"]}%)'
|
| 422 |
+
if params.is_translate: title_line += f'{char_newline}{tabbed_space}Translation:{char_tab}{info["transcription"]} (Handled by OpenAI Whisper)'
|
| 423 |
+
if translate_output: title_line += f'{char_newline}{tabbed_space}Translation:{char_tab}{info["translation"]} (Handled by Facebook NLLB)'
|
| 424 |
+
title_line += char_newline
|
| 425 |
+
|
| 426 |
+
total_result += title_line+info["subtitle"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 427 |
total_time += info["time_for_task"]
|
| 428 |
|
| 429 |
time_end = datetime.now()
|
| 430 |
+
total_info = f"Processed {file_count} {'file' if file_count == 1 else 'files'} in {self.format_time((time_end-time_start).total_seconds())}"
|
| 431 |
#total_info += f"Total processing time:\t{self.format_time((time_end-time_start).total_seconds())}"
|
| 432 |
+
|
| 433 |
+
result_str = self.transform_text_to_list(total_result) #Transform to gr.Dataframe format
|
| 434 |
+
result_str = result_str.replace(char_tab,"\t")
|
| 435 |
+
result_str = result_str.replace(char_newline,"\n")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 436 |
result_file_path = [info['path'] for info in files_to_download.values()]
|
| 437 |
|
| 438 |
return [result_str,result_file_path,total_info]
|
|
|
|
| 628 |
gc.collect()
|
| 629 |
|
| 630 |
@staticmethod
|
| 631 |
+
def transform_text_to_list(inputdata: str) -> list:
|
| 632 |
outputdata = []
|
| 633 |
+
temp_inputdata = inputdata.strip.split("\n")
|
| 634 |
for temp_line in temp_inputdata:
|
| 635 |
temp_line_list = []
|
| 636 |
+
temp_line_items = temp_line.split("\t")
|
| 637 |
for temp_line_item in temp_line_items:
|
| 638 |
temp_line_list.append(temp_line_item)
|
| 639 |
outputdata.append(temp_line_list)
|