Spaces:
Build error
Build error
abdulmatinomotoso
commited on
Commit
•
a6b44cd
1
Parent(s):
588b7d7
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
2 |
+
import numpy as np
|
3 |
+
import torch
|
4 |
+
import gradio as gr
|
5 |
+
|
6 |
+
#device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
7 |
+
labels = ['Not equivalent', "equivalent"]
|
8 |
+
model_name = "abdulmatinomotoso/paraphrase_detector"
|
9 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
10 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
11 |
+
|
12 |
+
def get_emotion(sentence1, sentence2):
|
13 |
+
input_tensor = tokenizer.encode(sentence1, sentence2, return_tensors="pt")
|
14 |
+
logits = model(input_tensor).logits
|
15 |
+
|
16 |
+
softmax = torch.nn.Softmax(dim=1)
|
17 |
+
probs = softmax(logits)[0]
|
18 |
+
probs = probs.cpu().detach().numpy()
|
19 |
+
max_index = np.argmax(probs)
|
20 |
+
result = labels[max_index]
|
21 |
+
return result
|
22 |
+
|
23 |
+
demo = gr.Interface(get_emotion, inputs=['text', 'text'],
|
24 |
+
outputs="text",
|
25 |
+
title = "PARAPHRASES_DETECTOR -- detecting if a pair of sentence are equivalent or not")
|
26 |
+
|
27 |
+
if __name__ == "__main__":
|
28 |
+
demo.launch(debug=True)
|