Spaces:
Sleeping
Sleeping
initial
Browse files- .gitignore +7 -0
- app.py +95 -0
- requirements.txt +2 -0
.gitignore
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
.DS_Store
|
2 |
+
__pycache__/
|
3 |
+
.vscode/
|
4 |
+
venv/
|
5 |
+
env/
|
6 |
+
*.pyc
|
7 |
+
.envrc
|
app.py
ADDED
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
3 |
+
from torch.nn.functional import softmax
|
4 |
+
|
5 |
+
|
6 |
+
model_name = "Ngit/MiniLMv2-L6-H384-goemotions-v2"
|
7 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
8 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
9 |
+
|
10 |
+
|
11 |
+
def evaluate(text):
|
12 |
+
text = text.strip()
|
13 |
+
proba = [0]*28
|
14 |
+
if text:
|
15 |
+
input_ids = tokenizer(text, return_tensors="pt").input_ids
|
16 |
+
output = model(input_ids)
|
17 |
+
proba = softmax(output.logits, dim=1)[0]
|
18 |
+
proba = [int(v*1000)/10 for v in proba]
|
19 |
+
return proba
|
20 |
+
|
21 |
+
|
22 |
+
with gr.Blocks() as demo:
|
23 |
+
text = gr.Textbox(label="Text to evaluate", lines=12)
|
24 |
+
with gr.Row():
|
25 |
+
with gr.Group():
|
26 |
+
t_adm = gr.Slider(label="admiration", value=0, maximum=100)
|
27 |
+
t_amu = gr.Slider(label="amusement", value=0, maximum=100)
|
28 |
+
t_ang = gr.Slider(label="anger", value=0, maximum=100)
|
29 |
+
t_ann = gr.Slider(label="annoyance", value=0, maximum=100)
|
30 |
+
t_app = gr.Slider(label="approval", value=0, maximum=100)
|
31 |
+
t_car = gr.Slider(label="caring", value=0, maximum=100)
|
32 |
+
t_con = gr.Slider(label="confusion", value=0, maximum=100)
|
33 |
+
with gr.Group():
|
34 |
+
t_cur = gr.Slider(label="curiosity", value=0, maximum=100)
|
35 |
+
t_des = gr.Slider(label="desire", value=0, maximum=100)
|
36 |
+
t_dis = gr.Slider(label="disappointment", value=0, maximum=100)
|
37 |
+
t_dip = gr.Slider(label="disapproval", value=0, maximum=100)
|
38 |
+
t_dit = gr.Slider(label="disgust", value=0, maximum=100)
|
39 |
+
t_emb = gr.Slider(label="embarrassment", value=0, maximum=100)
|
40 |
+
t_exc = gr.Slider(label="excitement", value=0, maximum=100)
|
41 |
+
with gr.Group():
|
42 |
+
t_fea = gr.Slider(label="fear", value=0, maximum=100)
|
43 |
+
t_gra = gr.Slider(label="gratitude", value=0, maximum=100)
|
44 |
+
t_gri = gr.Slider(label="grief", value=0, maximum=100)
|
45 |
+
t_joy = gr.Slider(label="joy", value=0, maximum=100)
|
46 |
+
t_lov = gr.Slider(label="love", value=0, maximum=100)
|
47 |
+
t_ner = gr.Slider(label="nervousness", value=0, maximum=100)
|
48 |
+
t_opt = gr.Slider(label="optimism", value=0, maximum=100)
|
49 |
+
with gr.Group():
|
50 |
+
t_pri = gr.Slider(label="pride", value=0, maximum=100)
|
51 |
+
t_rea = gr.Slider(label="realization", value=0, maximum=100)
|
52 |
+
t_rel = gr.Slider(label="relief", value=0, maximum=100)
|
53 |
+
t_rem = gr.Slider(label="remorse", value=0, maximum=100)
|
54 |
+
t_sad = gr.Slider(label="sadness", value=0, maximum=100)
|
55 |
+
t_sur = gr.Slider(label="surprise", value=0, maximum=100)
|
56 |
+
t_neu = gr.Slider(label="neutral", value=0, maximum=100)
|
57 |
+
|
58 |
+
btn = gr.Button(value="Evaluate Emotion")
|
59 |
+
btn.click(
|
60 |
+
evaluate,
|
61 |
+
inputs=[text],
|
62 |
+
outputs=[
|
63 |
+
t_adm,
|
64 |
+
t_amu,
|
65 |
+
t_ang,
|
66 |
+
t_ann,
|
67 |
+
t_app,
|
68 |
+
t_car,
|
69 |
+
t_con,
|
70 |
+
t_cur,
|
71 |
+
t_des,
|
72 |
+
t_dis,
|
73 |
+
t_dip,
|
74 |
+
t_dit,
|
75 |
+
t_emb,
|
76 |
+
t_exc,
|
77 |
+
t_fea,
|
78 |
+
t_gra,
|
79 |
+
t_gri,
|
80 |
+
t_joy,
|
81 |
+
t_lov,
|
82 |
+
t_ner,
|
83 |
+
t_opt,
|
84 |
+
t_pri,
|
85 |
+
t_rea,
|
86 |
+
t_rel,
|
87 |
+
t_rem,
|
88 |
+
t_sad,
|
89 |
+
t_sur,
|
90 |
+
t_neu,
|
91 |
+
],
|
92 |
+
)
|
93 |
+
|
94 |
+
if __name__ == "__main__":
|
95 |
+
demo.queue().launch()
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
transformers
|
2 |
+
torch
|