File size: 986 Bytes
9c41890
681a5b0
 
9c41890
681a5b0
 
 
 
9c41890
681a5b0
 
 
 
 
 
 
9c41890
681a5b0
9c41890
681a5b0
 
 
 
 
9c41890
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 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()