Skip to content

Commit

Permalink
added download all outputs button
Browse files Browse the repository at this point in the history
  • Loading branch information
Bikatr7 committed Sep 15, 2024
1 parent 40cb362 commit ea5ac29
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 4 deletions.
33 changes: 33 additions & 0 deletions lib/gui/save_to_zip.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
(...texts) =>
{
console.log("Starting save_to_zip function");

const sectionNames = [
"Indexed Text", "Indexing Results", "Indexing Debug Log",
"Preprocessed Text", "Preprocessing Results", "Preprocessing Debug Log",
"Translated Text", "JE Check Text", "Translator Debug Log",
"Overall Debug Log", "Error Log"
];

texts.forEach((text, index) =>
{
console.log(`Processing section: ${sectionNames[index]}`);
const fileName = `${sectionNames[index].replace(/ /g, '_').toLowerCase()}.txt`;
const blob = new Blob([text], { type: 'text/plain' });
const url = URL.createObjectURL(blob);
console.log("URL created:", url);

const a = document.createElement('a');
a.href = url;
a.download = fileName;
console.log("Download link created for", fileName);

a.click();
console.log("Download initiated for", fileName);

URL.revokeObjectURL(url);
console.log("URL revoked for", fileName);
});

console.log("save_to_zip function completed");
}
3 changes: 2 additions & 1 deletion modules/common/file_ensurer.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,9 @@ class FileEnsurer():
## favicon
favicon_path = os.path.join(gui_lib, "Kudasai_Logo.png")

## js save to file
## js
js_save_to_file_path = os.path.join(gui_lib, "save_to_file.js")
js_save_to_zip_path = os.path.join(gui_lib, "save_to_zip.js")

## translation settings description
translation_settings_description_path = os.path.join(common_lib, "translation_settings_description.txt")
Expand Down
48 changes: 45 additions & 3 deletions webgui.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ class KudasaiGUI:
with open(FileEnsurer.js_save_to_file_path, 'r', encoding='utf-8') as f:
js_save_to_file = f.read()

with open(FileEnsurer.js_save_to_zip_path, 'r', encoding='utf-8') as f:
js_save_to_zip = f.read()

## used for whether the debug log tab for Translator should be actively refreshing based of Logger.current_batch
is_translation_ongoing = False

Expand Down Expand Up @@ -92,7 +95,7 @@ class KudasaiGUI:

last_text_change = 0
debounce_delay = 2 ## 2 seconds

##-------------------start-of-build_gui()---------------------------------------------------------------------------------------------------------------------------------------------------------------------------

def build_gui(self) -> None:
Expand All @@ -104,7 +107,6 @@ def build_gui(self) -> None:
"""

with gr.Blocks(title="Kudasai", delete_cache=(300, 300)) as self.gui:

##-------------------start-of-Utility-Functions---------------------------------------------------------------------------------------------------------------------------------------------------------------------------

##-------------------start-of-fetch_log_content()---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -776,6 +778,11 @@ def create_new_key_value_tuple_pairs(translation_settings:typing.List[str]) -> t
with gr.Row():
self.logging_clear_logs_button = gr.Button('Clear Logs', variant='stop')

with gr.Tab("Output"):

with gr.Row():
self.download_all_outputs_button = gr.Button('Download All Outputs', elem_id="download-all-outputs-button")

##-------------------start-of-Listener-Functions---------------------------------------------------------------------------------------------------------------------------------------------------------------------------

def webgui_update_check() -> None:
Expand Down Expand Up @@ -2080,7 +2087,42 @@ def switch_translator_api_key_type(translation_method:str) -> str:
outputs=[],

## javascript code that allows us to save textbox contents to a file
js=(self.js_save_to_file).replace("downloaded_text.txt", "error_log.txt")
js=(self.js_save_to_zip).replace("downloaded_text.txt", "error_log.txt")
)

##-------------------start-of-download_all_outputs_click()---------------------------------------------------------------------------------------------------------------------------------------------------------------------------

self.download_all_outputs_button.click(
lambda indexed_text, indexing_results, indexing_debug,
preprocessed_text, preprocessing_results, preprocessing_debug,
translated_text, je_check_text, translator_debug,
logging_debug, logging_error:
f"Indexed Text:\n{indexed_text}\n\n"
f"Indexing Results:\n{indexing_results}\n\n"
f"Indexing Debug Log:\n{indexing_debug}\n\n"
f"Preprocessed Text:\n{preprocessed_text}\n\n"
f"Preprocessing Results:\n{preprocessing_results}\n\n"
f"Preprocessing Debug Log:\n{preprocessing_debug}\n\n"
f"Translated Text:\n{translated_text}\n\n"
f"JE Check Text:\n{je_check_text}\n\n"
f"Translator Debug Log:\n{translator_debug}\n\n"
f"Overall Debug Log:\n{logging_debug}\n\n"
f"Error Log:\n{logging_error}",
inputs=[
self.indexing_output_field,
self.indexing_results_output_field,
self.debug_log_output_field_indexing_tab,
self.preprocessing_output_field,
self.preprocessing_results_output_field,
self.debug_log_output_field_preprocess_tab,
self.translator_translated_text_output_field,
self.translator_je_check_text_output_field,
self.translator_debug_log_output_field,
self.logging_tab_debug_log_output_field,
self.logging_tab_error_log_output_field
],
outputs=[],
js=(self.js_save_to_zip)
)

##-------------------start-of-send_to_x_click()---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Expand Down

0 comments on commit ea5ac29

Please sign in to comment.