tanishkaguha commited on
Commit
681a5b0
·
verified ·
1 Parent(s): b203b8b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -17
app.py CHANGED
@@ -1,23 +1,25 @@
1
  import gradio as gr
2
- import language_tool_python
 
3
 
4
- # Load English grammar checking tool
5
- tool = language_tool_python.LanguageTool('en-US')
 
 
6
 
7
- # Function to check grammar
8
- def grammar_check(text):
9
- matches = tool.check(text)
10
- corrected = language_tool_python.utils.correct(text, matches)
11
- return corrected, len(matches)
 
 
12
 
13
- # Gradio UI
14
  gr.Interface(
15
- fn=grammar_check,
16
- inputs=gr.Textbox(lines=7, placeholder="Type or paste your text here...", label="Input Text"),
17
- outputs=[
18
- gr.Textbox(label="Corrected Text"),
19
- gr.Number(label="Number of Issues")
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()