Spaces:
Sleeping
Sleeping
added visualizations
Browse files- app.py +59 -11
- requirements.txt +6 -0
app.py
CHANGED
@@ -82,7 +82,58 @@ def similarity_top(descr_emb, disorder_embs):
|
|
82 |
|
83 |
return results[:5]
|
84 |
|
|
|
85 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
86 |
# with text_spinner_placeholder:
|
87 |
# with st.spinner("Please wait while your Tweet is being generated..."):
|
88 |
# mood_prompt = f"{mood} " if mood else ""
|
@@ -95,24 +146,21 @@ def similarity_top(descr_emb, disorder_embs):
|
|
95 |
# f"and in the style of the following Tweets:\n\n{tweets_prompt}\n\n"
|
96 |
|
97 |
# Configure Streamlit page and state
|
98 |
-
st.title("Detect
|
99 |
st.markdown(
|
100 |
-
"This mini-app predicts
|
|
|
101 |
)
|
102 |
|
103 |
-
input = st.text_input(label="Your description
|
104 |
if input:
|
105 |
input_embed = model.encode(input)
|
106 |
sim_score = similarity_top(input_embed, icd_embeddings)
|
107 |
st.write(sim_score)
|
|
|
|
|
|
|
|
|
108 |
|
109 |
-
# mood = st.text_input(
|
110 |
-
# label="Mood (e.g. inspirational, funny, serious) (optional)",
|
111 |
-
# placeholder="inspirational",
|
112 |
-
# )
|
113 |
-
# style = st.text_input(
|
114 |
-
# label="Twitter account handle to style-copy recent Tweets (optional, limited by Twitter's API)",
|
115 |
-
# placeholder="elonmusk",
|
116 |
-
# )
|
117 |
|
118 |
text_spinner_placeholder = st.empty()
|
|
|
82 |
|
83 |
return results[:5]
|
84 |
|
85 |
+
def vis_results_2d(input_embed):
|
86 |
|
87 |
+
# performing dimensionality reduction using PCA
|
88 |
+
pca = PCA(n_components=2)
|
89 |
+
disease_embeddings_2d = pca.fit_transform(icd_embeddings)
|
90 |
+
|
91 |
+
# creating a DataFrame for disease embeddings plot
|
92 |
+
disease_data_df = pd.DataFrame(disease_embeddings_2d, columns=['PC1', 'PC2'])
|
93 |
+
disease_data_df['Type'] = 'Disease'
|
94 |
+
disease_data_df['Name'] = disease_names
|
95 |
+
|
96 |
+
input_embed_2d = input_embed.reshape(1, -1)
|
97 |
+
input_embed_2d = pca.transform(input_embed_2d)
|
98 |
+
|
99 |
+
# creating a DataFrame for character embedding plot
|
100 |
+
pca_2d = pd.DataFrame(input_embed_2d, columns=['PC1', 'PC2'])
|
101 |
+
pca_2d['Type'] = 'Character'
|
102 |
+
pca_2d['Your character'] = 'Your character'
|
103 |
+
|
104 |
+
# concatenating the two DataFrames
|
105 |
+
combined_2d = pd.concat([disease_data_df, pca_2d], ignore_index=True)
|
106 |
+
|
107 |
+
# creating an interactive 3D scatter plot
|
108 |
+
fig = px.scatter(combined_2d, x='PC1', y='PC2', text='Name', color='Type', symbol='Type', width=800, height=800)
|
109 |
+
fig.show()
|
110 |
+
|
111 |
+
|
112 |
+
def vis_results_3d(input_embed):
|
113 |
+
|
114 |
+
# performing dimensionality reduction using PCA
|
115 |
+
pca = PCA(n_components=3)
|
116 |
+
disease_embeddings_3d = pca.fit_transform(icd_embeddings)
|
117 |
+
|
118 |
+
# creating a DataFrame for disease embeddings plot
|
119 |
+
disease_data_df = pd.DataFrame(disease_embeddings_3d, columns=['PC1', 'PC2', 'PC3'])
|
120 |
+
disease_data_df['Type'] = 'Disease'
|
121 |
+
disease_data_df['Name'] = disease_names
|
122 |
+
|
123 |
+
input_embed_2d = input_embed.reshape(1, -1)
|
124 |
+
input_embed_3d = pca.transform(input_embed_2d)
|
125 |
+
|
126 |
+
# creating a DataFrame for character embedding plot
|
127 |
+
pca_3d = pd.DataFrame(input_embed_3d, columns=['PC1', 'PC2', 'PC3'])
|
128 |
+
pca_3d['Type'] = 'Character'
|
129 |
+
pca_3d['Your character'] = 'Your character'
|
130 |
+
|
131 |
+
# concatenating the two DataFrames
|
132 |
+
combined_3d = pd.concat([disease_data_df, pca_3d], ignore_index=True)
|
133 |
+
|
134 |
+
# creating an interactive 3D scatter plot
|
135 |
+
fig = px.scatter_3d(combined_3d, x='PC1', y='PC2', z='PC3', text='Name', color='Type', symbol='Type', width=800, height=800)
|
136 |
+
fig.show()
|
137 |
# with text_spinner_placeholder:
|
138 |
# with st.spinner("Please wait while your Tweet is being generated..."):
|
139 |
# mood_prompt = f"{mood} " if mood else ""
|
|
|
146 |
# f"and in the style of the following Tweets:\n\n{tweets_prompt}\n\n"
|
147 |
|
148 |
# Configure Streamlit page and state
|
149 |
+
st.title("Detect your character's mental disorder!")
|
150 |
st.markdown(
|
151 |
+
"This mini-app predicts top-5 most likely mental disorder based on your description. The more information you provide, the more informative the results will be. \
|
152 |
+
Note that this app can't be used for diagnostic purposes."
|
153 |
)
|
154 |
|
155 |
+
input = st.text_input(label="Your description", placeholder="Insert a description of your character")
|
156 |
if input:
|
157 |
input_embed = model.encode(input)
|
158 |
sim_score = similarity_top(input_embed, icd_embeddings)
|
159 |
st.write(sim_score)
|
160 |
+
|
161 |
+
vis_results_2d(input_embed)
|
162 |
+
vis_results_3d(input_embed)
|
163 |
+
|
164 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
165 |
|
166 |
text_spinner_placeholder = st.empty()
|
requirements.txt
CHANGED
@@ -1 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
streamlit==1.26.0
|
|
|
1 |
+
nltk==3.8.1
|
2 |
+
numpy==1.23.5
|
3 |
+
pandas==1.5.3
|
4 |
+
plotly==5.15.0
|
5 |
+
scikit_learn==1.3.1
|
6 |
+
sentence_transformers==2.2.2
|
7 |
streamlit==1.26.0
|