pclarke commited on
Commit
cd70acf
·
1 Parent(s): 22f8af2

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -0
app.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import pandas as pd
3
+ from sentiment3d import Sentiment3D
4
+
5
+ s3d = Sentiment3D()
6
+
7
+ TITLE = "COMPASS Pathways 3D Sentiment Model"
8
+ EXAMPLES = [
9
+ "This is so awesome!",
10
+ "You're driving me up the wall!",
11
+ "I'm so lonely I could cry.",
12
+ "I'm not feeling very sad at all.",
13
+ "You're slapping your father in the face, aren't you?",
14
+ "Yes, that's how I feel [laughing].",
15
+ "Yes, that's how I feel [sobbing].",
16
+ "Now I hear what you're sayin' 😀",
17
+ "Now I hear what you're sayin' 🙁",
18
+ ]
19
+
20
+
21
+ def sentiment(text, state):
22
+ valence, arousal, confidence = s3d(text)
23
+ res = dict(text=text, valence=valence, arousal=arousal, confidence=confidence, words=len(text.split()))
24
+ #if clear_history:
25
+ # state = []
26
+ if state == None:
27
+ state = []
28
+ state.append(res)
29
+ df = pd.DataFrame(state)
30
+ res_txt = [
31
+ f"{r['text']}: valence={r['valence']:0.3f}, arousal={r['arousal']:0.3f}, confidence=arousal={r['confidence']:0.3f}"
32
+ for r in state
33
+ ]
34
+ return "\n".join(res_txt), df, state
35
+
36
+
37
+ iface = gr.Interface(
38
+ fn=sentiment,
39
+ inputs=[gr.Textbox(lines=1, placeholder="Text for 3d sentiment..."), "state"],
40
+ outputs=[
41
+ gr.Textbox(lines=5, max_lines=5, label="Results"),
42
+ gr.ScatterPlot(
43
+ x="valence",
44
+ y="arousal",
45
+ z="confidence",
46
+ tooltip="text",
47
+ size="words",
48
+ size_legend_position="none",
49
+ interactive=False,
50
+ x_lim=[-1.05, 1.05],
51
+ y_lim=[-1.05, 1.05],
52
+ z_lim=[-1.05, 1.05],
53
+ ),
54
+ "state",
55
+ ],
56
+ titel=TITLE,
57
+ examples=EXAMPLES,
58
+ )
59
+ iface.launch()