zionia commited on
Commit
3b68341
1 Parent(s): ef9b88b

change token for src lang

Browse files
Files changed (1) hide show
  1. app.py +12 -4
app.py CHANGED
@@ -1,18 +1,25 @@
1
  import gradio as gr
2
- from transformers import pipeline, M2M100Tokenizer
3
 
4
  model_name = "dsfsi/nr-en-m2m100-gov"
5
  tokenizer = M2M100Tokenizer.from_pretrained(model_name)
 
6
 
7
- print(tokenizer.lang_code_to_token)
8
 
9
- translater_nr_en = pipeline("translation", model=model_name, src_lang="nr", tgt_lang="en")
 
 
 
 
 
 
10
 
11
  def translate(inp):
12
- # Translate from isiNdebele to English
13
  res = translater_nr_en(inp, max_length=512, early_stopping=True)[0]['translation_text']
14
  return res
15
 
 
16
  description = """
17
  <p>
18
  <center>
@@ -38,3 +45,4 @@ iface = gr.Interface(
38
  )
39
 
40
  iface.launch(enable_queue=True)
 
 
1
  import gradio as gr
2
+ from transformers import M2M100Tokenizer, M2M100ForConditionalGeneration, pipeline
3
 
4
  model_name = "dsfsi/nr-en-m2m100-gov"
5
  tokenizer = M2M100Tokenizer.from_pretrained(model_name)
6
+ model = M2M100ForConditionalGeneration.from_pretrained(model_name)
7
 
8
+ tokenizer.src_lang = "nr"
9
 
10
+ model.config.forced_bos_token_id = tokenizer.get_lang_id("en")
11
+
12
+ translater_nr_en = pipeline(
13
+ "translation",
14
+ model=model,
15
+ tokenizer=tokenizer,
16
+ )
17
 
18
  def translate(inp):
 
19
  res = translater_nr_en(inp, max_length=512, early_stopping=True)[0]['translation_text']
20
  return res
21
 
22
+ # Update description and article as needed
23
  description = """
24
  <p>
25
  <center>
 
45
  )
46
 
47
  iface.launch(enable_queue=True)
48
+