HugoZeballos commited on
Commit
8fc1108
1 Parent(s): 3563422

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -0
app.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+
3
+
4
+ from translation import Translator, LANGUAGES
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,
16
+ tgt_lang=tgt_lang,
17
+ do_sample=random,
18
+ num_beams=int(num_beams),
19
+ by_sentence=by_sentence,
20
+ preprocess=preprocess,
21
+ )
22
+ return result
23
+
24
+
25
+ article = """
26
+ This is a NLLB-200-600M model fine-tuned for translation between Russian and Tyvan (Tuvan) languages,
27
+ using the data from https://tyvan.ru/.
28
+ This model is described in https://cointegrated.medium.com/a37fc706b865.
29
+ If you want to host in on your own backend, consider running this dockerized app: https://github.com/slone-nlp/nllb-docker-demo.
30
+ """
31
+
32
+
33
+ interface = gr.Interface(
34
+ translate_wrapper,
35
+ [
36
+ gr.Textbox(label="Text", lines=2, placeholder='text to translate '),
37
+ gr.Dropdown(LANGUAGES_LIST, type="value", label='source language', value=LANGUAGES_LIST[0]),
38
+ gr.Dropdown(LANGUAGES_LIST, type="value", label='target language', value=LANGUAGES_LIST[1]),
39
+ gr.Checkbox(label="by sentence", value=True),
40
+ gr.Checkbox(label="text preprocesing", value=True),
41
+ gr.Checkbox(label="randomize", value=False),
42
+ gr.Dropdown([1, 2, 3, 4, 5], label="number of beams", value=4),
43
+ ],
44
+ "text",
45
+ title='Tyvan-Russian translaton',
46
+ article=article,
47
+ )
48
+
49
+
50
+ if __name__ == '__main__':
51
+ translator = Translator()
52
+
53
+ interface.launch()