Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -18,12 +18,15 @@ st.write('Try to guess a secret word by semantic similarity')
|
|
18 |
|
19 |
word = st.text_input("Input a word")
|
20 |
|
|
|
|
|
21 |
if st.button("Guess") or word:
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
|
|
|
18 |
|
19 |
word = st.text_input("Input a word")
|
20 |
|
21 |
+
used_words = [w for w, s in st.session_state['words']]
|
22 |
+
|
23 |
if st.button("Guess") or word:
|
24 |
+
if word not in used_words:
|
25 |
+
word_embedding = model.encode(word)
|
26 |
+
similarity = util.pytorch_cos_sim(secred_embedding, word_embedding).cpu().numpy()[0][0]
|
27 |
+
st.session_state['words'].append((word, similarity))
|
28 |
+
words_df = pd.DataFrame(
|
29 |
+
st.session_state['words'],
|
30 |
+
columns=["word", "similarity"]
|
31 |
+
).sort_values(by=["similarity"], ascending=False)
|
32 |
+
st.dataframe(words_df)
|