|
import gradio as gr |
|
from gector.gec_model import GecBERTModel |
|
|
|
|
|
def load_model(): |
|
model = GecBERTModel( |
|
vocab_path='data/output_vocabulary', |
|
model_paths=['data/model_files/xlnet_0_gector.th'], |
|
max_len=128, min_len=3 |
|
) |
|
return model |
|
|
|
|
|
def correct_grammar(text): |
|
|
|
model = load_model() |
|
|
|
corrected_text = model.handle_batch([text]) |
|
return corrected_text[0] |
|
|
|
|
|
def create_gradio_interface(): |
|
|
|
interface = gr.Interface( |
|
fn=correct_grammar, |
|
inputs="text", |
|
outputs="text", |
|
title="Grammar Correction App using GECToR", |
|
description="Enter your text, and this app will correct its grammar using GECToR." |
|
) |
|
return interface |
|
|
|
|
|
if __name__ == "__main__": |
|
gradio_interface = create_gradio_interface() |
|
gradio_interface.launch() |
|
|