Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,29 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from transformers import pipeline
|
3 |
+
|
4 |
+
# Tải pipeline với mô hình sửa lỗi chính tả của bạn
|
5 |
+
@st.cache_resource
|
6 |
+
def load_corrector():
|
7 |
+
return pipeline("text2text-generation", model="hHoai/model_vietnamcorrection") # Thay "username/checkpoint-190" bằng đường dẫn đến mô hình của bạn
|
8 |
+
|
9 |
+
corrector = load_corrector()
|
10 |
+
MAX_LENGTH = 512
|
11 |
+
|
12 |
+
# Tiêu đề ứng dụng
|
13 |
+
st.title("Demo Sửa Lỗi Chính Tả")
|
14 |
+
st.write("Nhập vào văn bản tiếng Việt có lỗi, và công cụ sẽ đưa ra phiên bản đã được chỉnh sửa.")
|
15 |
+
|
16 |
+
# Nhập liệu từ người dùng
|
17 |
+
input_text = st.text_area("Nhập văn bản:", placeholder="Ví dụ: Kính chúc Bác, Mr.Trường va em Dật và các đồng bào yên hảo.", height=150)
|
18 |
+
|
19 |
+
if st.button("Sửa lỗi"):
|
20 |
+
if input_text.strip():
|
21 |
+
# Sửa lỗi chính tả
|
22 |
+
predictions = corrector([input_text], max_length=MAX_LENGTH)
|
23 |
+
corrected_text = predictions[0]["generated_text"]
|
24 |
+
|
25 |
+
# Hiển thị kết quả
|
26 |
+
st.subheader("Văn bản đã sửa:")
|
27 |
+
st.write(corrected_text)
|
28 |
+
else:
|
29 |
+
st.warning("Vui lòng nhập văn bản để sửa lỗi!")
|