Kavin0003 commited on
Commit
6d9f617
Β·
0 Parent(s):

πŸš€ Fresh start

Browse files
Files changed (2) hide show
  1. app.py +36 -0
  2. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
2
+ import gradio as gr
3
+ import torch
4
+
5
+ # Load from Hugging Face model hub
6
+ model_path = "mbalajibalu/grammar-model"
7
+
8
+ tokenizer = AutoTokenizer.from_pretrained(model_path)
9
+ model = AutoModelForSeq2SeqLM.from_pretrained(model_path)
10
+
11
+ def correct_grammar(text):
12
+ if not text.strip():
13
+ return "Please enter some text to correct."
14
+
15
+ inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=512)
16
+ with torch.no_grad():
17
+ outputs = model.generate(
18
+ **inputs,
19
+ max_length=512,
20
+ num_beams=5,
21
+ early_stopping=True,
22
+ do_sample=False
23
+ )
24
+ return tokenizer.decode(outputs[0], skip_special_tokens=True)
25
+
26
+ iface = gr.Interface(
27
+ fn=correct_grammar,
28
+ inputs=gr.Textbox(label="Enter text to correct", placeholder="Type here...", lines=3),
29
+ outputs=gr.Textbox(label="Corrected text", lines=3),
30
+ title="Grammar Correction",
31
+ description="Fixes grammar using a fine-tuned T5 model.",
32
+ examples=["She go to market.", "He don't like it.", "We was playing."]
33
+ )
34
+
35
+ if __name__ == "__main__":
36
+ iface.launch()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ transformers==4.36.2
2
+ torch==2.1.2
3
+ gradio==4.8.0