👍️[Update] All : 不要なprintLogを削除 / なるべくtry exceptした場合にはerrorLogを保存するように変更

This commit is contained in:
misyaguziya
2024-12-16 23:38:05 +09:00
parent 030b8a9f01
commit 3fa819df3f
14 changed files with 73 additions and 67 deletions

View File

@@ -6,7 +6,7 @@ from .translation_utils import ctranslate2_weights
import ctranslate2
import transformers
from utils import printLog
from utils import errorLogging
import warnings
warnings.filterwarnings("ignore")
@@ -25,6 +25,7 @@ class Translator():
self.deepl_client = deepl_Translator(authkey)
self.deepl_client.translate_text(" ", target_lang="EN-US")
except Exception:
errorLogging()
self.deepl_client = None
result = False
return result
@@ -47,8 +48,8 @@ class Translator():
)
try:
self.ctranslate2_tokenizer = transformers.AutoTokenizer.from_pretrained(tokenizer, cache_dir=tokenizer_path)
except Exception as e:
printLog("error:changeCTranslate2Model()", e)
except Exception:
errorLogging()
tokenizer_path = os_path.join("./weights", "ctranslate2", directory_name, "tokenizer")
self.ctranslate2_tokenizer = transformers.AutoTokenizer.from_pretrained(tokenizer, cache_dir=tokenizer_path)
self.is_loaded_ctranslate2_model = True
@@ -67,7 +68,7 @@ class Translator():
target = results[0].hypotheses[0][1:]
result = self.ctranslate2_tokenizer.decode(self.ctranslate2_tokenizer.convert_tokens_to_ids(target))
except Exception:
pass
errorLogging()
return result
@staticmethod
@@ -138,8 +139,7 @@ class Translator():
source_language=source_language,
target_language=target_language,
)
except Exception as e:
from utils import errorLogging
errorLogging(e)
except Exception:
errorLogging()
result = False
return result

View File

@@ -5,7 +5,7 @@ from os import makedirs as os_makedirs
from requests import get as requests_get
from typing import Callable
import hashlib
from utils import printLog
from utils import errorLogging
ctranslate2_weights = {
"small": { # M2M-100 418M-parameter model
@@ -79,12 +79,11 @@ def downloadCTranslate2Weight(root, weight_type="small", callback=None, end_call
if isinstance(callback, Callable):
total_chunk += len(chunk)
callback(total_chunk/file_size)
printLog(f"Downloading CTranslate Model: {total_chunk/file_size:.0%}")
with ZipFile(os_path.join(tmp_path, filename)) as zf:
zf.extractall(path)
except Exception as e:
printLog("warning:downloadCTranslate2Weight()", e)
except Exception:
errorLogging()
if isinstance(end_callback, Callable):
end_callback()