File size: 2,977 Bytes
3a379e2
 
 
 
 
87c6a48
 
 
 
3a379e2
 
c58e97a
87c6a48
 
 
 
 
 
 
 
 
c58e97a
3a379e2
 
1022780
3a379e2
6aa67c2
3a379e2
87c6a48
3a379e2
 
 
 
 
 
16bdc89
afbd3c6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1022780
afbd3c6
1022780
afbd3c6
 
1022780
afbd3c6
1022780
afbd3c6
2062585
afbd3c6
 
 
 
 
 
 
 
 
16bdc89
 
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
67
68
69
70
71
72
73
74
75
76
import gradio as gr
import siameser
import norm_typing
import json
import logging
# import os
# import parameters
# import stat
# import utils

std = siameser.Siameser(stadard_scope='all')

# directory = parameters.LOG_DIRECTORY
# file_path = os.path.join(directory, parameters.LOG_RESULT_FILE)
# if not os.path.exists(directory):
#     os.mkdir(directory)
#     os.chmod(directory, stat.S_IRWXU)
#     data = []
#     with open(file_path, 'w', encoding='utf8') as f:
#         json.dump(data, f, ensure_ascii=False, indent=4)
#     os.chmod(file_path, stat.S_IRUSR | stat.S_IWUSR)

count = 0

def standardize(raw_address_input):
    global count
    raw_address = norm_typing.norm_vietnamese_sentence_accent(raw_address_input)    
    top_1, top_5 = std.get_top_k(raw_address, 5)
    # utils.save_result(file_path, top_5)
    count += 1
    if count % 10 == 9:
        print(f'Request: {count}')
    return top_1, top_5


with gr.Blocks() as iface:
    gr.Markdown("## Chuẩn hóa địa chỉ tiếng Việt")
    gr.Markdown(
        """
        Công cụ sử dụng để chuẩn hóa địa chỉ tiếng Việt. <br>
        Nhập vào 1 câu địa chỉ thô (ví dụ ở dưới), mô hình sẽ chuẩn hóa thành địa chỉ chuẩn dưới dạng bảng, gồm 2 phần: <br>
        * **Địa chỉ chi tiết (Detail Address):** thông tin về số nhà, ngõ ngách, hẻm,... <br>
        * **Địa chỉ chính (Main Address):** hiển thị tối đa 3 trên 4 trường: đường/phố, phường/xã, quận/huyện, tỉnh/thành phố. <br>
        """
    )
    with gr.Row():
        raw_address_input = gr.Textbox(
            label='Raw Address', 
            placeholder="Nhập địa chỉ thô"
        )
    with gr.Row():
        clear_button = gr.Button("Clear", scale=1)
        submit_button = gr.Button("Submit", variant="primary", scale=1)

    with gr.Row():
        standard_address_output = gr.JSON(
            label='Standard Address', 
            # headers=["Detail Address", "Street", "Ward", "District", "City"]
        )
    with gr.Row():
        top5_addresses_output = gr.JSON(
            label='Top 5 Standard Addresses', 
            # headers=["Detail Address", "Street", "Ward", "District", "City"]
        )
    submit_button.click(standardize, inputs=raw_address_input, outputs=[standard_address_output, top5_addresses_output], api_name="standardize")
    clear_button.click(lambda: "", inputs=[], outputs=[raw_address_input])
    gr.Examples([
        ['1 dong khoi str., dist. 1 ,hcmc'],
        ['112/21 bạch đằng, p.2, tân bình, tp. hồ chí minh'], 
        ['văn phòng và căn hộ cao cấp licogi 13 tower , thanh xuân , hn'],
        ['dablend hostel, 417/2 hoà hảo, phường 5, quận 10, hồ chí minh, vietnam'],
        ['17-05, tower 4,the sun avenue, 28 mai chi tho, district 2, ho chi minh city']
    ], inputs=raw_address_input)

if __name__ == "__main__":
    iface.launch()