rfdougherty commited on
Commit
57a095c
·
1 Parent(s): 7601458

Improve layout

Browse files
Files changed (1) hide show
  1. app.py +34 -10
app.py CHANGED
@@ -6,25 +6,49 @@ s2d = Sentiment2D()
6
 
7
  history = []
8
 
9
- FONT_COLOR = '#666666'
10
- FILL_COLOR = 'rgb(.7,.7,.7)'
 
 
 
 
 
 
 
 
 
11
 
12
  def sentiment(text, clear_history):
13
  global history
14
  valence, arousal = s2d(text)
15
- #res = f"{text}: valence={valence:0.3f}, arousal={arousal:0.3f}"
16
  res = dict(text=text, valence=valence, arousal=arousal, words=len(text.split()))
17
  if clear_history:
18
  history = []
19
  history.append(res)
20
  df = pd.DataFrame(history)
21
- res_txt = [f"{r['text']}: valence={r['valence']:0.3f}, arousal={r['arousal']:0.3f}" for r in history]
 
 
 
22
  return "\n".join(res_txt), df
23
 
24
- iface = gr.Interface(fn=sentiment,
25
- inputs=[gr.Textbox(lines=1, placeholder="Text for 2d sentiment..."), "checkbox"],
26
- outputs=["text",
27
- gr.ScatterPlot(x="valence", y="arousal", tooltip="text", size="words",
28
- x_lim=[-1.05, 1.05], y_lim=[-1.05, 1.05])])
29
- iface.launch()
30
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
  history = []
8
 
9
+ FONT_COLOR = "#666666"
10
+ FILL_COLOR = "rgb(.7,.7,.7)"
11
+ TITLE = "COMPASS Pathways 2D Sentiment Model"
12
+ EXAMPLES = [
13
+ "This is so awesome!",
14
+ "You're driving me up the wall!",
15
+ "I'm so lonely I could cry.",
16
+ "I'm not feeling very sad at all.",
17
+ "I'm just chillin' this morning.",
18
+ ]
19
+
20
 
21
  def sentiment(text, clear_history):
22
  global history
23
  valence, arousal = s2d(text)
24
+ # res = f"{text}: valence={valence:0.3f}, arousal={arousal:0.3f}"
25
  res = dict(text=text, valence=valence, arousal=arousal, words=len(text.split()))
26
  if clear_history:
27
  history = []
28
  history.append(res)
29
  df = pd.DataFrame(history)
30
+ res_txt = [
31
+ f"{r['text']}: valence={r['valence']:0.3f}, arousal={r['arousal']:0.3f}"
32
+ for r in history
33
+ ]
34
  return "\n".join(res_txt), df
35
 
 
 
 
 
 
 
36
 
37
+ iface = gr.Interface(
38
+ fn=sentiment,
39
+ inputs=[gr.Textbox(lines=1, placeholder="Text for 2d sentiment..."), "checkbox"],
40
+ outputs=[
41
+ gr.TextBox(lines=5, max_lines=5, label="Results"),
42
+ gr.ScatterPlot(
43
+ x="valence",
44
+ y="arousal",
45
+ tooltip="text",
46
+ size="words",
47
+ x_lim=[-1.05, 1.05],
48
+ y_lim=[-1.05, 1.05],
49
+ ),
50
+ ],
51
+ titel=TITLE,
52
+ examples=EXAMPLES,
53
+ )
54
+ iface.launch()