File size: 1,060 Bytes
84669bc
23b0057
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5065a5b
23b0057
5065a5b
23b0057
 
 
 
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
import gradio as gr
from gramformer import Gramformer  # Assuming gramformer.py is in the same directory as this app

# Initialize Gramformer
gf = Gramformer(models=1, use_gpu=False)  # Set use_gpu=True if using a GPU-enabled space

def correct_sentence(input_sentence):
    # Use the correct method from Gramformer
    corrected_sentences = gf.correct(input_sentence, max_candidates=1)
    return "\n".join(corrected_sentences)

# Create Gradio interface
def gradio_interface():
    input_text = gr.inputs.Textbox(lines=2, placeholder="Enter a sentence here...")
    output_text = gr.outputs.Textbox()

    # Gradio Interface: Takes a sentence, corrects it, and outputs the correction
    iface = gr.Interface(
        fn=correct_sentence,
        inputs=input_text,
        outputs=output_text,
        title="Grammar Correction",
        description="Corrects grammatical errors in the input sentence using the Gramformer model."
    )
    
    return iface

# Run the Gradio app
if __name__ == "__main__":
    iface = gradio_interface()
    iface.launch()