leslyarun commited on
Commit
2b0ff86
1 Parent(s): 67bde9a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -6
app.py CHANGED
@@ -1,12 +1,16 @@
1
  import gradio as gr
2
- from happytransformer import HappyTextToText, TTSettings
3
 
4
  def check_grammar(sentence):
5
- happy_tt = HappyTextToText("T5", "leslyarun/grammatical-error-correction")
6
- args = TTSettings(num_beams=5, min_length=1)
7
- # Add the prefix "grammar: " before each input
8
- result = happy_tt.generate_text("grammar: " + sentence, args=args)
9
- return result.text
 
 
 
 
10
 
11
  demo = gr.Interface(check_grammar, inputs=['text'],
12
  outputs="text",
 
1
  import gradio as gr
2
+ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
3
 
4
  def check_grammar(sentence):
5
+ tokenizer = AutoTokenizer.from_pretrained("leslyarun/grammatical-error-correction")
6
+ model = AutoModelForSeq2SeqLM.from_pretrained("leslyarun/grammatical-error-correction")
7
+
8
+ inputs = tokenizer("grammar: " + sentence, truncation=True, return_tensors='pt')
9
+
10
+ output = model.generate(inputs['input_ids'], num_beams=5, max_length=512, early_stopping=True)
11
+ correction = tokenizer.batch_decode(output, skip_special_tokens=True)
12
+ return "".join(correction)
13
+
14
 
15
  demo = gr.Interface(check_grammar, inputs=['text'],
16
  outputs="text",