Jitendra12421 commited on
Commit
ab04512
·
verified ·
1 Parent(s): 1f1b0c0

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +36 -0
  2. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import T5ForConditionalGeneration, T5Tokenizer
3
+
4
+ # Load model and tokenizer
5
+ model_name = "vennify/t5-base-grammar-correction"
6
+ print("Loading model...")
7
+ tokenizer = T5Tokenizer.from_pretrained(model_name)
8
+ model = T5ForConditionalGeneration.from_pretrained(model_name)
9
+ print("Model loaded.")
10
+
11
+ def correct_text(text):
12
+ if not text.strip():
13
+ return ""
14
+ # "vennify/t5-base-grammar-correction" requires "grammar: " prefix
15
+ inputs = tokenizer("grammar: " + text, return_tensors="pt")
16
+
17
+ # Generate prediction
18
+ outputs = model.generate(
19
+ **inputs,
20
+ num_beams=5,
21
+ max_length=128
22
+ )
23
+
24
+ corrected = tokenizer.decode(outputs[0], skip_special_tokens=True)
25
+ return corrected
26
+
27
+ # Simple Gradio interface
28
+ iface = gr.Interface(
29
+ fn=correct_text,
30
+ inputs=gr.Textbox(lines=5, placeholder="Enter text with grammar errors..."),
31
+ outputs=gr.Textbox(label="Corrected text"),
32
+ title="Grammar Correction API",
33
+ description="A simple API for the local Windows grammar autocorrect."
34
+ )
35
+
36
+ iface.launch()
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ transformers
2
+ torch
3
+ sentencepiece
4
+ gradio