Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,10 +1,8 @@
|
|
1 |
import gradio as gr
|
2 |
import difflib
|
3 |
-
import
|
4 |
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
|
5 |
|
6 |
-
nltk.download('punkt')
|
7 |
-
|
8 |
def load_model(checkpoint_path):
|
9 |
tokenizer = AutoTokenizer.from_pretrained(checkpoint_path)
|
10 |
model = AutoModelForSeq2SeqLM.from_pretrained(checkpoint_path)
|
@@ -34,31 +32,29 @@ def find_spelling_errors(s1, s2):
|
|
34 |
|
35 |
return " ".join(highlighted_text)
|
36 |
|
37 |
-
def
|
38 |
-
sentences =
|
39 |
corrected_sentences = []
|
40 |
highlighted_sentences = []
|
41 |
-
|
42 |
for sentence in sentences:
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
return highlighted_text, corrected_text
|
52 |
|
53 |
checkpoint_path = "Diezu/Batpho_v2"
|
54 |
model, tokenizer = load_model(checkpoint_path)
|
55 |
|
56 |
demo = gr.Interface(
|
57 |
-
fn=
|
58 |
-
inputs=gr.Textbox(placeholder="Nhập
|
59 |
-
outputs=[gr.HTML(label="Phát hiện lỗi"), gr.Textbox(label="Văn bản đã sửa"
|
60 |
title="Demo Sửa Lỗi Chính Tả",
|
61 |
-
description="Sử dụng mô hình để sửa lỗi chính
|
62 |
)
|
63 |
|
64 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
import difflib
|
3 |
+
import re
|
4 |
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
|
5 |
|
|
|
|
|
6 |
def load_model(checkpoint_path):
|
7 |
tokenizer = AutoTokenizer.from_pretrained(checkpoint_path)
|
8 |
model = AutoModelForSeq2SeqLM.from_pretrained(checkpoint_path)
|
|
|
32 |
|
33 |
return " ".join(highlighted_text)
|
34 |
|
35 |
+
def process_text(text):
|
36 |
+
sentences = re.split(r'(?<=[.!?])\s+', text)
|
37 |
corrected_sentences = []
|
38 |
highlighted_sentences = []
|
39 |
+
|
40 |
for sentence in sentences:
|
41 |
+
if sentence.strip():
|
42 |
+
corrected_text = correct_spelling(sentence)
|
43 |
+
highlighted_text = find_spelling_errors(sentence, corrected_text)
|
44 |
+
corrected_sentences.append(corrected_text)
|
45 |
+
highlighted_sentences.append(highlighted_text)
|
46 |
+
|
47 |
+
return "<br>".join(highlighted_sentences), "\n".join(corrected_sentences)
|
|
|
|
|
48 |
|
49 |
checkpoint_path = "Diezu/Batpho_v2"
|
50 |
model, tokenizer = load_model(checkpoint_path)
|
51 |
|
52 |
demo = gr.Interface(
|
53 |
+
fn=process_text,
|
54 |
+
inputs=gr.Textbox(placeholder="Nhập văn bản có lỗi chính tả..."),
|
55 |
+
outputs=[gr.HTML(label="Phát hiện lỗi"), gr.Textbox(label="Văn bản đã sửa")],
|
56 |
title="Demo Sửa Lỗi Chính Tả",
|
57 |
+
description="Sử dụng mô hình để sửa lỗi chính tả. Tách câu để xử lý nhanh hơn. Từ bị thay thế sẽ được gạch chân đỏ, từ bị xóa có màu cam gạch ngang, từ được thêm có màu xanh đậm."
|
58 |
)
|
59 |
|
60 |
demo.launch()
|