hHoai commited on
Commit
38b7bd9
·
verified ·
1 Parent(s): 905784c

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -0
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
3
+
4
+ # Load model từ Hugging Face
5
+ model_name = "hHoai/model_vietnamcorrection" # Thay bằng tên model của bạn
6
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
7
+ model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
8
+
9
+ def correct_spelling(input_text):
10
+ # Tokenize input
11
+ inputs = tokenizer.encode(input_text, return_tensors="pt")
12
+ # Generate prediction
13
+ outputs = model.generate(inputs, max_length=512, num_beams=5, early_stopping=True)
14
+ # Decode output
15
+ corrected_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
16
+ return corrected_text
17
+
18
+ # Tạo giao diện Gradio
19
+ demo = gr.Interface(
20
+ fn=correct_spelling,
21
+ inputs="text",
22
+ outputs="text",
23
+ title="Spell Correction Demo",
24
+ description="Nhập câu tiếng Việt bị sai chính tả và nhận câu đã được sửa lỗi."
25
+ )
26
+
27
+ # Chạy demo
28
+ if __name__ == "__main__":
29
+ demo.launch()