-
Notifications
You must be signed in to change notification settings - Fork 0
/
dash_deploy.py
94 lines (85 loc) · 3.29 KB
/
dash_deploy.py
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
from dash import Dash, dcc, html, Input, Output
import plotly.graph_objects as go
import pandas as pd
import plotly.express as px
# df = pd.read_csv("/Users/sylvainestebe/Code/nlp_project/cognitive_distortion_project/data/corpus_kmean.csv")
# df2 = pd.read_csv("/Users/sylvainestebe/Code/nlp_project/cognitive_distortion_project/data/corpus_aglom.csv")
# df3 = pd.read_csv("/Users/sylvainestebe/Code/nlp_project/cognitive_distortion_project/data/corpus_hdbscan.csv")
df = pd.read_csv("https://raw.githubusercontent.com/SylvainEstebe/cognitive_distortion_project/main/data/corpus_kmean.csv")
df2 = pd.read_csv("https://raw.githubusercontent.com/SylvainEstebe/cognitive_distortion_project/main/data/corpus_hdbscan_bayesian_optimisation.csv")
# specify the model
model = 'all-mpnet-base-v2'
model_2 = 'all-MiniLM-L12-v2'
model_3 = 'All-Distilroberta-v1'
models = [model,model_2,model_3]
app = Dash(__name__)
server = app.server
app.layout = html.Div(
[
html.H4("Embedding of cognitive distortion"),
html.P("Select a model:"),
dcc.RadioItems(
id="selection",
options=["K-mean 1","K-mean 2","K-mean 3","HDBSCAN 1 (Bayesian optimization)","HDBSCAN 2 (Bayesian optimization)","HDBSCAN 3 (Bayesian optimization)"],
value="K-mean 1",
),
dcc.Loading(dcc.Graph(id="graph"), type="cube"),
]
)
@app.callback(
Output("graph", "figure"), Input("selection", "value")
)
def display_animated_graph(selection):
animations = {
"K-mean 1": px.scatter(
df,
x=df[f"{model} x"],
y=df[f"{model} y"],
color= df[f"{model} k-mean"].astype(str),
hover_data= 'thought',
title= f'Cluster of cognitive distortion using {model} model'
),
"K-mean 2": px.scatter(
df,
x=df[f"{model_2} x"],
y=df[f"{model_2} y"],
color= df[f"{model_2} k-mean"].astype(str),
hover_data= 'thought',
title= f'Cluster of cognitive distortion using {model_2} model'
),
"K-mean 3": px.scatter(
df,
x=df[f"{model_3} x"],
y=df[f"{model_3} y"],
color= df[f"{model_3} k-mean"].astype(str),
hover_data= 'thought',
title= f'Cluster of cognitive distortion using {model_3} model'
),
"HDBSCAN 1 (Bayesian optimization)": px.scatter(
df2,
x=df2[f"{model} x"],
y=df2[f"{model} y"],
color= df2[f"{model} hdbscan_bayesian_optimisation"].astype(str),
hover_data= 'thought',
title= f'Cluster of cognitive distortion using {model} model'
),
"HDBSCAN 2 (Bayesian optimization)": px.scatter(
df2,
x=df2[f"{model_2} x"],
y=df2[f"{model_2} y"],
color= df2[f"{model_2} hdbscan_bayesian_optimisation"].astype(str),
hover_data= 'thought',
title= f'Cluster of cognitive distortion using {model_2} model'
),
"HDBSCAN 3 (Bayesian optimization)": px.scatter(
df2,
x=df2[f"{model_3} x"],
y=df2[f"{model_3} y"],
color= df2[f"{model_3} hdbscan_bayesian_optimisation"].astype(str),
hover_data= 'thought',
title= f'Cluster of cognitive distortion using {model_3} model'
)
}
return animations[selection]
if __name__ == "__main__":
app.run_server(debug=True)