File size: 1,930 Bytes
1cfde26
 
46fe50f
1cfde26
46fe50f
1cfde26
46fe50f
 
1cfde26
 
46fe50f
 
 
 
1cfde26
 
 
 
 
 
 
c45b82d
1cfde26
 
 
 
6f08302
 
1cfde26
 
 
 
 
 
16426d4
46fe50f
1cfde26
 
 
 
 
c45b82d
1cfde26
 
 
 
 
0839379
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 myv_translit import lat2cyr, cyr2lat, detect_script

DIRECTIONS = ['lat -> кир', 'кир -> lat']


def transliterator(input_text, direction, joint_acute=True, not_first_e_with_hacek=False, not_soft_l_after_vowels=True):
    first_e_with_hacek = not not_first_e_with_hacek
    soft_l_after_vowels = not not_soft_l_after_vowels
    if direction is None:
        code = detect_script(input_text)
        direction = DIRECTIONS[int(code != 'lat')]
    if direction == DIRECTIONS[1]:
        result = cyr2lat(input_text, joint_acute=joint_acute, first_e_with_hacek=first_e_with_hacek, soft_l_after_vowels=soft_l_after_vowels)
    else:
        result = lat2cyr(input_text, joint_acute=joint_acute, first_e_with_hacek=first_e_with_hacek, soft_l_after_vowels=soft_l_after_vowels)
    return result


article = """
Это автоматический транслитератор между кириллицей и латиницей для эрзянского языка.

В основе - алгоритм Михаила Потапова:
- https://github.com/potapoff271083/automatic_translation_latin_to_cyrillic
- http://valks.erzja.info/2020/04/30/эрзянский-алфавит/

Исходный код и обратная связь: https://github.com/slone-nlp/myv-translit
"""


interface = gr.Interface(
    transliterator,
    [
        gr.Textbox(label="Текст", lines=2, placeholder='text to transliterate'),
        gr.Radio(choices=DIRECTIONS, type="value", interactive=True, label='Направление'),
        gr.Checkbox(value=True, label='L + ́  -> Ĺ'),
        gr.Checkbox(value=False, label='ěrzä -> erzä'),
        gr.Checkbox(value=False, label='peĺks -> pelks'),
    ],
    "text",
    title='Эрзянь транслитератор <-> Ěrzäń transliterator',
    article=article,
)


if __name__ == '__main__':
    interface.launch(server_name="0.0.0.0")