File size: 605 Bytes
c16fec3
 
a9e7556
c16fec3
a9e7556
c16fec3
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
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)