Spaces:
Runtime error
Runtime error
Commit ·
5c199a4
1
Parent(s): f1fc916
Fix state
Browse files
app.py
CHANGED
|
@@ -4,10 +4,6 @@ from sentiment2d import Sentiment2D
|
|
| 4 |
|
| 5 |
s2d = Sentiment2D()
|
| 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!",
|
|
@@ -18,25 +14,25 @@ EXAMPLES = [
|
|
| 18 |
]
|
| 19 |
|
| 20 |
|
| 21 |
-
def sentiment(text,
|
| 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 |
-
|
| 28 |
-
|
| 29 |
-
|
|
|
|
|
|
|
| 30 |
res_txt = [
|
| 31 |
f"{r['text']}: valence={r['valence']:0.3f}, arousal={r['arousal']:0.3f}"
|
| 32 |
-
for r in
|
| 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..."), "
|
| 40 |
outputs=[
|
| 41 |
gr.Textbox(lines=5, max_lines=5, label="Results"),
|
| 42 |
gr.ScatterPlot(
|
|
@@ -47,8 +43,9 @@ iface = gr.Interface(
|
|
| 47 |
x_lim=[-1.05, 1.05],
|
| 48 |
y_lim=[-1.05, 1.05],
|
| 49 |
),
|
|
|
|
| 50 |
],
|
| 51 |
titel=TITLE,
|
| 52 |
-
|
| 53 |
)
|
| 54 |
iface.launch()
|
|
|
|
| 4 |
|
| 5 |
s2d = Sentiment2D()
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
TITLE = "COMPASS Pathways 2D Sentiment Model"
|
| 8 |
EXAMPLES = [
|
| 9 |
"This is so awesome!",
|
|
|
|
| 14 |
]
|
| 15 |
|
| 16 |
|
| 17 |
+
def sentiment(text, state):
|
|
|
|
| 18 |
valence, arousal = s2d(text)
|
|
|
|
| 19 |
res = dict(text=text, valence=valence, arousal=arousal, words=len(text.split()))
|
| 20 |
+
#if clear_history:
|
| 21 |
+
# state = []
|
| 22 |
+
if state == None:
|
| 23 |
+
state = []
|
| 24 |
+
state.append(res)
|
| 25 |
+
df = pd.DataFrame(state)
|
| 26 |
res_txt = [
|
| 27 |
f"{r['text']}: valence={r['valence']:0.3f}, arousal={r['arousal']:0.3f}"
|
| 28 |
+
for r in state
|
| 29 |
]
|
| 30 |
+
return "\n".join(res_txt), df, state
|
| 31 |
|
| 32 |
|
| 33 |
iface = gr.Interface(
|
| 34 |
fn=sentiment,
|
| 35 |
+
inputs=[gr.Textbox(lines=1, placeholder="Text for 2d sentiment..."), "state"],
|
| 36 |
outputs=[
|
| 37 |
gr.Textbox(lines=5, max_lines=5, label="Results"),
|
| 38 |
gr.ScatterPlot(
|
|
|
|
| 43 |
x_lim=[-1.05, 1.05],
|
| 44 |
y_lim=[-1.05, 1.05],
|
| 45 |
),
|
| 46 |
+
"state",
|
| 47 |
],
|
| 48 |
titel=TITLE,
|
| 49 |
+
examples=EXAMPLES,
|
| 50 |
)
|
| 51 |
iface.launch()
|