autosumm / translation /translation.py
mhsvieira's picture
Add timer
a9e7556
raw
history blame
605 Bytes
from deep_translator import GoogleTranslator
from easynmt import EasyNMT
from utils.timing import Timer
@Timer.time_it('tradução', 'translation')
def translate(text, source_language, target_language):
try:
print("Trying to use Google Translator...")
return GoogleTranslator(source = source_language, target = target_language).translate(text)
except:
print("Google Translator is not working... using M2M100")
translation_model = EasyNMT('m2m_100_418M')
return translation_model.translate(text, source_lang = source_language, target_lang = target_language)