File size: 893 Bytes
d8da5b4
 
 
 
 
 
 
 
 
 
2bcc8be
d8da5b4
 
 
 
 
 
 
 
83cf4cd
d8da5b4
 
2bcc8be
d8da5b4
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
from transformers import AutoTokenizer
from transformers import AutoModelForSequenceClassification
import torch
import numpy as np

labels = ['Not Acceptale', "Acceptable"]
model_name = "abdulmatinomotoso/English_Grammar_Checker"
model = AutoModelForSequenceClassification.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)

def check_grammar(sentence):
  input_tensor = tokenizer.encode(sentence, return_tensors="pt")
  logits = model(input_tensor).logits

  softmax = torch.nn.Softmax(dim=1)
  probs = softmax(logits)[0]
  probs = probs.cpu().detach().numpy()
  max_index = np.argmax(probs)
  result = labels[max_index]
  
  return result
  
demo = gr.Interface(check_grammar, inputs=['text'],
                    outputs="text",
                    title = "English Grammar Checker")
                    
if __name__ == "__main__":
    demo.launch(debug=True)