from tool.file_name import * from ui.ui_component import * import gradio as gr import os def write_simple_transcribe_file(simple_transcribe_txt_list: list): with open(dir_simple_transcribe_file, "w", encoding="utf-8") as file: file.writelines(simple_transcribe_txt_list) def read_simple_transcribe_file(): with open(dir_simple_transcribe_file, "r", encoding="utf-8") as file: simple_transcribe_txt_list = file.readlines() return simple_transcribe_txt_list def write_transcribe_subtitle_file(transcribe_txt_list: list, subtitle_txt_list: list, write_adjusted_file: bool): transcribe = dir_base_transcribe_file subtitle = dir_base_subtitle_file if write_adjusted_file: transcribe = dir_adjusted_transcribe_file subtitle = dir_adjusted_subtitle_file with open(transcribe, "w", encoding="utf-8") as file: file.writelines(transcribe_txt_list) with open(subtitle, "w", encoding="utf-8") as file: file.writelines(subtitle_txt_list) def read_transcribe_subtitle_file(read_adjusted_file: bool): transcribe = dir_base_transcribe_file subtitle = dir_base_subtitle_file if read_adjusted_file: transcribe = dir_adjusted_transcribe_file subtitle = dir_adjusted_subtitle_file if not os.path.exists(transcribe): raise gr.Error(current_ui_lang["file_not_exist"] + ": Transcribe") if not os.path.exists(subtitle): raise gr.Error(current_ui_lang["file_not_exist"] + ": Subtitle") with open(transcribe, "r", encoding="utf-8") as file: transcribe_txt_list = file.readlines() with open(subtitle, "r", encoding="utf-8") as file: subtitle_txt_list = file.readlines() return transcribe_txt_list, subtitle_txt_list