leslyarun's picture
Update app.py
0a1a5c9
raw
history blame
855 Bytes
import gradio as gr
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
from optimum.onnxruntime import ORTModelForSeq2SeqLM
def check_grammar(sentence):
tokenizer = AutoTokenizer.from_pretrained("leslyarun/grammatical-error-correction-quantized")
model = ORTModelForSeq2SeqLM.from_pretrained("leslyarun/grammatical-error-correction-quantized")
inputs = tokenizer("grammar: " + sentence, return_tensors='pt')
output = model.generate(inputs['input_ids'], num_beams=5, max_length=512, early_stopping=True)
correction = tokenizer.batch_decode(output, skip_special_tokens=True)
return "".join(correction)
demo = gr.Interface(check_grammar, inputs=['text'],
outputs="text",
title = "English Grammar Corrector")
if __name__ == "__main__":
demo.launch(debug=True)