anyantudre commited on
Commit
0f464cc
1 Parent(s): 4561589

Update goai_traduction.py

Browse files
Files changed (1) hide show
  1. goai_traduction.py +2 -0
goai_traduction.py CHANGED
@@ -2,6 +2,7 @@ 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)
@@ -13,6 +14,7 @@ def goai_traduction(text, src_lang, tgt_lang):
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"]
 
2
  from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
3
 
4
  max_length = 512
5
+ device = 0 if torch.cuda.is_available() else "cpu"
6
  model_id = "ArissBandoss/nllb-200-distilled-600M-finetuned-fr-to-mos-V1"
7
 
8
  tokenizer = AutoTokenizer.from_pretrained(model_id)
 
14
  model=model, tokenizer=tokenizer,
15
  src_lang=src_lang, tgt_lang=tgt_lang,
16
  max_length=max_length
17
+ device=device
18
  )
19
 
20
  return trans_pipe(text)[0]["translation_text"]