hHoai's picture
Create app.py
38b7bd9 verified
raw
history blame
982 Bytes
import gradio as gr
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
# Load model từ Hugging Face
model_name = "hHoai/model_vietnamcorrection" # Thay bằng tên model của bạn
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
def correct_spelling(input_text):
# Tokenize input
inputs = tokenizer.encode(input_text, return_tensors="pt")
# Generate prediction
outputs = model.generate(inputs, max_length=512, num_beams=5, early_stopping=True)
# Decode output
corrected_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
return corrected_text
# Tạo giao diện Gradio
demo = gr.Interface(
fn=correct_spelling,
inputs="text",
outputs="text",
title="Spell Correction Demo",
description="Nhập câu tiếng Việt bị sai chính tả và nhận câu đã được sửa lỗi."
)
# Chạy demo
if __name__ == "__main__":
demo.launch()