gradsyntax commited on
Commit
8bfd817
·
verified ·
1 Parent(s): aa03692

created app

Browse files
Files changed (1) hide show
  1. app.py +25 -0
app.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
3
+ import torch
4
+
5
+ # Load model and tokenizer
6
+ model_name = "prithivida/grammar_error_correcter_v1"
7
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
8
+ model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
9
+
10
+ def correct_grammar(input_text):
11
+ inputs = tokenizer.encode("gec: " + input_text, return_tensors="pt", max_length=128, truncation=True)
12
+ outputs = model.generate(inputs, max_length=128, num_beams=5, early_stopping=True)
13
+ corrected = tokenizer.decode(outputs[0], skip_special_tokens=True)
14
+ return corrected
15
+
16
+ # Gradio Interface
17
+ iface = gr.Interface(
18
+ fn=correct_grammar,
19
+ inputs=gr.Textbox(lines=4, placeholder="Enter your sentence..."),
20
+ outputs="text",
21
+ title="Grammar Correction Tool",
22
+ description="Enter text with errors. The model will return a grammatically corrected version."
23
+ )
24
+
25
+ iface.launch()