Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,7 +1,10 @@
|
|
1 |
import gradio as gr
|
2 |
import difflib
|
|
|
3 |
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
|
4 |
|
|
|
|
|
5 |
def load_model(checkpoint_path):
|
6 |
tokenizer = AutoTokenizer.from_pretrained(checkpoint_path)
|
7 |
model = AutoModelForSeq2SeqLM.from_pretrained(checkpoint_path)
|
@@ -31,20 +34,31 @@ def find_spelling_errors(s1, s2):
|
|
31 |
|
32 |
return " ".join(highlighted_text)
|
33 |
|
34 |
-
def
|
35 |
-
|
36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
37 |
return highlighted_text, corrected_text
|
38 |
|
39 |
checkpoint_path = "Diezu/Batpho_v2"
|
40 |
model, tokenizer = load_model(checkpoint_path)
|
41 |
|
42 |
demo = gr.Interface(
|
43 |
-
fn=
|
44 |
-
inputs=gr.Textbox(placeholder="Nhập văn
|
45 |
-
outputs=[gr.HTML(label="Phát hiện lỗi"), gr.Textbox(label="Văn bản đã sửa")],
|
46 |
title="Demo Sửa Lỗi Chính Tả",
|
47 |
-
description="Sử dụng mô hình để sửa lỗi chính
|
48 |
)
|
49 |
|
50 |
demo.launch()
|
|
|
1 |
import gradio as gr
|
2 |
import difflib
|
3 |
+
import nltk
|
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 |
|
35 |
return " ".join(highlighted_text)
|
36 |
|
37 |
+
def process_paragraph(text):
|
38 |
+
sentences = nltk.sent_tokenize(text) # Chia đoạn văn thành câu
|
39 |
+
corrected_sentences = []
|
40 |
+
highlighted_sentences = []
|
41 |
+
|
42 |
+
for sentence in sentences:
|
43 |
+
corrected = correct_spelling(sentence)
|
44 |
+
highlighted = find_spelling_errors(sentence, corrected)
|
45 |
+
corrected_sentences.append(corrected)
|
46 |
+
highlighted_sentences.append(highlighted)
|
47 |
+
|
48 |
+
highlighted_text = " ".join(highlighted_sentences)
|
49 |
+
corrected_text = " ".join(corrected_sentences)
|
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=process_paragraph,
|
58 |
+
inputs=gr.Textbox(placeholder="Nhập đoạn văn có lỗi chính tả...", lines=5),
|
59 |
+
outputs=[gr.HTML(label="Phát hiện lỗi"), gr.Textbox(label="Văn bản đã sửa", lines=5)],
|
60 |
title="Demo Sửa Lỗi Chính Tả",
|
61 |
+
description="Sử dụng mô hình để sửa lỗi chính tả trong đoạn vă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."
|
62 |
)
|
63 |
|
64 |
demo.launch()
|