From 522b8b03d7996716de97fdd923b7f4fe686e2eab Mon Sep 17 00:00:00 2001 From: Piero Toffanin Date: Mon, 30 Oct 2023 00:09:52 -0400 Subject: [PATCH] Fix some warnings --- libretranslate/detect.py | 4 ++-- libretranslate/language.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libretranslate/detect.py b/libretranslate/detect.py index 5aee048..559aea8 100644 --- a/libretranslate/detect.py +++ b/libretranslate/detect.py @@ -17,7 +17,8 @@ def load_detector(langcodes = ()): for lc in langcodes: try: languages.append(linguars.Language.from_iso_code_639_1(lc)) - except: + except Exception as e: + print(f"{lc} is not supported by lingua") pass # Not supported return linguars.LanguageDetector(languages=languages) @@ -29,7 +30,6 @@ class Detector: def detect(self, text): top_3_choices = self.detector.confidence(text)[:3] - print(top_3_choices) if top_3_choices[0][1] == 0: return [Language("en", 0)] return [Language(lang.iso_code_639_1, round(conf * 100)) for lang, conf in top_3_choices] diff --git a/libretranslate/language.py b/libretranslate/language.py index 6cebb95..cc647b1 100644 --- a/libretranslate/language.py +++ b/libretranslate/language.py @@ -37,8 +37,8 @@ def detect_languages(text): for i in range(len(d)): d[i].text_length = len(t) candidates.extend(d) - except: - pass + except Exception as e: + print(str(e)) # total read bytes of the provided text text_length_total = sum(c.text_length for c in candidates)