Spaces:
Runtime error
Runtime error
File size: 799 Bytes
2501a98 2b0ff86 2501a98 2b0ff86 2501a98 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
import gradio as gr
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
def check_grammar(sentence):
tokenizer = AutoTokenizer.from_pretrained("leslyarun/grammatical-error-correction")
model = AutoModelForSeq2SeqLM.from_pretrained("leslyarun/grammatical-error-correction")
inputs = tokenizer("grammar: " + sentence, truncation=True, 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) |