Spaces:
Runtime error
Runtime error
anyantudre
commited on
Commit
•
5ef186d
1
Parent(s):
9f0bf0f
Rename translation.py to goai_traduction.py
Browse files- goai_traduction.py +18 -0
- translation.py +0 -10
goai_traduction.py
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import pipeline
|
2 |
+
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
|
3 |
+
|
4 |
+
max_length = 512
|
5 |
+
model_id = "ArissBandoss/nllb-200-distilled-600M-finetuned-fr-to-mos-V1"
|
6 |
+
|
7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
8 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(model_id)
|
9 |
+
|
10 |
+
|
11 |
+
def traduction(text, src_lang, tgt_lang):
|
12 |
+
trans_pipe = pipeline("translation",
|
13 |
+
model=model, tokenizer=tokenizer,
|
14 |
+
src_lang=src_lang, tgt_lang=tgt_lang,
|
15 |
+
max_length=max_length
|
16 |
+
)
|
17 |
+
|
18 |
+
return trans_pipe(text)[0]["translation_text"]
|
translation.py
DELETED
@@ -1,10 +0,0 @@
|
|
1 |
-
from transformers import pipeline
|
2 |
-
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
|
3 |
-
|
4 |
-
tokenizer = AutoTokenizer.from_pretrained("facebook/nllb-200-distilled-600M")
|
5 |
-
model = AutoModelForSeq2SeqLM.from_pretrained("facebook/nllb-200-distilled-600M")
|
6 |
-
|
7 |
-
|
8 |
-
def translation(text, src_lang, tgt_lang):
|
9 |
-
trans_pipe = pipeline("translation", model=model, tokenizer=tokenizer, src_lang=src_lang, tgt_lang=tgt_lang, max_length=400)
|
10 |
-
return trans_pipe(text)[0]["translation_text"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|