Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import requests
|
3 |
+
import time
|
4 |
+
|
5 |
+
def spellcheck(text):
|
6 |
+
url = "https://spellcheck.vcntt.tech/spellcheck"
|
7 |
+
data = {"text": text}
|
8 |
+
|
9 |
+
start_time = time.time()
|
10 |
+
response = requests.post(url, json=data)
|
11 |
+
end_time = time.time()
|
12 |
+
|
13 |
+
if response.status_code != 200:
|
14 |
+
return "Lỗi kết nối API", "", "", ""
|
15 |
+
|
16 |
+
result = response.json()
|
17 |
+
|
18 |
+
corrected_text = result.get("corrected_text", text)
|
19 |
+
processing_time = f"{end_time - start_time:.4f} giây"
|
20 |
+
|
21 |
+
if not result.get("has_errors", False):
|
22 |
+
return "Không có lỗi chính tả", corrected_text, "", processing_time
|
23 |
+
|
24 |
+
errors = result.get("errors", [])
|
25 |
+
error_info = "\n".join([f"Từ sai: '{e['word']}' - Gợi ý: {', '.join(e['suggestions']) if e['suggestions'] else 'Không có gợi ý'}" for e in errors])
|
26 |
+
|
27 |
+
return "Có lỗi chính tả", corrected_text, error_info, processing_time
|
28 |
+
|
29 |
+
with gr.Blocks() as demo:
|
30 |
+
gr.Markdown("# Demo Kiểm tra lỗi chính tả tiếng Việt")
|
31 |
+
|
32 |
+
input_text = gr.Textbox(label="Nhập văn bản")
|
33 |
+
output_status = gr.Textbox(label="Trạng thái", interactive=False)
|
34 |
+
output_corrected = gr.Textbox(label="Văn bản sau khi sửa", interactive=False)
|
35 |
+
output_errors = gr.Textbox(label="Chi tiết lỗi", lines=5, interactive=False)
|
36 |
+
output_time = gr.Textbox(label="Thời gian xử lý", interactive=False)
|
37 |
+
|
38 |
+
submit_btn = gr.Button("Kiểm tra lỗi")
|
39 |
+
|
40 |
+
submit_btn.click(spellcheck, inputs=input_text, outputs=[output_status, output_corrected, output_errors, output_time])
|
41 |
+
|
42 |
+
gr.Markdown("### Ví dụ: Nhập văn bản có lỗi chính tả để kiểm tra")
|
43 |
+
|
44 |
+
if __name__ == "__main__":
|
45 |
+
demo.launch()
|