Spaces:
Sleeping
Sleeping
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() | |