Skip to content

Commit

Permalink
some mass correction of logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Bikatr7 committed May 14, 2024
1 parent fbe383e commit 4af36e0
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 20 deletions.
4 changes: 2 additions & 2 deletions handlers/json_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ def validate_json() -> None:

JsonHandler.current_translation_settings = FileEnsurer.INVALID_TRANSLATION_SETTINGS_PLACEHOLDER

logging.info(f"translation_settings.json is valid, current:"
logging.debug(f"translation_settings.json is valid, current:"
f"\n{JsonHandler.current_translation_settings}")

##-------------------start-of-reset_translation_settings_to_default()---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -313,7 +313,7 @@ def log_translation_settings(output_to_console:bool=False) -> None:

for key,value in JsonHandler.current_translation_settings[section].items():
log_message = key + " : " + str(value)
logging.info(log_message)
logging.debug(log_message)
if(output_to_console):
print(log_message)

Expand Down
9 changes: 6 additions & 3 deletions kudasai.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def boot() -> None:

FileEnsurer.setup_needed_files()

logging.info(f"Kudasai started; Current version : {Toolkit.CURRENT_VERSION}")
logging.debug(f"Kudasai started; Current version : {Toolkit.CURRENT_VERSION}")

try:

Expand Down Expand Up @@ -336,8 +336,8 @@ def print_usage_statement():

FileEnsurer.standard_create_directory(FileEnsurer.output_dir)

## setup logging
## Setup logging

## Debug log setup
debug_log_handler = logging.FileHandler(FileEnsurer.debug_log_path, mode='w+', encoding='utf-8')
debug_log_handler.setLevel(logging.DEBUG)
Expand All @@ -363,4 +363,7 @@ def print_usage_statement():
logger.addHandler(error_log_handler)
logger.addHandler(console)

## Ensure only INFO level and above messages are sent to the console
console.setLevel(logging.INFO)

asyncio.run(main())
13 changes: 8 additions & 5 deletions modules/common/file_ensurer.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,10 @@ def purge_storage() -> None:
"""

if(not FileEnsurer.is_hugging_space()):
logging.debug("Not running on Hugging Face, skipping storage purge")
return

logging.debug("Running on Hugging Face, purging storage")

stuff_to_purge = [
FileEnsurer.secrets_dir,
Expand Down Expand Up @@ -247,7 +250,7 @@ def standard_create_directory(directory_path:str) -> None:

if(os.path.isdir(directory_path) == False):
os.makedirs(directory_path)
logging.info(directory_path + " created due to lack of the folder")
logging.debug(directory_path + " created due to lack of the folder")

##--------------------start-of-standard_create_file()------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Expand All @@ -265,7 +268,7 @@ def standard_create_file(file_path:str) -> None:
"""

if(os.path.exists(file_path) == False):
logging.info(file_path + " was created due to lack of the file")
logging.debug(file_path + " was created due to lack of the file")
with open(file_path, "w+", encoding="utf-8") as file:
file.truncate()

Expand All @@ -291,7 +294,7 @@ def modified_create_file(file_path:str, content_to_write:str) -> bool:
did_overwrite = False

if(os.path.exists(file_path) == False or os.path.getsize(file_path) == 0):
logging.info(file_path + " was created due to lack of the file or because it is blank")
logging.debug(file_path + " was created due to lack of the file or because it is blank")
with open(file_path, "w+", encoding="utf-8") as file:
file.write(content_to_write)

Expand Down Expand Up @@ -322,7 +325,7 @@ def standard_overwrite_file(file_path:str, content_to_write:str, omit:bool = Tru
if(omit):
content_to_write = "(Content was omitted)"

logging.info(file_path + " was overwritten with the following content: " + content_to_write)
logging.debug(file_path + " was overwritten with the following content: " + content_to_write)

##--------------------start-of-clear_file()------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Expand All @@ -342,7 +345,7 @@ def clear_file(file_path:str) -> None:
with open(file_path, "w+", encoding="utf-8") as file:
file.truncate()

logging.info(file_path + " was cleared")
logging.debug(file_path + " was cleared")

##--------------------start-of-standard_read_file()------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Expand Down
5 changes: 5 additions & 0 deletions modules/common/toolkit.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import os
import typing
import logging
import platform
import subprocess

Expand Down Expand Up @@ -209,6 +210,8 @@ def check_update() -> typing.Tuple[bool, str]:

if(LooseVersion(latest_version) > LooseVersion(Toolkit.CURRENT_VERSION)):

logging.debug("New update available: " + latest_version)

update_prompt += "There is a new update for Kudasai (" + latest_version + ")\nIt is recommended that you use the latest version of Kudasai\nYou can download it at https://github.com/Bikatr7/Kudasai/releases/latest \n"

if(release_notes):
Expand All @@ -219,6 +222,8 @@ def check_update() -> typing.Tuple[bool, str]:
## used to determine if user lacks an internet connection.
except:

logging.debug("No internet connection detected.")

print("You seem to lack an internet connection, this will prevent you from checking from update notification and machine translation.\n")

Toolkit.pause_console()
Expand Down
18 changes: 9 additions & 9 deletions modules/common/translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ async def commence_translation(is_webgui:bool=False) -> None:
"""

logging.info(f"Translator Activated, Translation Method : {Translator.TRANSLATION_METHOD}"
logging.debug(f"Translator Activated, Translation Method : {Translator.TRANSLATION_METHOD}"
f"Settings are as follows : ")

JsonHandler.log_translation_settings()
Expand Down Expand Up @@ -568,21 +568,21 @@ def generate_text_to_translate_batches(index:int) -> tuple[typing.List[str],int]

if(any(char in sentence for char in ["▼", "△", "◇"])):
prompt.append(f'{sentence}\n')
logging.info(f"Sentence : {sentence}, Sentence is a pov change... adding to prompt.")
logging.debug(f"Sentence : {sentence}, Sentence is a pov change... adding to prompt.")

elif(stripped_sentence == ''):
logging.info(f"Sentence : {sentence} is empty... skipping.")
logging.debug(f"Sentence : {sentence} is empty... skipping.")

elif(is_part_in_sentence or all(char in ["1","2","3","4","5","6","7","8","9", " "] for char in sentence)):
prompt.append(f'{sentence}\n')
logging.info(f"Sentence : {sentence}, Sentence is part marker... adding to prompt.")
logging.debug(f"Sentence : {sentence}, Sentence is part marker... adding to prompt.")

elif(non_word_pattern.match(sentence) or KatakanaUtil.is_punctuation(stripped_sentence) and not has_quotes):
logging.info(f"Sentence : {sentence}, Sentence is punctuation... skipping.")
logging.debug(f"Sentence : {sentence}, Sentence is punctuation... skipping.")

else:
prompt.append(f'{sentence}\n')
logging.info(f"Sentence : {sentence}, Sentence is a valid sentence... adding to prompt.")
logging.debug(f"Sentence : {sentence}, Sentence is a valid sentence... adding to prompt.")

else:
return prompt, index
Expand Down Expand Up @@ -650,7 +650,7 @@ def build_translation_batches() -> None:

logging_message += message + "\n"

logging.info(logging_message)
logging.debug(logging_message)

##-------------------start-of-handle_cost_estimate_prompt()---------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Expand Down Expand Up @@ -784,7 +784,7 @@ async def handle_translation(model:str,
## will only occur if the max_batch_duration is exceeded, so we just return the untranslated text
except MaxBatchDurationExceededException:

logging.error(f"Batch {batch_number} of {length_of_batch//2} was not translated due to exceeding the max request duration, returning the untranslated text...")
logging.warning(f"Batch {batch_number} of {length_of_batch//2} was not translated due to exceeding the max request duration, returning the untranslated text...")
break

## do not even bother if not a gpt 4 model, because gpt-3 seems unable to format properly
Expand All @@ -802,7 +802,7 @@ async def handle_translation(model:str,

else:
num_tries += 1
logging.error(f"Batch {batch_number} of {length_of_batch//2} was malformed, retrying...")
logging.warning(f"Batch {batch_number} of {length_of_batch//2} was malformed, retrying...")
Translator.num_occurred_malformed_batches += 1

if(isinstance(text_to_translate, ModelTranslationMessage)):
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
backoff==2.2.1
gradio==4.19.2
kairyou==1.5.0
easytl==0.3.2
easytl==0.3.3

0 comments on commit 4af36e0

Please sign in to comment.