|
import gradio as gr |
|
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM |
|
|
|
|
|
model_name = "hHoai/model_vietnamcorrection" |
|
tokenizer = AutoTokenizer.from_pretrained(model_name) |
|
model = AutoModelForSeq2SeqLM.from_pretrained(model_name) |
|
|
|
def correct_spelling(input_text): |
|
|
|
inputs = tokenizer.encode(input_text, return_tensors="pt") |
|
|
|
outputs = model.generate(inputs, max_length=512, num_beams=5, early_stopping=True) |
|
|
|
corrected_text = tokenizer.decode(outputs[0], skip_special_tokens=True) |
|
return corrected_text |
|
|
|
|
|
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." |
|
) |
|
|
|
|
|
if __name__ == "__main__": |
|
demo.launch() |
|
|