Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -11,7 +11,7 @@ def spellcheck(text):
|
|
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 |
|
@@ -19,12 +19,13 @@ def spellcheck(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 |
-
|
|
|
26 |
|
27 |
-
return "Có lỗi chính tả", corrected_text,
|
28 |
|
29 |
with gr.Blocks() as demo:
|
30 |
gr.Markdown("# Demo Kiểm tra lỗi chính tả tiếng Việt")
|
@@ -32,14 +33,18 @@ with gr.Blocks() as demo:
|
|
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 |
-
|
|
|
|
|
|
|
|
|
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()
|
|
|
11 |
end_time = time.time()
|
12 |
|
13 |
if response.status_code != 200:
|
14 |
+
return "Lỗi kết nối API", text, "", "", ""
|
15 |
|
16 |
result = response.json()
|
17 |
|
|
|
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_words = "\n".join([e['word'] for e in errors])
|
26 |
+
suggestions = "\n".join([', '.join(e['suggestions']) if e['suggestions'] else 'Xóa bỏ' for e in errors])
|
27 |
|
28 |
+
return "Có lỗi chính tả", corrected_text, error_words, suggestions, processing_time
|
29 |
|
30 |
with gr.Blocks() as demo:
|
31 |
gr.Markdown("# Demo Kiểm tra lỗi chính tả tiếng Việt")
|
|
|
33 |
input_text = gr.Textbox(label="Nhập văn bản")
|
34 |
output_status = gr.Textbox(label="Trạng thái", interactive=False)
|
35 |
output_corrected = gr.Textbox(label="Văn bản sau khi sửa", interactive=False)
|
36 |
+
|
37 |
+
with gr.Row():
|
38 |
+
output_errors = gr.Textbox(label="Từ sai", lines=4, interactive=False)
|
39 |
+
output_suggestions = gr.Textbox(label="Gợi ý sửa", lines=4, interactive=False)
|
40 |
+
|
41 |
output_time = gr.Textbox(label="Thời gian xử lý", interactive=False)
|
42 |
|
43 |
submit_btn = gr.Button("Kiểm tra lỗi")
|
44 |
|
45 |
+
submit_btn.click(spellcheck, inputs=input_text, outputs=[output_status, output_corrected, output_errors, output_suggestions, output_time])
|
46 |
|
47 |
gr.Markdown("### Ví dụ: Nhập văn bản có lỗi chính tả để kiểm tra")
|
48 |
|
49 |
if __name__ == "__main__":
|
50 |
+
demo.launch()
|