Update app.py
Browse files
app.py
CHANGED
@@ -2,17 +2,19 @@ import gradio as gr
|
|
2 |
import difflib
|
3 |
|
4 |
def find_spelling_errors(s1, s2):
|
5 |
-
|
|
|
|
|
6 |
highlighted_text = []
|
7 |
|
8 |
for tag, i1, i2, j1, j2 in matcher.get_opcodes():
|
9 |
-
if tag in ['replace', 'delete']:
|
10 |
-
# Bôi đen
|
11 |
-
highlighted_text.append(f'<span style="color: black; font-weight: bold;">{
|
12 |
else:
|
13 |
-
highlighted_text.append(
|
14 |
|
15 |
-
return "".join(highlighted_text)
|
16 |
|
17 |
def process_text(wrong_text, corrected_text):
|
18 |
highlighted_text = find_spelling_errors(wrong_text, corrected_text)
|
@@ -21,15 +23,15 @@ def process_text(wrong_text, corrected_text):
|
|
21 |
demo = gr.Interface(
|
22 |
fn=process_text,
|
23 |
inputs=[
|
24 |
-
gr.Textbox(label="Câu có lỗi", placeholder="Nhập câu có lỗi chính tả..."
|
25 |
-
gr.Textbox(label="Câu đã sửa", placeholder="Nhập câu đã được sửa..."
|
26 |
],
|
27 |
outputs=[
|
28 |
gr.HTML(label="Phát hiện lỗi trong câu gốc"),
|
29 |
-
gr.Textbox(label="Văn bản đã sửa"
|
30 |
],
|
31 |
title="So sánh câu sai và câu đã sửa",
|
32 |
-
description="Các
|
33 |
)
|
34 |
|
35 |
demo.launch()
|
|
|
2 |
import difflib
|
3 |
|
4 |
def find_spelling_errors(s1, s2):
|
5 |
+
a = s1.split()
|
6 |
+
b = s2.split()
|
7 |
+
matcher = difflib.SequenceMatcher(None, a, b)
|
8 |
highlighted_text = []
|
9 |
|
10 |
for tag, i1, i2, j1, j2 in matcher.get_opcodes():
|
11 |
+
if tag in ['replace', 'delete']:
|
12 |
+
# Bôi đen các từ bị thay hoặc bị xóa trong câu có lỗi
|
13 |
+
highlighted_text.append(f'<span style="color: black; font-weight: bold;">{" ".join(a[i1:i2])}</span>')
|
14 |
else:
|
15 |
+
highlighted_text.append(" ".join(a[i1:i2]))
|
16 |
|
17 |
+
return " ".join(highlighted_text)
|
18 |
|
19 |
def process_text(wrong_text, corrected_text):
|
20 |
highlighted_text = find_spelling_errors(wrong_text, corrected_text)
|
|
|
23 |
demo = gr.Interface(
|
24 |
fn=process_text,
|
25 |
inputs=[
|
26 |
+
gr.Textbox(label="Câu có lỗi", placeholder="Nhập câu có lỗi chính tả..."),
|
27 |
+
gr.Textbox(label="Câu đã sửa", placeholder="Nhập câu đã được sửa...")
|
28 |
],
|
29 |
outputs=[
|
30 |
gr.HTML(label="Phát hiện lỗi trong câu gốc"),
|
31 |
+
gr.Textbox(label="Văn bản đã sửa")
|
32 |
],
|
33 |
title="So sánh câu sai và câu đã sửa",
|
34 |
+
description="Các từ bị sai trong câu gốc sẽ được bôi đen đậm."
|
35 |
)
|
36 |
|
37 |
demo.launch()
|