Spaces:
Sleeping
Sleeping
Update translator.py
Browse files- translator.py +5 -4
translator.py
CHANGED
@@ -17,14 +17,12 @@ class MangaTranslator:
|
|
17 |
def translate(self, text, method="google"):
|
18 |
"""
|
19 |
Translates the given text to the target language using the specified method.
|
20 |
-
|
21 |
Args:
|
22 |
text (str): The text to be translated.
|
23 |
method (str):"google" for Google Translator,
|
24 |
"hf" for Helsinki-NLP's opus-mt-ja-es model (HF pipeline)
|
25 |
"baidu" for Baidu Translate
|
26 |
"bing" for Microsoft Bing Translator
|
27 |
-
|
28 |
Returns:
|
29 |
str: The translated text.
|
30 |
"""
|
@@ -58,5 +56,8 @@ class MangaTranslator:
|
|
58 |
return translated_text if translated_text is not None else text
|
59 |
|
60 |
def _preprocess_text(self, text):
|
61 |
-
|
62 |
-
|
|
|
|
|
|
|
|
17 |
def translate(self, text, method="google"):
|
18 |
"""
|
19 |
Translates the given text to the target language using the specified method.
|
|
|
20 |
Args:
|
21 |
text (str): The text to be translated.
|
22 |
method (str):"google" for Google Translator,
|
23 |
"hf" for Helsinki-NLP's opus-mt-ja-es model (HF pipeline)
|
24 |
"baidu" for Baidu Translate
|
25 |
"bing" for Microsoft Bing Translator
|
|
|
26 |
Returns:
|
27 |
str: The translated text.
|
28 |
"""
|
|
|
56 |
return translated_text if translated_text is not None else text
|
57 |
|
58 |
def _preprocess_text(self, text):
|
59 |
+
# Asegurarse de que el texto esté en codificación UTF-8
|
60 |
+
if isinstance(text, bytes):
|
61 |
+
text = text.decode('utf-8')
|
62 |
+
preprocessed_text = text.replace(".", ".") # Reemplazo si es necesario
|
63 |
+
return preprocessed_text
|