Skip to content

Commit

Permalink
updated kudasai depedencies and cote replacements
Browse files Browse the repository at this point in the history
  • Loading branch information
Bikatr7 committed Dec 29, 2024
1 parent a8ddb46 commit fa3136b
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 13 deletions.
2 changes: 1 addition & 1 deletion jsons/cote_replacements.json
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@
"Manabe Shiho": ["真鍋","志保"],
"Mashima Tomonari": ["真嶋","智也"],
"Matsushita Chiaki": ["松下","千秋"],
"Minami Hakuo": ["南伯夫"],
"Minami Hakuo": ["","伯夫"],
"Miyake Akito": ["三宅","明人"],
"Miyamoto Sōshi":["宮本","蒼士"],
"Morishige Takurō": ["森重","卓郎"],
Expand Down
2 changes: 1 addition & 1 deletion kudasai.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ async def run_kudasai() -> None:
and Kudasai.knowledge_base != ""):
Kudasai.text_to_preprocess, indexing_log = Kudasai.run_kairyou_indexer(Kudasai.text_to_preprocess, Kudasai.replacement_json, Kudasai.knowledge_base)

preprocessed_text, preprocessing_log, error_log = Kairyou.preprocess(Kudasai.text_to_preprocess, Kudasai.replacement_json)
preprocessed_text, preprocessing_log, error_log = Kairyou.preprocess(Kudasai.text_to_preprocess, Kudasai.replacement_json, add_closing_period=True)

## Need to set this so auto-translation can use the preprocessed text
Kudasai.text_to_preprocess = preprocessed_text
Expand Down
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
backoff==2.2.1
gradio==4.44.0
kairyou==1.6.5
easytl==0.4.10
gradio==5.5.0
kairyou==1.6.7
easytl==0.5.1
python-dotenv
38 changes: 30 additions & 8 deletions webgui.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@

from kudasai import Kudasai

## since debug log doesn't update periodically, we need to somehow show progress updates in the gui for the translation tab, should get the info from backend somehow idk

##-------------------start-of-KudasaiGUI---------------------------------------------------------------------------------------------------------------------------------------------------------------------------

class KudasaiGUI:
Expand Down Expand Up @@ -106,7 +108,24 @@ def build_gui(self) -> None:
"""

with gr.Blocks(title="Kudasai", delete_cache=(300, 300), analytics_enabled=False) as self.gui:
with gr.Blocks(
title="Kudasai",
delete_cache=(300, 300),
analytics_enabled=False,
) as self.gui:
self.gui.load(
None,
None,
js="""
() => {
const params = new URLSearchParams(window.location.search);
if (!params.has('__theme')) {
params.set('__theme', 'dark');
window.location.search = params.toString();
}
}"""
)

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

##-------------------start-of-fetch_log_content()---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -860,12 +879,13 @@ def index(input_txt_file:gr.File, input_json_file_preprocessing:gr.File, input_k
else:
knowledge_base_paths = [file for file in input_knowledge_base_directory]


for file in knowledge_base_paths:
knowledge_base_string += gui_get_text_from_file(file)

gr.Info("Indexing may take a while, please be patient.")

unique_names, indexing_log = Indexer.index(text_to_index, knowledge_base_string, replacements)
unique_names, indexing_log = Indexer.index(text_to_index, knowledge_base_string, replacements, discard_ner_objects=False)

## Indexer does not directly log anything, in case of anything else touching it, we will grab the log from the log file
log_text = FileEnsurer.standard_read_file(FileEnsurer.debug_log_path)
Expand Down Expand Up @@ -922,7 +942,7 @@ def preprocess(input_txt_file:gr.File, input_json_file_preprocessing:gr.File, in

try:

preprocessed_text, preprocessing_log, error_log = Kairyou.preprocess(text_to_preprocess, replacements)
preprocessed_text, preprocessing_log, error_log = Kairyou.preprocess(text_to_preprocess, replacements, discard_ner_objects=False)

except InvalidReplacementJsonKeys:
## link needs to be updated later
Expand Down Expand Up @@ -1674,9 +1694,7 @@ def switch_translator_api_key_type(translation_method:str) -> str:
self.translator_translate_button.click(fn=fetch_log_content,
inputs=[],

outputs=[self.translator_debug_log_output_field], ## debug log on translator tab

every=.1) ## update every 100ms
outputs=[self.translator_debug_log_output_field])

##-------------------start-of translator_calculate_costs_button_click()---------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Expand Down Expand Up @@ -2157,8 +2175,12 @@ def toggle_text_inputs(file_input, text_input):
if current_time - KudasaiGUI.last_text_change < KudasaiGUI.debounce_delay:
# If it's a text change and we're within the debounce period, don't update
return gr.update(), gr.update()
self.last_text_change = current_time
return gr.update(placeholder=""), gr.update(interactive=not bool(file_input)), gr.update(interactive=not bool(text_input))
KudasaiGUI.last_text_change = current_time

return (
gr.update(placeholder="", interactive=not bool(file_input)), # text input update
gr.update(interactive=not bool(text_input)) # file input update
)


## For preprocessor
Expand Down

0 comments on commit fa3136b

Please sign in to comment.