File size: 917 Bytes
8bfd817
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import gradio as gr
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
import torch

# Load model and tokenizer
model_name = "prithivida/grammar_error_correcter_v1"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)

def correct_grammar(input_text):
    inputs = tokenizer.encode("gec: " + input_text, return_tensors="pt", max_length=128, truncation=True)
    outputs = model.generate(inputs, max_length=128, num_beams=5, early_stopping=True)
    corrected = tokenizer.decode(outputs[0], skip_special_tokens=True)
    return corrected

# Gradio Interface
iface = gr.Interface(
    fn=correct_grammar,
    inputs=gr.Textbox(lines=4, placeholder="Enter your sentence..."),
    outputs="text",
    title="Grammar Correction Tool",
    description="Enter text with errors. The model will return a grammatically corrected version."
)

iface.launch()