ywuan commited on
Commit
0a8431b
1 Parent(s): 5b5f5f8
Files changed (1) hide show
  1. app.py +35 -0
app.py ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
3
+ import torch.nn as nn
4
+
5
+ name = ["negative","neutral","positive"]
6
+
7
+
8
+ def main_note(sentence,aspect):
9
+ tokenizer = AutoTokenizer.from_pretrained("yangheng/deberta-v3-base-absa-v1.1")
10
+ model = AutoModelForSequenceClassification.from_pretrained("yangheng/deberta-v3-base-absa-v1.1")
11
+ # model = AutoModelForSequenceClassification.from_pretrained("yangheng/deberta-v3-large-absa-v1.1")
12
+ input_str = "[CLS]" + sentence + "[SEP]" + aspect + "[SEP]"
13
+ # input_str = "[CLS] when tables opened up, the manager sat another party before us. [SEP] manager [SEP]"
14
+ inputs = tokenizer(input_str, return_tensors="pt")
15
+ outputs = model(**inputs)
16
+ softmax = nn.Softmax(dim=1)
17
+ outputs = softmax(outputs.logits)
18
+ result = [round(i,4) for i in outputs.tolist()[0]]
19
+ # print(result)
20
+ return dict(zip(name,result))
21
+
22
+ # main_note("","")
23
+
24
+ iface = gr.Interface(
25
+ fn = main_note,
26
+ inputs=["text","text"],
27
+ outputs = gr.outputs.Label(),
28
+ examples=[["1.) Instead of being at the back of the oven, the cord is attached at the front right side.","cord"],
29
+ ["The pan I received was not in the same league as my old pan, new is cheap feeling and does not have a plate on the bottom.","pan"],
30
+ ["The pan I received was not in the same league as my old pan, new is cheap feeling and does not have a plate on the bottom.","bottom"],
31
+ ["They seem much more durable and less prone to staining, retaining their white properties for a much longer period of time.","durability"],
32
+ ["It took some time to clean and maintain, but totally worth it!","clean"],
33
+ ["this means that not only will the smallest burner heat up the pan, but it will also vertically heat up 1\" of the handle.","handle"]])
34
+
35
+ iface.launch(share=True)