File size: 268 Bytes
46e7aa4
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
from transformers import pipeline

def load_translator(language1, language2):
    modelo = f"Helsinki-NLP/opus-mt-{language1}-{language2}"
    return pipeline('translation', model=modelo)

def translator(text, pipe):
    return pipe(text)[0]['translation_text']