File size: 1,161 Bytes
8911544
043440f
9fc880b
043440f
 
fdeaa3e
043440f
4146933
043440f
9fc880b
043440f
 
fdeaa3e
043440f
fdeaa3e
9fc880b
043440f
9fc880b
fdeaa3e
9fc880b
 
fdeaa3e
9fc880b
 
 
 
043440f
 
9fc880b
 
 
 
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
27
28
29
30
31
32
33
import gradio as gr
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM

# Load the grammar correction model and tokenizer
model_name = "hassaanik/grammar-correction-model"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)

# Function for grammar correction using the grammar correction model
def correct_grammar(text):
    # Tokenize the input text
    inputs = tokenizer.encode(text, return_tensors="pt", max_length=512, truncation=True)

    # Generate the corrected output from the model
    outputs = model.generate(inputs, max_length=512, num_beams=5, early_stopping=True)

    # Decode the generated tokens to get the corrected text
    corrected_text = tokenizer.decode(outputs[0], skip_special_tokens=True)

    return corrected_text

# Gradio interface for the grammar correction app
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()