Spaces:
Runtime error
Runtime error
Update goai_traduction.py
Browse files- goai_traduction.py +21 -21
goai_traduction.py
CHANGED
@@ -1,21 +1,21 @@
|
|
1 |
-
import torch
|
2 |
-
from transformers import pipeline
|
3 |
-
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
|
4 |
-
|
5 |
-
max_length = 512
|
6 |
-
device = 0 if torch.cuda.is_available() else "cpu"
|
7 |
-
model_id = "ArissBandoss/nllb-200-distilled-600M-finetuned-
|
8 |
-
|
9 |
-
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
10 |
-
model = AutoModelForSeq2SeqLM.from_pretrained(model_id)
|
11 |
-
|
12 |
-
|
13 |
-
def goai_traduction(text, src_lang, tgt_lang):
|
14 |
-
trans_pipe = pipeline("translation",
|
15 |
-
model=model, tokenizer=tokenizer,
|
16 |
-
src_lang=src_lang, tgt_lang=tgt_lang,
|
17 |
-
max_length=max_length,
|
18 |
-
device=device
|
19 |
-
)
|
20 |
-
|
21 |
-
return trans_pipe(text)[0]["translation_text"]
|
|
|
1 |
+
import torch
|
2 |
+
from transformers import pipeline
|
3 |
+
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
|
4 |
+
|
5 |
+
max_length = 512
|
6 |
+
device = 0 if torch.cuda.is_available() else "cpu"
|
7 |
+
model_id = "ArissBandoss/nllb-200-distilled-600M-finetuned-mos-to-fr-V2"
|
8 |
+
|
9 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
10 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(model_id)
|
11 |
+
|
12 |
+
|
13 |
+
def goai_traduction(text, src_lang, tgt_lang):
|
14 |
+
trans_pipe = pipeline("translation",
|
15 |
+
model=model, tokenizer=tokenizer,
|
16 |
+
src_lang=src_lang, tgt_lang=tgt_lang,
|
17 |
+
max_length=max_length,
|
18 |
+
device=device
|
19 |
+
)
|
20 |
+
|
21 |
+
return trans_pipe(text)[0]["translation_text"]
|