GrammarChecker / app.py
tanishkaguha's picture
Update app.py
681a5b0 verified
raw
history blame contribute delete
986 Bytes
import gradio as gr
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
import torch
# Load grammar correction model
model_name = "pszemraj/grammar-synthesis-small"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
# Grammar correction function
def correct_grammar(text):
input_text = "gec: " + text
inputs = tokenizer.encode(input_text, return_tensors="pt", 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
# Gradio Interface
gr.Interface(
fn=correct_grammar,
inputs=gr.Textbox(lines=7, placeholder="Enter your text here...", label="Input Text"),
outputs=gr.Textbox(label="Corrected Text"),
title="Grammar Checker (No Java)",
description="Uses a Hugging Face transformer model to fix grammar mistakes in English."
).launch()