Spaces:
Runtime error
Runtime error
File size: 2,180 Bytes
cd70acf 8745af2 cd70acf 6252b7b cd70acf 61f88f1 cd70acf 7e371f5 cd70acf 2c9a6a2 cd70acf 6958c0d cd70acf 7e371f5 6958c0d cd70acf 2768781 5ddbc5d cd70acf | 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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 | import gradio as gr
import pandas as pd
from sentiment3d import Sentiment3D
s3d = Sentiment3D()
TITLE = "COMPASS Pathways: 3D 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.",
"A day without sunshine is like, you know, night.",
"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):
sent = s3d(text)
res = dict(text=text, valence=sent['valence'], arousal=sent['arousal'], confidence=sent['confidence'], words=len(text.split()))
#if clear_history:
# state = []
if state == None:
state = []
state.append(res)
df = pd.DataFrame(state)
res_txt = [
f"{r['text']}: \n valence = {r['valence']:0.3f}, arousal = {r['arousal']:0.3f}, confidence = {r['confidence']:0.3f}"
for r in state
]
return "\n".join(res_txt), df, df, df, state
iface = gr.Interface(
fn=sentiment,
inputs=[gr.Textbox(lines=1, placeholder="Text for 3d 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],
),
gr.ScatterPlot(
x="valence",
y="confidence",
tooltip="text",
size="words",
size_legend_position="none",
interactive=False,
x_lim=[-1.05, 1.05],
y_lim=[-1.05, 1.05],
),
gr.ScatterPlot(
x="arousal",
y="confidence",
tooltip="text",
size="words",
size_legend_position="none",
interactive=False,
x_lim=[-1.05, 1.05],
y_lim=[-1.05, 1.05],
),
"state",
],
title=TITLE,
examples=EXAMPLES
)
iface.launch() |