nroggendorff commited on
Commit
fc893e7
1 Parent(s): e4032ff

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -19
app.py CHANGED
@@ -1,15 +1,12 @@
1
  import gradio as gr
2
 
3
-
4
  from translation import Translator, LANGUAGES, MODEL_URL
5
- LANGUAGES_LIST = list(LANGUAGES.keys())
6
 
 
7
 
8
  def translate_wrapper(text, src, trg, by_sentence=True, preprocess=True, random=False, num_beams=4):
9
  src_lang = LANGUAGES.get(src)
10
  tgt_lang = LANGUAGES.get(trg)
11
- # if src == trg:
12
- # return 'Please choose two different languages'
13
  result = translator.translate(
14
  text=text,
15
  src_lang=src_lang,
@@ -21,34 +18,28 @@ def translate_wrapper(text, src, trg, by_sentence=True, preprocess=True, random=
21
  )
22
  return result
23
 
24
-
25
  article = f"""
26
  This is the demo for a NLLB-200-600M model fine-tuned for a few (mostly new) languages.
27
-
28
  The model itself is available at https://huggingface.co/{MODEL_URL}
29
-
30
  If you want to host in on your own backend, consider running this dockerized app: https://github.com/slone-nlp/nllb-docker-demo.
31
  """
32
 
33
-
34
  interface = gr.Interface(
35
  translate_wrapper,
36
  [
37
- gr.Textbox(label="Text", lines=2, placeholder='text to translate '),
38
- gr.Dropdown(LANGUAGES_LIST, type="value", label='source language', value=LANGUAGES_LIST[0]),
39
- gr.Dropdown(LANGUAGES_LIST, type="value", label='target language', value=LANGUAGES_LIST[1]),
40
- gr.Checkbox(label="by sentence", value=True),
41
- gr.Checkbox(label="text preprocesing", value=True),
42
- gr.Checkbox(label="randomize", value=False),
43
- gr.Dropdown([1, 2, 3, 4, 5], label="number of beams", value=4),
44
  ],
45
  "text",
46
- title='Erzya-Russian translation',
47
  article=article,
48
  )
49
 
50
-
51
  if __name__ == '__main__':
52
  translator = Translator()
53
-
54
- interface.launch()
 
1
  import gradio as gr
2
 
 
3
  from translation import Translator, LANGUAGES, MODEL_URL
 
4
 
5
+ LANGUAGES_LIST = list(LANGUAGES.keys())
6
 
7
  def translate_wrapper(text, src, trg, by_sentence=True, preprocess=True, random=False, num_beams=4):
8
  src_lang = LANGUAGES.get(src)
9
  tgt_lang = LANGUAGES.get(trg)
 
 
10
  result = translator.translate(
11
  text=text,
12
  src_lang=src_lang,
 
18
  )
19
  return result
20
 
 
21
  article = f"""
22
  This is the demo for a NLLB-200-600M model fine-tuned for a few (mostly new) languages.
 
23
  The model itself is available at https://huggingface.co/{MODEL_URL}
 
24
  If you want to host in on your own backend, consider running this dockerized app: https://github.com/slone-nlp/nllb-docker-demo.
25
  """
26
 
 
27
  interface = gr.Interface(
28
  translate_wrapper,
29
  [
30
+ gr.Textbox(label="Text to Translate", lines=2, placeholder='Enter text to translate'),
31
+ gr.Dropdown(LANGUAGES_LIST, type="value", label='Source Language', value=LANGUAGES_LIST[0], description='Select the source language'),
32
+ gr.Dropdown(LANGUAGES_LIST, type="value", label='Target Language', value=LANGUAGES_LIST[1], description='Select the target language'),
33
+ gr.Checkbox(label="Translate by Sentence", value=True, description='If checked, the text will be translated sentence by sentence'),
34
+ gr.Checkbox(label="Apply Text Preprocessing", value=True, description='If checked, the text will be preprocessed before translation'),
35
+ gr.Checkbox(label="Randomize", value=False, description='If checked, the translation will use random sampling'),
36
+ gr.Slider(minimum=1, maximum=5, step=1, label="Number of Beams", value=4, description='Select the number of beams for the translation'),
37
  ],
38
  "text",
39
+ title='Erzya-Russian Translation',
40
  article=article,
41
  )
42
 
 
43
  if __name__ == '__main__':
44
  translator = Translator()
45
+ interface.launch()