georgescutelnicu
commited on
Commit
•
b9b22c3
1
Parent(s):
27568b2
Upload translator.py
Browse files- translator.py +5 -5
translator.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
from deep_translator import GoogleTranslator
|
2 |
from transformers import pipeline
|
3 |
import translators as ts
|
4 |
|
@@ -38,24 +38,24 @@ class MangaTranslator:
|
|
38 |
def _translate_with_google(self, text):
|
39 |
translator = GoogleTranslator(source=self.source, target=self.target)
|
40 |
translated_text = translator.translate(text)
|
41 |
-
return translated_text if translated_text
|
42 |
|
43 |
def _translate_with_hf(self, text):
|
44 |
pipe = pipeline("translation", model=f"Helsinki-NLP/opus-mt-ja-en")
|
45 |
translated_text = pipe(text)[0]["translation_text"]
|
46 |
-
return translated_text if translated_text
|
47 |
|
48 |
def _translate_with_baidu(self, text):
|
49 |
translated_text = ts.translate_text(text, translator="baidu",
|
50 |
from_language="jp",
|
51 |
to_language=self.target)
|
52 |
-
return translated_text if translated_text
|
53 |
|
54 |
def _translate_with_bing(self, text):
|
55 |
translated_text = ts.translate_text(text, translator="bing",
|
56 |
from_language=self.source,
|
57 |
to_language=self.target)
|
58 |
-
return translated_text if translated_text
|
59 |
|
60 |
def _preprocess_text(self, text):
|
61 |
preprocessed_text = text.replace(".", ".")
|
|
|
1 |
+
from deep_translator import GoogleTranslator
|
2 |
from transformers import pipeline
|
3 |
import translators as ts
|
4 |
|
|
|
38 |
def _translate_with_google(self, text):
|
39 |
translator = GoogleTranslator(source=self.source, target=self.target)
|
40 |
translated_text = translator.translate(text)
|
41 |
+
return translated_text if translated_text is not None else text
|
42 |
|
43 |
def _translate_with_hf(self, text):
|
44 |
pipe = pipeline("translation", model=f"Helsinki-NLP/opus-mt-ja-en")
|
45 |
translated_text = pipe(text)[0]["translation_text"]
|
46 |
+
return translated_text if translated_text is not None else text
|
47 |
|
48 |
def _translate_with_baidu(self, text):
|
49 |
translated_text = ts.translate_text(text, translator="baidu",
|
50 |
from_language="jp",
|
51 |
to_language=self.target)
|
52 |
+
return translated_text if translated_text is not None else text
|
53 |
|
54 |
def _translate_with_bing(self, text):
|
55 |
translated_text = ts.translate_text(text, translator="bing",
|
56 |
from_language=self.source,
|
57 |
to_language=self.target)
|
58 |
+
return translated_text if translated_text is not None else text
|
59 |
|
60 |
def _preprocess_text(self, text):
|
61 |
preprocessed_text = text.replace(".", ".")
|