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