schlenker commited on
Commit
9a26334
·
1 Parent(s): da4be0c

related word button changes

Browse files
Files changed (1) hide show
  1. app.py +10 -6
app.py CHANGED
@@ -47,12 +47,15 @@ def remove_punctuation(word):
47
 
48
  return word_without_punctuation
49
 
50
- def return_top_k(sentence, k=10):
51
 
52
- if sentence[-1] != ".":
53
- sentence = sentence + "."
54
 
55
- inputs = [f"Descripton : {sentence}. Word : "]
 
 
 
56
 
57
  inputs = tokenizer(
58
  inputs,
@@ -245,7 +248,8 @@ for message in st.session_state.messages:
245
  #display user message in chat message container
246
  prompt = get_text()
247
  if prompt:
248
- with st.chat_message('user', avatar='simon.jpg'):
 
249
  st.markdown(prompt)
250
  #add to history
251
  st.session_state.messages.append({'role': 'user', 'content': prompt})
@@ -348,7 +352,7 @@ if st.session_state.actions[-1] == 'cue':
348
 
349
  elif b6:
350
  sent = f"It is related to '{target}' but not '{target}'."
351
- rels = return_top_k(target)
352
 
353
  write_bot(f'Here are words that are related to your word: {", ".join(rels)}')
354
 
 
47
 
48
  return word_without_punctuation
49
 
50
+ def return_top_k(sentence, k=10, word=None, rels=False):
51
 
52
+ #if sentence[-1] != ".":
53
+ # sentence = sentence + "."
54
 
55
+ if rels:
56
+ inputs = [f"Description : It is related to '{word}' but not '{word}'. Word : "]
57
+ else:
58
+ inputs = [f"Description : {sentence}. Word : "]
59
 
60
  inputs = tokenizer(
61
  inputs,
 
248
  #display user message in chat message container
249
  prompt = get_text()
250
  if prompt:
251
+ #JS: would replace Simon by some neutral character
252
+ with st.chat_message('user'):
253
  st.markdown(prompt)
254
  #add to history
255
  st.session_state.messages.append({'role': 'user', 'content': prompt})
 
352
 
353
  elif b6:
354
  sent = f"It is related to '{target}' but not '{target}'."
355
+ rels = return_top_k(st.session_state.descriptions[-1], word=target, rels=True)
356
 
357
  write_bot(f'Here are words that are related to your word: {", ".join(rels)}')
358