schlenker commited on
Commit
1228435
·
1 Parent(s): eee8e53

changes in conversational flow

Browse files
Files changed (1) hide show
  1. app.py +115 -30
app.py CHANGED
@@ -128,7 +128,7 @@ def ask_if_helped():
128
  write_bot("Please describe your word!")
129
  # st.session_state.is_helpful['ask'] = False
130
 
131
- if st.session_state.actions[-1] == "result":
132
  a1 = st.button('Results', key=10)
133
  a2 = st.button('Cue', key=11)
134
  if a1:
@@ -144,7 +144,7 @@ if st.session_state.actions[-1] == "result":
144
  st.session_state.is_helpful['ask'] = True
145
 
146
  if st.session_state.is_helpful['ask'] == True:
147
- ask_if_helped()
148
 
149
  # JS
150
  def postproc_wn(related_words, syns=False):
@@ -165,7 +165,7 @@ def get_available_cues(target):
165
  available_cues = {}
166
  synset_target = wn.synsets(target, pos=wn.NOUN)[0]
167
 
168
- if wn.synonyms(target):
169
  available_cues['Synonyms'] = postproc_wn(wn.synonyms(target)[0], syns=True)
170
  #available_cues['Synonyms'] = [word.split('.')[0] if word[0] != "." else word.split('.')[1] for word in wn.synonyms(target)[0]]
171
 
@@ -189,7 +189,117 @@ def get_available_cues(target):
189
  else:
190
  return None
191
 
192
- if st.session_state.actions[-1] == 'cue':
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
193
  guessed = False
194
  write_bot('What do you want to see?', remember=False, blink=False)
195
 
@@ -254,32 +364,7 @@ if st.session_state.actions[-1] == 'cue':
254
  new = st.button('Play again', key=64)
255
  if new:
256
  write_bot("Please describe your word!")
257
- break
258
-
259
- #display user message in chat message container
260
- prompt = get_text()
261
- if prompt:
262
- with st.chat_message('user', avatar='simon.jpg'):
263
- st.markdown(prompt)
264
- #add to history
265
- st.session_state.messages.append({'role': 'user', 'content': prompt})
266
- yes = ['yes', 'again', 'Yes', 'sure', 'new word', 'yes!', 'yep', 'yeah']
267
- if prompt in yes:
268
- write_bot("Please describe your word!")
269
- elif prompt == 'It is similar to the best place on earth':
270
- write_bot("Great! Let me think what it could be...")
271
- time.sleep(3)
272
- write_bot("Do you mean Saarland?")
273
- #if previously we asked to give a prompt
274
- elif (st.session_state.messages[-2]['content'] == "Please describe your word!") & (st.session_state.messages[-1]['content'] != "no"):
275
- write_bot("Great! Let me think what it could be...")
276
- st.session_state.descriptions.append(prompt)
277
- st.session_state.results['results'] = return_top_k(st.session_state.descriptions[-1])
278
- st.session_state.results['results_print'] = dict(zip(range(1, 11), st.session_state.results['results']))
279
- write_bot("I think I have some ideas. Do you want to see my guesses or do you want a cue?")
280
- st.session_state.actions.append("result")
281
-
282
-
283
 
284
  # elif prompt == 'results':
285
  # st.text("results")
 
128
  write_bot("Please describe your word!")
129
  # st.session_state.is_helpful['ask'] = False
130
 
131
+ '''if st.session_state.actions[-1] == "result":
132
  a1 = st.button('Results', key=10)
133
  a2 = st.button('Cue', key=11)
134
  if a1:
 
144
  st.session_state.is_helpful['ask'] = True
145
 
146
  if st.session_state.is_helpful['ask'] == True:
147
+ ask_if_helped()'''
148
 
149
  # JS
150
  def postproc_wn(related_words, syns=False):
 
165
  available_cues = {}
166
  synset_target = wn.synsets(target, pos=wn.NOUN)[0]
167
 
168
+ if wn.synonyms(target)[0]:
169
  available_cues['Synonyms'] = postproc_wn(wn.synonyms(target)[0], syns=True)
170
  #available_cues['Synonyms'] = [word.split('.')[0] if word[0] != "." else word.split('.')[1] for word in wn.synonyms(target)[0]]
171
 
 
189
  else:
190
  return None
191
 
192
+ def cue_generation():
193
+ if st.session_state.actions[-1] == 'cue':
194
+ guessed = False
195
+ write_bot('What do you want to see?', remember=False, blink=False)
196
+
197
+ while guessed == False:
198
+ b1 = st.button("Next letter", key="1")
199
+ b2 = st.button("Next word", key="2")
200
+
201
+ # JS
202
+ word_count = st.session_state.counters["word_count"]
203
+ target = st.session_state.results["results"][word_count]
204
+ if get_available_cues(target):
205
+ avail_cues = get_available_cues(target)
206
+ cues_buttons = {}
207
+ for cue_type, cues in avail_cues.items():
208
+ #st.button(cue_type)
209
+ cues_buttons[cue_type] = st.button(cue_type)
210
+
211
+ b3 = st.button("All words", key="3")
212
+ b4 = st.button("I remembered the word!", key="4", type='primary')
213
+ b5 = st.button("Exit", key="5", type='primary')
214
+
215
+ if b1:
216
+ st.session_state.counters["letter_count"] += 1
217
+ word_count = st.session_state.counters["word_count"]
218
+ letter_count = st.session_state.counters["letter_count"]
219
+ write_bot(f'The word starts with {st.session_state.results["results"][word_count][:letter_count]}', remember=False)
220
+
221
+ elif b2:
222
+ st.session_state.counters["letter_count"] = 1
223
+ letter_count = st.session_state.counters["letter_count"]
224
+ st.session_state.counters["word_count"] += 1
225
+ word_count = st.session_state.counters["word_count"]
226
+ write_bot(f'The next word starts with {st.session_state.results["results"][word_count][:letter_count]}', remember=False)
227
+
228
+ elif "Synonyms" in cues_buttons and cues_buttons['Synonyms']:
229
+ write_bot(f'Here are synonyms for the current word: {", ".join(avail_cues["Synonyms"])}', remember=False)
230
+
231
+ elif "Hypernyms" in cues_buttons and cues_buttons['Hypernyms']:
232
+ write_bot(f'Here are hypernyms for the current word: {", ".join(avail_cues["Hypernyms"])}', remember=False)
233
+
234
+ elif "Hyponyms" in cues_buttons and cues_buttons['Hyponyms']:
235
+ write_bot(f'Here are hyponyms for the current word: {", ".join(avail_cues["Hyponyms"])}', remember=False)
236
+
237
+ elif "Examples" in cues_buttons and cues_buttons['Examples']:
238
+ write_bot(f'Here are example contexts for the current word: {", ".join(avail_cues["Examples"])}', remember=False)
239
+
240
+ elif b3:
241
+ write_bot(f"Here are all my guesses about your word: {st.session_state.results['results_print']}")
242
+
243
+ elif b4:
244
+ write_bot("Yay! I am happy I could be of help!")
245
+ new = st.button('Play again', key=63)
246
+ if new:
247
+ write_bot("Please describe your word!")
248
+ guessed = True
249
+
250
+ break
251
+
252
+ elif b5:
253
+ write_bot("I am sorry I couldn't help you this time. See you soon!")
254
+ st.session_state.actions.append('cue')
255
+ new = st.button('Play again', key=64)
256
+ if new:
257
+ write_bot("Please describe your word!")
258
+ break
259
+
260
+ #display user message in chat message container
261
+ prompt = get_text()
262
+ if prompt:
263
+ with st.chat_message('user', avatar='simon.jpg'):
264
+ st.markdown(prompt)
265
+ #add to history
266
+ st.session_state.messages.append({'role': 'user', 'content': prompt})
267
+ yes = ['yes', 'again', 'Yes', 'sure', 'new word', 'yes!', 'yep', 'yeah']
268
+ if prompt in yes:
269
+ write_bot("Please describe your word!")
270
+ elif prompt == 'It is similar to the best place on earth':
271
+ write_bot("Great! Let me think what it could be...")
272
+ time.sleep(3)
273
+ write_bot("Do you mean Saarland?")
274
+ #if previously we asked to give a prompt
275
+ elif (st.session_state.messages[-2]['content'] == "Please describe your word!") & (st.session_state.messages[-1]['content'] != "no"):
276
+ write_bot("Great! Let me think what it could be...")
277
+ st.session_state.descriptions.append(prompt)
278
+ st.session_state.results['results'] = return_top_k(st.session_state.descriptions[-1])
279
+ st.session_state.results['results_print'] = dict(zip(range(1, 11), st.session_state.results['results']))
280
+ write_bot("I think I have some ideas. Do you want to see my guesses or do you want a cue?")
281
+ st.session_state.actions.append("result")
282
+
283
+ if st.session_state.actions[-1] == "result":
284
+ a1 = st.button('Results', key=10)
285
+ a2 = st.button('Cue', key=11)
286
+ if a1:
287
+ write_bot("Here are my guesses about your word:")
288
+ st.write(st.session_state.results['results_print'])
289
+ time.sleep(1)
290
+ write_bot('Does it help you remember the word?', remember=False)
291
+ st.session_state.is_helpful['ask'] = True
292
+ elif a2:
293
+ #write_bot(f'The first letter is {st.session_state.results["results"][0][0]}.')
294
+ #time.sleep(1)
295
+ cue_generation()
296
+ write_bot('Does it help you remember the word?', remember=False)
297
+ st.session_state.is_helpful['ask'] = True
298
+
299
+ if st.session_state.is_helpful['ask']:
300
+ ask_if_helped()
301
+
302
+ '''if st.session_state.actions[-1] == 'cue':
303
  guessed = False
304
  write_bot('What do you want to see?', remember=False, blink=False)
305
 
 
364
  new = st.button('Play again', key=64)
365
  if new:
366
  write_bot("Please describe your word!")
367
+ break'''
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
368
 
369
  # elif prompt == 'results':
370
  # st.text("results")