File size: 1,632 Bytes
a3e54de
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import gradio as gr
from transformers import pipeline
import torch

# Load the Grammarly CoEdit model for grammar & spelling correction
pipe = pipeline("text2text-generation", 
                model="grammarly/coedit-large",
                torch_dtype=torch.bfloat16)

def correct_grammar(text: str) -> str:
    """
    Takes an English sentence or paragraph and returns
    a grammatically and orthographically corrected version.
    """
    # Generate corrected text
    outputs = pipe(
        text,
        max_length=256,
        num_beams=5,
        early_stopping=True
    )
    return outputs[0]["generated_text"]

# Build a simple Gradio interface
with gr.Blocks(theme=gr.themes.Default()) as demo:
    gr.Markdown(
        """
        # πŸ“ Grammar & Spelling Corrector  
        Paste or type any English sentence below and receive a corrected version  
        powered by `grammarly/coedit-large`.
        """
    )

    with gr.Row():
        inp = gr.Textbox(
            label="✍️ Input Text",
            placeholder="Type a sentence or paragraph here…",
            lines=4,
            show_copy_button=True
        )
        out = gr.Textbox(
            label="βœ… Corrected Text",
            placeholder="The corrected text will appear here.",
            lines=4,
            interactive=False,
            show_copy_button=True
        )

    btn = gr.Button("βœ”οΈ Correct Grammar")
    btn.click(fn=correct_grammar, inputs=inp, outputs=out)

    gr.Markdown(
        """
        ---  
        Built with πŸ€— Transformers (`grammarly/coedit-large`) and πŸš€ Gradio
        """
    )

demo.launch()