Skip to content

Commit

Permalink
update build version, some documentation changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Bikatr7 committed May 17, 2024
1 parent 92ce812 commit eaade4c
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 11 deletions.
55 changes: 47 additions & 8 deletions modules/common/file_ensurer.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ class FileEnsurer():
##----------------------------------/

## output files
preprocessed_text_path = os.path.join(output_dir, "preprocessed_text.txt") ## path for the preprocessed text
translated_text_path = os.path.join(output_dir, "translated_text.txt") ## path for translated text
preprocessed_text_path = os.path.join(output_dir, "preprocessed_text.txt")
translated_text_path = os.path.join(output_dir, "translated_text.txt")

je_check_path = os.path.join(output_dir, "je_check_text.txt") ## path for je check text (text generated by the translation modules to compare against the translated text)
je_check_path = os.path.join(output_dir, "je_check_text.txt")

kairyou_log_path = os.path.join(output_dir, "preprocessing_results.txt") ## path for kairyou log (the results of preprocessing)
error_log_path = os.path.join(output_dir, "error_log.txt") ## path for the error log (errors generated by the preprocessing and translation modules)
debug_log_path = os.path.join(output_dir, "debug_log.txt") ## path for the debug log (debug info generated by the preprocessing and translation modules)
kairyou_log_path = os.path.join(output_dir, "preprocessing_results.txt")
error_log_path = os.path.join(output_dir, "error_log.txt")
debug_log_path = os.path.join(output_dir, "debug_log.txt")

## translation settings
external_translation_settings_path = os.path.join(script_dir,'translation_settings.json')
Expand Down Expand Up @@ -139,6 +139,9 @@ def is_hugging_space() -> bool:
Determines if Kudasai is running on a Hugging Face server.
Returns:
bool : whether or not Kudasai is running on a Hugging Face server.
"""

return os.path.exists(FileEnsurer.hugging_face_flag)
Expand Down Expand Up @@ -168,6 +171,9 @@ def setup_needed_files() -> None:
Ensures that the required files and directories exist.
Decorated By:
permission_error_decorator
"""


Expand Down Expand Up @@ -200,6 +206,9 @@ def purge_storage() -> None:
In case of hugging face, purges the storage.
Decorated By:
permission_error_decorator
"""

if(not FileEnsurer.is_hugging_space()):
Expand Down Expand Up @@ -253,6 +262,9 @@ def standard_create_directory(directory_path:str) -> None:
Parameters:
directory_path (str) : path to the directory to be created.
Decorated By:
permission_error_decorator
"""

if(os.path.isdir(directory_path) == False):
Expand All @@ -272,6 +284,9 @@ def standard_create_file(file_path:str) -> None:
Parameters:
file_path (str) : path to the file to be created.
Decorated By:
permission_error_decorator
"""

if(os.path.exists(file_path) == False):
Expand All @@ -296,6 +311,9 @@ def modified_create_file(file_path:str, content_to_write:str) -> bool:
Returns:
bool : whether or not the file was overwritten.
Decorated By:
permission_error_decorator
"""

did_overwrite = False
Expand All @@ -322,7 +340,10 @@ def standard_overwrite_file(file_path:str, content_to_write:str, omit:bool = Tru
Parameters:
file_path (str) : path to the file to be overwritten.
content to write (str) : content to be written to the file.
omit (bool | optional) : whether or not to omit the content from the log.
omit (bool | optional | default=True) : whether or not to omit the content from the log.
Decorated By:
permission_error_decorator
"""

Expand All @@ -347,6 +368,9 @@ def clear_file(file_path:str) -> None:
Parameters:
file_path (str) : path to the file to be cleared.
Decorated By:
permission_error_decorator
"""

with open(file_path, "w+", encoding="utf-8") as file:
Expand All @@ -370,6 +394,9 @@ def standard_read_file(file_path:str) -> str:
Returns:
content (str) : the content of the file.
Decorated By:
permission_error_decorator
"""

with open(file_path, "r", encoding="utf-8") as file:
Expand All @@ -389,11 +416,14 @@ def handle_critical_exception(critical_exception:Exception) -> None:
Parameters:
critical_exception (object - Exception) : the exception to be handled.
Decorated By:
permission_error_decorator
"""

traceback_msg = traceback.format_exc()

logging.error(f"Kudasai has crashed"
logging.error(f"Kudasai has crashed "
f"Please send the following to the developer on github at https://github.com/Bikatr7/Kudasai/issues :"
f"{traceback_msg}")

Expand All @@ -417,6 +447,9 @@ def archive_results(list_of_result_tuples:typing.List[typing.Tuple[str,str]], mo
module (str) : name of the module that generated the results.
timestamp (str) : timestamp of when the results were generated.
Decorated By:
permission_error_decorator
"""

archival_path = os.path.join(FileEnsurer.archive_dir, f'{module}_run_{timestamp}')
Expand Down Expand Up @@ -445,6 +478,9 @@ def standard_read_json(file_path:str) -> dict:
Returns:
json_object (dict) : the json object.
Decorated By:
permission_error_decorator
"""

with open(file_path, "r", encoding="utf-8") as file:
Expand All @@ -468,6 +504,9 @@ def write_kairyou_results(text_to_preprocess:str, preprocessing_log:str, error_l
error_log (str) : the log of any errors that occurred during preprocessing.
timestamp (str) : the timestamp of when the results were generated (Can be obtained from Toolkit.get_timestamp(is_archival=True))
Decorated By:
permission_error_decorator
"""

## ensures the output directory exists, cause it could get moved or fucked with.
Expand Down
6 changes: 4 additions & 2 deletions modules/common/toolkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Toolkit():
"""

CURRENT_VERSION = "v3.4.5-beta"
CURRENT_VERSION = "v3.4.5-beta-2"

##-------------------start-of-clear_console()---------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Expand Down Expand Up @@ -91,7 +91,6 @@ def pause_console(message:str="Press any key to continue...") -> None:
termios.tcsetattr(0, termios.TCSANOW, old_settings)

except ImportError:

pass

##-------------------start-of-maximize_window()---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -187,6 +186,9 @@ def check_update(do_pause:bool=True) -> typing.Tuple[bool, str]:
Determines if Kudasai has a new latest release, and confirms if an internet connection is present or not.
Parameters:
do_pause (bool | optional | default=True) : Whether or not to pause the console after displaying the update prompt.
Returns:
is_connection (bool) : Whether or not the user has an internet connection.
update_prompt (str) : The update prompt to be displayed to the user, can either be blank if there is no update or contain the update prompt if there is an update.
Expand Down
7 changes: 6 additions & 1 deletion modules/common/translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Translator:
## meanwhile for gemini, we just need to send the prompt and the text to be translated concatenated together
gemini_translation_batches:typing.List[str] = []

## same as above, but for deepl
## same as above, but for deepl, just the text to be translated
deepl_translation_batches:typing.List[str] = []

num_occurred_malformed_batches = 0
Expand Down Expand Up @@ -125,6 +125,9 @@ def log_failure(details) -> None:
Parameters:
details (dict) : the details of the failure.
Raises:
MaxBatchDurationExceededException : An exception that is raised when the max batch duration is exceeded.
"""

error_msg = f"Exceeded allowed duration of {details['wait']} seconds, returning untranslated text after {details['tries']} tries {details['target']}."
Expand Down Expand Up @@ -322,6 +325,8 @@ def reset_static_variables() -> None:
Translator.num_occurred_malformed_batches = 0
Translator.translation_print_result = ""
Translator.TRANSLATION_METHOD = "openai"
Translator.pre_provided_api_key = ""
Translator.is_cli = False

##-------------------start-of-check-settings()---------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Expand Down

0 comments on commit eaade4c

Please sign in to comment.