File size: 1,110 Bytes
2501a98
cf1f5b8
0a1a5c9
cf1f5b8
0a1a5c9
2501a98
 
0a1a5c9
d016bfd
 
 
 
2b0ff86
cf1f5b8
 
956953f
2b0ff86
2501a98
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import gradio as gr
from transformers import AutoTokenizer
from optimum.onnxruntime import ORTModelForSeq2SeqLM
from optimum.pipelines import pipeline


def check_grammar(sentence):
  tokenizer = AutoTokenizer.from_pretrained("leslyarun/grammatical-error-correction-quantized")
  model = ORTModelForSeq2SeqLM.from_pretrained("leslyarun/grammatical-error-correction-quantized",
                                                   encoder_file_name="encoder_model_quantized.onnx",
                                                   decoder_file_name="decoder_model_quantized.onnx",
                                                   decoder_with_past_file_name="decoder_with_past_model_quantized.onnx")
  
  text2text_generator = pipeline("text2text-generation", model=model, tokenizer=tokenizer)
  output = text2text_generator("grammar: " + sentence)
  return output[0]["generated_text"]

  
demo = gr.Interface(check_grammar, inputs=['text'],
                    outputs="text",
                    title = "English Grammar Corrector")
                    
if __name__ == "__main__":
    demo.launch(debug=True)