ayushsinha commited on
Commit
2dda026
·
verified ·
1 Parent(s): 9f13e70

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +38 -0
  2. requirements.txt +8 -0
app.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import T5ForConditionalGeneration, T5Tokenizer
3
+
4
+ # Load model and tokenizer
5
+ model_name = "AventIQ-AI/T5-small-grammar-correction"
6
+ model = T5ForConditionalGeneration.from_pretrained(model_name)
7
+ tokenizer = T5Tokenizer.from_pretrained(model_name)
8
+
9
+ def correct_grammar(text):
10
+ input_text = "correct: " + text
11
+ inputs = tokenizer(input_text, return_tensors="pt", max_length=512, truncation=True)
12
+ outputs = model.generate(**inputs, max_length=512)
13
+ corrected_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
14
+ return corrected_text
15
+
16
+ # Example inputs
17
+ examples = [
18
+ ["She go to the market yesterday."],
19
+ ["He don't like playing football."],
20
+ ["I has a new phone."]
21
+ ]
22
+
23
+ # Gradio Interface
24
+ with gr.Blocks() as demo:
25
+ gr.Markdown("# 📝 Grammar Correction System")
26
+ gr.Markdown("Enter a sentence with grammatical errors, and the model will correct it!")
27
+
28
+ with gr.Row():
29
+ input_text = gr.Textbox(label="Enter Text", placeholder="Type a grammatically incorrect sentence here...")
30
+
31
+ output_text = gr.Textbox(label="Corrected Text")
32
+ correct_button = gr.Button("Correct Grammar")
33
+
34
+ correct_button.click(correct_grammar, inputs=[input_text], outputs=[output_text])
35
+
36
+ gr.Examples(examples, inputs=[input_text])
37
+
38
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ torch
2
+ transformers
3
+ gradio
4
+ sentencepiece
5
+ torchvision
6
+ huggingface_hub
7
+ pillow
8
+ numpy