cointegrated commited on
Commit
54fb600
1 Parent(s): bc7c963

Use a newer model; add randomization; allow same lang

Browse files
Files changed (2) hide show
  1. .gitignore +1 -0
  2. app.py +9 -8
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ .idea
app.py CHANGED
@@ -1,13 +1,12 @@
1
  import gradio as gr
2
  import torch
3
  from transformers import NllbTokenizer, AutoModelForSeq2SeqLM
4
- MODEL_URL = 'slone/nllb-rus-tyv-v1'
5
- # tokenizer = NllbTokenizer.from_pretrained(MODEL_URL, force_download=True)
6
 
7
 
8
  lang_to_code = {
9
- 'Русский | Russian': 'rus_Cyrl',
10
- 'Тувинский | Tyvan': 'tyv_Cyrl',
11
  }
12
 
13
 
@@ -60,18 +59,19 @@ def translate(
60
  return out
61
 
62
 
63
- def translate_wrapper(text, src, trg, correct=None):
64
  src_lang = lang_to_code.get(src)
65
  tgt_lang = lang_to_code.get(trg)
66
- if src == trg:
67
- return 'Please choose two different languages'
68
- print(text, src, trg)
69
  result = translate(
70
  text=text,
71
  model=model,
72
  tokenizer=tokenizer,
73
  src_lang=src_lang,
74
  tgt_lang=tgt_lang,
 
 
75
  )
76
  return result
77
 
@@ -92,6 +92,7 @@ interface = gr.Interface(
92
  gr.Textbox(label="Text", lines=2, placeholder='text to translate '),
93
  gr.Dropdown(list(lang_to_code.keys()), type="value", label='source language', value=list(lang_to_code.keys())[0]),
94
  gr.Dropdown(list(lang_to_code.keys()), type="value", label='target language', value=list(lang_to_code.keys())[1]),
 
95
  ],
96
  "text",
97
  title='Tyvan-Russian translaton',
 
1
  import gradio as gr
2
  import torch
3
  from transformers import NllbTokenizer, AutoModelForSeq2SeqLM
4
+ MODEL_URL = 'slone/nllb-rus-tyv-v2-extvoc'
 
5
 
6
 
7
  lang_to_code = {
8
+ 'Орус | Русский | Russian': 'rus_Cyrl',
9
+ 'Тыва | Тувинский | Tyvan': 'tyv_Cyrl',
10
  }
11
 
12
 
 
59
  return out
60
 
61
 
62
+ def translate_wrapper(text, src, trg, random=False):
63
  src_lang = lang_to_code.get(src)
64
  tgt_lang = lang_to_code.get(trg)
65
+ # if src == trg:
66
+ # return 'Please choose two different languages'
 
67
  result = translate(
68
  text=text,
69
  model=model,
70
  tokenizer=tokenizer,
71
  src_lang=src_lang,
72
  tgt_lang=tgt_lang,
73
+ do_sample=random,
74
+ num_beams=1 if random else 4,
75
  )
76
  return result
77
 
 
92
  gr.Textbox(label="Text", lines=2, placeholder='text to translate '),
93
  gr.Dropdown(list(lang_to_code.keys()), type="value", label='source language', value=list(lang_to_code.keys())[0]),
94
  gr.Dropdown(list(lang_to_code.keys()), type="value", label='target language', value=list(lang_to_code.keys())[1]),
95
+ gr.Checkbox(label="random", value=False),
96
  ],
97
  "text",
98
  title='Tyvan-Russian translaton',