File size: 2,411 Bytes
b76bcf9
266419e
862d012
266419e
b76bcf9
266419e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b76bcf9
266419e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9aa8f59
33477ae
 
 
 
43f2d61
33477ae
 
9aa8f59
ed2627c
33477ae
 
 
 
 
 
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import gradio as gr
import pandas as pd
import os
from pyvi import ViTokenizer, ViPosTagger

pos_mapping = {
    "A": ("Adjective", "Tính từ"),
    "C": ("Coordinating conjunction", "Liên từ kết hợp"),
    "E": ("Preposition", "Giới từ"),
    "I": ("Interjection", "Thán từ"),
    "L": ("Determiner", "Hạn định từ"),
    "M": ("Numeral", "Số từ"),
    "N": ("Common noun", "Danh từ chung"),
    "Nc": ("Noun Classifier", "Lượng từ"),
    "Ny": ("Noun abbreviation", "Từ viết tắt danh từ"),
    "Np": ("Proper noun", "Danh từ riêng"),
    "Nu": ("Unit noun", "Danh từ đơn vị"),
    "P": ("Pronoun", "Đại từ"),
    "R": ("Adverb", "Trạng từ"),
    "S": ("Subordinating conjunction", "Liên từ phụ thuộc"),
    "T": ("Auxiliary, modal words", "Trợ từ, động từ tình thái"),
    "V": ("Verb", "Động từ"),
    "X": ("Unknown", "Không xác định"),
    "F": ("Filtered out (punctuation)", "Bị loại bỏ (dấu câu)")
}

def change(sentence):
    resutlt = ViPosTagger.postagging(ViTokenizer.tokenize(sentence))
    print(resutlt)
    words, pos_tags = resutlt
    pos_tags_engs = []
    pos_tags_vies = []
    for i in pos_tags:
        print(pos_mapping[i][0])
        print(pos_mapping[i][1])
        pos_tags_engs.append(pos_mapping[i][0])
        pos_tags_vies.append(pos_mapping[i][1])
    # final_result = ''''''
    # for word, pos_tag, pos_tags_eng, pos_tags_vie in zip(words, pos_tags, pos_tags_engs, pos_tags_vies):
    #     final_result += f"Từ: {word}, Loại từ: {pos_tag} ({pos_tags_eng} - {pos_tags_vie})\n"
    # return final_result

    header = f"{'Từ':<15} {'Loại từ':<10} {'English POS':<20} {'Tiếng Việt POS'}\n"
    header += "-" * 60 + "\n"
    rows = [f"{word:<15} {pos_tag:<10} {pos_tags_eng:<20} {pos_tags_vie}"
            for word, pos_tag, pos_tags_eng, pos_tags_vie in zip(words, pos_tags, pos_tags_engs, pos_tags_vies)]
    final_result = header + "\n".join(rows)
    return final_result


demo_interface = gr.Interface(
    fn=change,
    inputs="text",
    outputs="text",
    examples=eval(os.environ['DES_EXAMPLE']),
    description=os.environ['DES_DEMO']
)

intro_interface = gr.HTML(os.environ['DES_INTERFACE'])
tabbed_interface = gr.TabbedInterface(
    interface_list=[demo_interface, intro_interface],
    tab_names=["Demo", "Giới thiệu"]
)

tabbed_interface.launch()