Spaces:
Runtime error
Runtime error
Commit ·
7601458
1
Parent(s): 9555be8
Add app.py, update readme
Browse files- README.md +17 -1
- app.py +30 -0
- requirements.txt +2 -0
README.md
CHANGED
|
@@ -9,5 +9,21 @@ app_file: app.py
|
|
| 9 |
pinned: false
|
| 10 |
license: cc-by-4.0
|
| 11 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
-
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 9 |
pinned: false
|
| 10 |
license: cc-by-4.0
|
| 11 |
---
|
| 12 |
+
# COMPASS Pathways Two-dimensional Sentiment Model
|
| 13 |
+
|
| 14 |
+
<div align="center">
|
| 15 |
+
|
| 16 |
+
[](https://github.com/psf/black)
|
| 17 |
+
[](https://github.com/compasspathways/Sentiment2D/blob/main/.pre-commit-config.yaml)
|
| 18 |
+
[](https://creativecommons.org/licenses/by/4.0/)
|
| 19 |
+
|
| 20 |
+
A package for computing the two-dimensional sentiment scores and a Jupyter notebook for replicating the analysis described in the paper "[Psilocybin Therapy for Treatment Resistant Depression: Prediction of Clinical Outcome by Natural Language Processing](https://psyarxiv.com/kh3cx/)".
|
| 21 |
+
|
| 22 |
+
</div>
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
## Citation
|
| 27 |
+
|
| 28 |
+
Please cite our paper titled "Psilocybin Therapy for Treatment Resistant Depression: Prediction of Clinical Outcome by Natural Language Processing". ([preprint](https://psyarxiv.com/kh3cx/))
|
| 29 |
|
|
|
app.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import pandas as pd
|
| 3 |
+
from sentiment2d import Sentiment2D
|
| 4 |
+
|
| 5 |
+
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 |
+
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
git+https://github.com/compasspathways/Sentiment2D
|
| 2 |
+
|