File size: 1,468 Bytes
8fc1108
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8320308
8fc1108
 
 
 
 
 
8320308
 
8fc1108
 
 
 
 
 
3893b0e
8fc1108
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import gradio as gr


from translation import Translator, LANGUAGES
LANGUAGES_LIST = list(LANGUAGES.keys())


def translate_wrapper(text, src, trg, by_sentence=True, preprocess=True, random=False, num_beams=4):
    src_lang = LANGUAGES.get(src)
    tgt_lang = LANGUAGES.get(trg)
    # if src == trg:
    #     return 'Please choose two different languages'
    result = translator.translate(
        text=text,
        src_lang=src_lang,
        tgt_lang=tgt_lang,
        do_sample=random,
        num_beams=int(num_beams),
        by_sentence=by_sentence,
        preprocess=preprocess,
    )
    return result


article = """
This is a NLLB-200-600M model fine-tuned for translation between Español and Rapa Nui languages"""


interface = gr.Interface(
    translate_wrapper,
    [
        gr.Textbox(label="Text", lines=2, placeholder='text to translate '),
        gr.Dropdown(LANGUAGES_LIST, type="value", label='source language', value=LANGUAGES_LIST[1]),
        gr.Dropdown(LANGUAGES_LIST, type="value", label='target language', value=LANGUAGES_LIST[0]),
        gr.Checkbox(label="by sentence", value=True),
        gr.Checkbox(label="text preprocesing", value=True),
        gr.Checkbox(label="randomize", value=False),
        gr.Dropdown([1, 2, 3, 4, 5], label="number of beams", value=4),
    ],
    "text",
    title='Traductor Español-RapaNui',
    article=article,
)


if __name__ == '__main__':
    translator = Translator()

    interface.launch()