CaoHaiNam's picture
update code
87c6a48
raw
history blame contribute delete
No virus
2.59 kB
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):
global count
raw_address = norm_typing.norm_vietnamese_sentence_accent(raw_address)
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
demo = gr.Interface(
fn=standardize,
inputs=gr.Textbox(label='raw address', lines=1, placeholder="Nhập địa chỉ thô"),
outputs=[gr.JSON(label='stadard address'), gr.JSON(label='top 5 standard addresses')],
allow_flagging='auto',
title='Chuẩn hóa địa chỉ tiếng Việt',
description='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 json, gồm 2 phần: <br> \
* Địa chỉ chi tiết (detail address): thông tin về số nhà, ngõ ngách, hẻm,... được cung cấp trong địa chỉ thô. <br> \
* Địa chỉ chính (main address): hiển thị dưới dạng dict, gồm tối đa 3 trên 4 trường thông tin: đường/phố, phường/xã, quận/huyện, tỉnh/thành phố. <br>\
* Trong trường hợp địa chỉ thô xuất hiện cả tên đường và phường, thì địa chỉ chính chỉ chứa tên đường mà không cần phường (vì như thế đã đủ để xác định ví trí rồi). <br>',
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'
],
article='Contact<br>Email: chnhust1@gmail.com'
)
demo.launch()