Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,23 +1,25 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import
|
|
|
|
| 3 |
|
| 4 |
-
# Load
|
| 5 |
-
|
|
|
|
|
|
|
| 6 |
|
| 7 |
-
#
|
| 8 |
-
def
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
|
|
|
|
|
|
| 12 |
|
| 13 |
-
# Gradio
|
| 14 |
gr.Interface(
|
| 15 |
-
fn=
|
| 16 |
-
inputs=gr.Textbox(lines=7, placeholder="
|
| 17 |
-
outputs=
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
],
|
| 21 |
-
title="Grammar Checker",
|
| 22 |
-
description="A simple tool to check and correct grammar using LanguageTool."
|
| 23 |
).launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
|
| 3 |
+
import torch
|
| 4 |
|
| 5 |
+
# Load grammar correction model
|
| 6 |
+
model_name = "pszemraj/grammar-synthesis-small"
|
| 7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 8 |
+
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
| 9 |
|
| 10 |
+
# Grammar correction function
|
| 11 |
+
def correct_grammar(text):
|
| 12 |
+
input_text = "gec: " + text
|
| 13 |
+
inputs = tokenizer.encode(input_text, return_tensors="pt", truncation=True)
|
| 14 |
+
outputs = model.generate(inputs, max_length=512, num_beams=5, early_stopping=True)
|
| 15 |
+
corrected_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 16 |
+
return corrected_text
|
| 17 |
|
| 18 |
+
# Gradio Interface
|
| 19 |
gr.Interface(
|
| 20 |
+
fn=correct_grammar,
|
| 21 |
+
inputs=gr.Textbox(lines=7, placeholder="Enter your text here...", label="Input Text"),
|
| 22 |
+
outputs=gr.Textbox(label="Corrected Text"),
|
| 23 |
+
title="Grammar Checker (No Java)",
|
| 24 |
+
description="Uses a Hugging Face transformer model to fix grammar mistakes in English."
|
|
|
|
|
|
|
|
|
|
| 25 |
).launch()
|