aaurelions commited on
Commit
7a3385d
·
verified ·
1 Parent(s): 33bde80

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -0
app.py ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
3
+
4
+ # Load your model and tokenizer
5
+ model_name = "akhmat-s/t5-base-grammar-corrector" # or "akhmat-s/t5-large-quant-grammar-corrector"
6
+ model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
7
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
8
+
9
+ def correct_grammar(text):
10
+ inputs = tokenizer.encode("fix: " + text, return_tensors="pt", max_length=512, truncation=True)
11
+ outputs = model.generate(inputs, max_length=512, num_beams=4, early_stopping=True)
12
+ corrected_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
13
+ return corrected_text
14
+
15
+ iface = gr.Interface(
16
+ fn=correct_grammar,
17
+ inputs=gr.inputs.Textbox(lines=5, label="Input Text"),
18
+ outputs=gr.outputs.Textbox(label="Corrected Text"),
19
+ title="Grammar Correction Chat",
20
+ description="Enter text with grammatical errors, and the model will provide corrections."
21
+ )
22
+
23
+ if __name__ == "__main__":
24
+ iface.launch()