Spaces:
Build error
Build error
abdulmatinomotoso
commited on
Commit
•
d8da5b4
1
Parent(s):
503b117
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import AutoTokenizer
|
2 |
+
from transformers import AutoModelForSequenceClassification
|
3 |
+
import torch
|
4 |
+
import numpy as np
|
5 |
+
|
6 |
+
labels = ['Not Acceptale', "Acceptable"]
|
7 |
+
model_name = "abdulmatinomotoso/English_Grammar_Checker"
|
8 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
9 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
10 |
+
|
11 |
+
def get_emotion(sentence):
|
12 |
+
input_tensor = tokenizer.encode(sentence, return_tensors="pt")
|
13 |
+
logits = model(input_tensor).logits
|
14 |
+
|
15 |
+
softmax = torch.nn.Softmax(dim=1)
|
16 |
+
probs = softmax(logits)[0]
|
17 |
+
probs = probs.cpu().detach().numpy()
|
18 |
+
max_index = np.argmax(probs)
|
19 |
+
result = labels[max_index]
|
20 |
+
return result
|
21 |
+
|
22 |
+
demo = gr.Interface(get_emotion, inputs=['text'],
|
23 |
+
outputs="text",
|
24 |
+
title = "English Grammar Checker")
|
25 |
+
|
26 |
+
if __name__ == "__main__":
|
27 |
+
demo.launch(debug=True)
|