Spaces:
Runtime error
Runtime error
File size: 739 Bytes
4a8c30f 5ef186d 0f464cc 5ef186d 0ae08c7 5ef186d fdd09e7 0f464cc 5ef186d |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
import torch
from transformers import pipeline
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
max_length = 512
device = 0 if torch.cuda.is_available() else "cpu"
model_id = "ArissBandoss/nllb-200-distilled-600M-finetuned-fr-to-mos-V1"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForSeq2SeqLM.from_pretrained(model_id)
def goai_traduction(text, src_lang, tgt_lang):
trans_pipe = pipeline("translation",
model=model, tokenizer=tokenizer,
src_lang=src_lang, tgt_lang=tgt_lang,
max_length=max_length,
device=device
)
return trans_pipe(text)[0]["translation_text"]
|