sashtech's picture
Update app.py
46627d5 verified
raw
history blame
1 kB
import subprocess
import spacy
import gradio as gr
from gramformer import Gramformer
# Check if the 'en_core_web_sm' model is installed, if not, install it
try:
spacy.load("en_core_web_sm")
except OSError:
subprocess.run(["python", "-m", "spacy", "download", "en_core_web_sm"])
# Initialize the Gramformer model (using default settings for now)
gf = Gramformer(models=1, use_gpu=False)
def correct_grammar(text):
# Correct the input text using Gramformer
corrected_sentences = gf.correct(text)
return " ".join(corrected_sentences)
# Gradio Interface
def main():
interface = gr.Interface(
fn=correct_grammar,
inputs=gr.Textbox(lines=2, placeholder="Enter text here..."),
outputs="text",
title="Grammar Correction App",
description="This app corrects grammar using the Gramformer model. Enter a sentence to correct its grammar.",
)
# Launch the Gradio interface
interface.launch()
if __name__ == "__main__":
main()