|
import gradio as gr |
|
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM |
|
|
|
|
|
model_name = "hassaanik/grammar-correction-model" |
|
tokenizer = AutoTokenizer.from_pretrained(model_name) |
|
model = AutoModelForSeq2SeqLM.from_pretrained(model_name) |
|
|
|
|
|
def correct_grammar(text): |
|
|
|
inputs = tokenizer.encode(text, return_tensors="pt", max_length=512, truncation=True) |
|
|
|
|
|
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 |
|
|
|
|
|
interface = gr.Interface( |
|
fn=correct_grammar, |
|
inputs="text", |
|
outputs="text", |
|
title="Grammar Correction App", |
|
description="Enter a sentence or paragraph to get grammar corrections using a Seq2Seq grammar correction model." |
|
) |
|
|
|
if __name__ == "__main__": |
|
interface.launch() |
|
|