Spaces:
Configuration error
Configuration error
simple ui to plot and select samples
Browse files
app.py
CHANGED
|
@@ -1,3 +1,29 @@
|
|
| 1 |
import streamlit as st
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
-
st.write(f'streamlit version: {st.__version__}')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import pandas as pd
|
| 3 |
+
from gensim.models import Word2Vec
|
| 4 |
+
import matplotlib.pyplot as plt
|
| 5 |
|
| 6 |
+
# DEBUG st.write(f'streamlit version: {st.__version__}')
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
model_name = st.text_input('Enter model version: ', 'metapath2vec_v1.202112011')
|
| 10 |
+
|
| 11 |
+
model = Word2Vec.load(f'models/{model_name}.pkl')
|
| 12 |
+
|
| 13 |
+
positive_samples = st.multiselect('Positive samples', options=model.wv.index_to_key, default=[])
|
| 14 |
+
negative_samples = st.multiselect('Negative samples', options=model.wv.index_to_key, default=[])
|
| 15 |
+
n_recomms = 5
|
| 16 |
+
|
| 17 |
+
if len(positive_samples) + len(negative_samples) > 0:
|
| 18 |
+
st.header('Recommendations:')
|
| 19 |
+
recomms = model.wv.most_similar(positive=positive_samples,
|
| 20 |
+
negative=negative_samples,
|
| 21 |
+
topn=n_recomms)
|
| 22 |
+
recomms_df = pd.DataFrame(recomms, columns=['word', 'similarity'])
|
| 23 |
+
ax = recomms_df.plot(x='word', y='similarity', kind='barh')
|
| 24 |
+
ax.invert_yaxis()
|
| 25 |
+
st.pyplot(plt)
|
| 26 |
+
else:
|
| 27 |
+
st.warning('No samples selected')
|
| 28 |
+
|
| 29 |
+
# st.write(recomms_df)
|