Spaces:
Sleeping
Sleeping
bug with file locations fixed
Browse files- app.py +23 -577
- pages/App.py +0 -25
app.py
CHANGED
@@ -1,579 +1,25 @@
|
|
1 |
import streamlit as st
|
2 |
-
import torch
|
3 |
-
from tqdm import tqdm
|
4 |
-
from peft import PeftModel, PeftConfig
|
5 |
-
from transformers import AutoModelForSeq2SeqLM, AutoModelForCausalLM
|
6 |
-
from transformers import AutoTokenizer
|
7 |
-
import numpy as np
|
8 |
-
import time
|
9 |
-
import string
|
10 |
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
llama_tokenizer = AutoTokenizer.from_pretrained(model_name, use_auth_token=access_token, use_fast=True)#, use_fast=True)
|
35 |
-
llama_model = AutoModelForCausalLM.from_pretrained(model_name, use_auth_token=access_token, device_map={'':0})#, load_in_4bit=True)
|
36 |
-
st.write("The assistant is loaded and ready to use!")
|
37 |
-
return model, tokenizer, llama_model, llama_tokenizer
|
38 |
-
|
39 |
-
else:
|
40 |
-
st.write("_The assistant is loaded and ready to use! :tada:_")
|
41 |
-
return model, tokenizer
|
42 |
-
|
43 |
-
model, tokenizer = get_models()
|
44 |
-
|
45 |
-
def remove_punctuation(word):
|
46 |
-
# Create a translation table that maps all punctuation characters to None
|
47 |
-
translator = str.maketrans('', '', string.punctuation)
|
48 |
-
|
49 |
-
# Use the translate method to remove punctuation from the word
|
50 |
-
word_without_punctuation = word.translate(translator)
|
51 |
-
|
52 |
-
return word_without_punctuation
|
53 |
-
|
54 |
-
def return_top_k(sentence, k=10, word=None, rels=False):
|
55 |
-
|
56 |
-
if sentence[-1] != ".":
|
57 |
-
sentence = sentence + "."
|
58 |
-
|
59 |
-
if rels:
|
60 |
-
inputs = [f"Description : It is related to '{word}' but not '{word}'. Word : "]
|
61 |
-
else:
|
62 |
-
inputs = [f"Description : {sentence} Word : "]
|
63 |
-
|
64 |
-
inputs = tokenizer(
|
65 |
-
inputs,
|
66 |
-
padding=True, truncation=True,
|
67 |
-
return_tensors="pt",
|
68 |
-
)
|
69 |
-
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
70 |
-
model.to(device)
|
71 |
-
|
72 |
-
with torch.no_grad():
|
73 |
-
inputs = {k: v.to(device) for k, v in inputs.items()}
|
74 |
-
output_sequences = model.generate(input_ids=inputs["input_ids"], max_new_tokens=10, num_beams=k+5, num_return_sequences=k+5, #max_length=3,
|
75 |
-
top_p = 50, output_scores=True, return_dict_in_generate=True) #repetition_penalty=10000.0
|
76 |
-
|
77 |
-
logits = output_sequences['sequences_scores'].clone().detach()
|
78 |
-
decoded_probabilities = torch.softmax(logits, dim=0)
|
79 |
-
|
80 |
-
|
81 |
-
#all word predictions
|
82 |
-
predictions = [tokenizer.decode(tokens, skip_special_tokens=True) for tokens in output_sequences['sequences']]
|
83 |
-
probabilities = [round(float(prob), 2) for prob in decoded_probabilities]
|
84 |
-
|
85 |
-
stripped_sent = [remove_punctuation(word.lower()) for word in sentence.split()]
|
86 |
-
for pred in predictions:
|
87 |
-
if (len(pred) < 2) | (pred in stripped_sent):
|
88 |
-
predictions.pop(predictions.index(pred))
|
89 |
-
|
90 |
-
return predictions[:10]
|
91 |
-
|
92 |
-
# JS
|
93 |
-
def get_related_words(word, num=5):
|
94 |
-
model.eval()
|
95 |
-
with torch.no_grad():
|
96 |
-
sentence = [f"Descripton : It is related to {word} but not {word}. Word : "]
|
97 |
-
#inputs = ["Description: It is something to cut stuff with. Word: "]
|
98 |
-
print(sentence)
|
99 |
-
inputs = tokenizer(sentence, padding=True, truncation=True, return_tensors="pt",)
|
100 |
-
|
101 |
-
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
102 |
-
model.to(device)
|
103 |
-
|
104 |
-
batch = {k: v.to(device) for k, v in inputs.items()}
|
105 |
-
beam_outputs = model.generate(
|
106 |
-
input_ids=batch['input_ids'], max_new_tokens=10, num_beams=num+2, num_return_sequences=num+2, early_stopping=True
|
107 |
-
)
|
108 |
-
|
109 |
-
#beam_preds = [tokenizer.decode(beam_output.detach().cpu().numpy(), skip_special_tokens=True) for beam_output in beam_outputs if ]
|
110 |
-
beam_preds = []
|
111 |
-
for beam_output in beam_outputs:
|
112 |
-
prediction = tokenizer.decode(beam_output.detach().cpu().numpy(), skip_special_tokens=True).strip()
|
113 |
-
if prediction not in " ".join(sentence):
|
114 |
-
beam_preds.append(prediction)
|
115 |
-
|
116 |
-
return ", ".join(beam_preds[:num])
|
117 |
-
|
118 |
-
#if 'messages' not in st.session_state:
|
119 |
-
|
120 |
-
def get_text():
|
121 |
-
input_text = st.chat_input()
|
122 |
-
return input_text
|
123 |
-
|
124 |
-
def write_bot(input, remember=True, blink=True):
|
125 |
-
with st.chat_message('assistant'):
|
126 |
-
message_placeholder = st.empty()
|
127 |
-
full_response = input
|
128 |
-
if blink == True:
|
129 |
-
response = ''
|
130 |
-
for chunk in full_response.split():
|
131 |
-
response += chunk + " "
|
132 |
-
time.sleep(0.05)
|
133 |
-
# Add a blinking cursor to simulate typing
|
134 |
-
message_placeholder.markdown(response + "β")
|
135 |
-
time.sleep(0.5)
|
136 |
-
message_placeholder.markdown(full_response)
|
137 |
-
if remember == True:
|
138 |
-
st.session_state.messages.append({'role': 'assistant', 'content': full_response})
|
139 |
-
|
140 |
-
def ask_if_helped():
|
141 |
-
y = st.button('Yes!', key=60)
|
142 |
-
n = st.button('No...', key=61)
|
143 |
-
new = st.button('I have a new word', key=62)
|
144 |
-
if y:
|
145 |
-
write_bot("I am happy to help!")
|
146 |
-
again = st.button('Play again')
|
147 |
-
if again:
|
148 |
-
write_bot("Please describe your word!")
|
149 |
-
st.session_state.is_helpful['ask'] = False
|
150 |
-
elif n:
|
151 |
-
st.session_state.actions.append('cue')
|
152 |
-
st.session_state.is_helpful['ask'] = False
|
153 |
-
#cue_generation()
|
154 |
-
elif new:
|
155 |
-
write_bot("Please describe your word!")
|
156 |
-
st.session_state.is_helpful['ask'] = False
|
157 |
-
|
158 |
-
## removed: if st.session_state.actions[-1] == "result":
|
159 |
-
|
160 |
-
# JS
|
161 |
-
def get_related_words_llama(relation, target, device, num=5):
|
162 |
-
prompt = f"Provide {num} {relation}s for the word '{target}'. Your answer consists of these {num} words only. Do not include the word '{target}' itself in your answer"
|
163 |
-
|
164 |
-
inputs = tokenizer([prompt], return_tensors='pt').to(device)
|
165 |
-
output = model.generate(
|
166 |
-
**inputs, max_new_tokens=40, temperature=.75, early_stopping=True,
|
167 |
-
)
|
168 |
-
chatbot_response = tokenizer.decode(output[:, inputs['input_ids'].shape[-1]:][0], skip_special_tokens=True).strip()
|
169 |
-
|
170 |
-
postproc = [word for word in word_tokenize(chatbot_response) if len(word)>=3]
|
171 |
-
|
172 |
-
return postproc[-num:] if len(postproc)>=num else postproc
|
173 |
-
|
174 |
-
|
175 |
-
def postproc_wn(related_words, syns=False):
|
176 |
-
if syns:
|
177 |
-
related_words = [word.split('.')[0] if word[0] != "." else word.split('.')[1] for word in related_words]
|
178 |
-
else:
|
179 |
-
related_words = [word.name().split('.')[0] if word.name()[0] != "." else word.name().split('.')[1] for word in related_words]
|
180 |
-
related_words = [word.replace("_", " ") for word in related_words]
|
181 |
-
|
182 |
-
return related_words
|
183 |
-
|
184 |
-
# JS
|
185 |
-
def get_available_cues(target):
|
186 |
-
wn_nouns = [word.name() for word in wn.all_synsets(pos='n')]
|
187 |
-
wn_nouns = [word.split('.')[0] if word[0] != "." else word.split('.')[1] for word in wn_nouns]
|
188 |
-
|
189 |
-
if target in wn_nouns:
|
190 |
-
available_cues = {}
|
191 |
-
synset_target = wn.synsets(target, pos=wn.NOUN)[0]
|
192 |
-
|
193 |
-
#if wn.synonyms(target)[0]:
|
194 |
-
# available_cues['Synonyms'] = postproc_wn(wn.synonyms(target)[0], syns=True)
|
195 |
-
|
196 |
-
#if synset_target.hypernyms():
|
197 |
-
# available_cues['Hypernyms'] = postproc_wn(synset_target.hypernyms())
|
198 |
-
|
199 |
-
|
200 |
-
#if synset_target.hyponyms():
|
201 |
-
# available_cues['Hyponyms'] = postproc_wn(synset_target.hyponyms())
|
202 |
-
|
203 |
-
if synset_target.examples():
|
204 |
-
examples = []
|
205 |
-
|
206 |
-
for example in synset_target.examples():
|
207 |
-
examples.append(example.replace(target, "..."))
|
208 |
-
|
209 |
-
available_cues['Examples'] = examples
|
210 |
-
|
211 |
-
return available_cues
|
212 |
-
|
213 |
-
else:
|
214 |
-
return None
|
215 |
-
|
216 |
-
# JS: moved the cue generation further down
|
217 |
-
#def cue_generation():
|
218 |
-
# if st.session_state.actions[-1] == 'cue':
|
219 |
-
|
220 |
-
if 'messages' not in st.session_state:
|
221 |
-
st.session_state.messages = []
|
222 |
-
|
223 |
-
if 'results' not in st.session_state:
|
224 |
-
st.session_state.results = {'results': False, 'results_print': False}
|
225 |
-
|
226 |
-
if 'actions' not in st.session_state:
|
227 |
-
st.session_state.actions = [""]
|
228 |
-
|
229 |
-
if 'counters' not in st.session_state:
|
230 |
-
st.session_state.counters = {"letter_count": 0, "word_count": 0}
|
231 |
-
|
232 |
-
if 'is_helpful' not in st.session_state:
|
233 |
-
st.session_state.is_helpful = {'ask':False}
|
234 |
-
|
235 |
-
if 'descriptions' not in st.session_state:
|
236 |
-
st.session_state.descriptions = []
|
237 |
-
|
238 |
-
st.title("You name it! π£")
|
239 |
-
|
240 |
-
# JS: would remove Simon by some neutral avatar
|
241 |
-
with st.chat_message('user'):
|
242 |
-
st.write("Hey assistant!")
|
243 |
-
|
244 |
-
bot = st.chat_message('assistant')
|
245 |
-
bot.write("Hello human! Wanna practice naming some words?")
|
246 |
-
|
247 |
-
#for showing history of messages
|
248 |
-
for message in st.session_state.messages:
|
249 |
-
if message['role'] == 'user':
|
250 |
-
with st.chat_message(message['role']):
|
251 |
-
st.markdown(message['content'])
|
252 |
-
else:
|
253 |
-
with st.chat_message(message['role']):
|
254 |
-
st.markdown(message['content'])
|
255 |
-
|
256 |
-
#display user message in chat message container
|
257 |
-
prompt = get_text()
|
258 |
-
if prompt:
|
259 |
-
#JS: would replace Simon by some neutral character
|
260 |
-
with st.chat_message('user'):
|
261 |
-
st.markdown(prompt)
|
262 |
-
#add to history
|
263 |
-
st.session_state.messages.append({'role': 'user', 'content': prompt})
|
264 |
-
#TODO: replace it with zero-shot classifier
|
265 |
-
yes = ['yes', 'again', 'Yes', 'sure', 'new word', 'yes!', 'yep', 'yeah']
|
266 |
-
if prompt in yes:
|
267 |
-
write_bot("Please describe your word!")
|
268 |
-
elif prompt == 'It is similar to the best place on earth':
|
269 |
-
write_bot("Great! Let me think what it could be...")
|
270 |
-
time.sleep(3)
|
271 |
-
write_bot("Do you mean Saarland?")
|
272 |
-
#if previously we asked to give a prompt
|
273 |
-
elif (st.session_state.messages[-2]['content'] == "Please describe your word!") & (st.session_state.messages[-1]['content'] != "no"):
|
274 |
-
write_bot("Great! Let me think what it could be...")
|
275 |
-
st.session_state.descriptions.append(prompt)
|
276 |
-
st.session_state.results['results'] = return_top_k(st.session_state.descriptions[-1])
|
277 |
-
st.session_state.results['results_print'] = dict(zip(range(1, 11), st.session_state.results['results']))
|
278 |
-
write_bot("I think I have some ideas. Do you want to see my guesses or do you want a cue?")
|
279 |
-
st.session_state.actions.append("result")
|
280 |
-
|
281 |
-
if st.session_state.actions[-1] == "result":
|
282 |
-
col1, col2, col3, col4, col5 = st.columns(5)
|
283 |
-
with col1:
|
284 |
-
a1 = st.button('Results', key=10)
|
285 |
-
with col2:
|
286 |
-
a2 = st.button('Cue', key=11)
|
287 |
-
if a1:
|
288 |
-
write_bot("Here are my guesses about your word:")
|
289 |
-
st.write(st.session_state.results['results_print'])
|
290 |
-
time.sleep(1)
|
291 |
-
write_bot('Does it help you remember the word?', remember=False)
|
292 |
-
st.session_state.is_helpful['ask'] = True
|
293 |
-
elif a2:
|
294 |
-
#write_bot(f'The first letter is {st.session_state.results["results"][0][0]}.')
|
295 |
-
#time.sleep(1)
|
296 |
-
st.session_state.actions.append('cue')
|
297 |
-
#cue_generation()
|
298 |
-
#write_bot('Does it help you remember the word?', remember=False)
|
299 |
-
#st.session_state.is_helpful['ask'] = True
|
300 |
-
|
301 |
-
if st.session_state.is_helpful['ask']:
|
302 |
-
ask_if_helped()
|
303 |
-
|
304 |
-
if st.session_state.actions[-1] == 'cue':
|
305 |
-
guessed = False
|
306 |
-
write_bot('What do you want to see?', remember=False, blink=False)
|
307 |
-
|
308 |
-
while guessed == False:
|
309 |
-
# JS
|
310 |
-
word_count = st.session_state.counters["word_count"]
|
311 |
-
target = st.session_state.results["results"][word_count]
|
312 |
-
|
313 |
-
col1, col2, col3, col4, col5 = st.columns(5)
|
314 |
-
|
315 |
-
|
316 |
-
with col1:
|
317 |
-
b1 = st.button("Next letter", key="1")
|
318 |
-
with col2:
|
319 |
-
b2 = st.button("Related words")
|
320 |
-
with col3:
|
321 |
-
b3 = st.button("Next word", key="2")
|
322 |
-
with col4:
|
323 |
-
b4 = st.button("All words", key="3")
|
324 |
-
|
325 |
-
# JS
|
326 |
-
#if get_available_cues(target):
|
327 |
-
# avail_cues = get_available_cues(target)
|
328 |
-
#cues_buttons = {cue_type: st.button(cue_type) for cue_type in avail_cues}
|
329 |
-
|
330 |
-
b5 = st.button("I remembered the word!", key="4", type='primary')
|
331 |
-
b6 = st.button("Exit", key="5", type='primary')
|
332 |
-
new = st.button('Play again', key=64, type='primary')
|
333 |
-
|
334 |
-
if b1:
|
335 |
-
st.session_state.counters["letter_count"] += 1
|
336 |
-
#word_count = st.session_state.counters["word_count"]
|
337 |
-
letter_count = st.session_state.counters["letter_count"]
|
338 |
-
if letter_count < len(target):
|
339 |
-
write_bot(f'The word starts with {st.session_state.results["results"][word_count][:letter_count]}. \n Does this help you remember the word?', remember=False)
|
340 |
-
#ask_if_helped()
|
341 |
-
st.session_state.is_helpful['ask'] = True
|
342 |
-
else:
|
343 |
-
write_bot(f'This is my predicted word: "{target}". Does this match your query?')
|
344 |
-
#ask_if_helped()
|
345 |
-
st.session_state.is_helpful['ask'] = True
|
346 |
-
|
347 |
-
elif b2:
|
348 |
-
rels = return_top_k(st.session_state.descriptions[-1], word=target, rels=True)
|
349 |
-
write_bot(f'Here are words that are related to your word: {", ".join(rels)}. \n Does this help you remember the word?', remember=False)
|
350 |
-
#ask_if_helped()
|
351 |
-
st.session_state.is_helpful['ask'] = True
|
352 |
-
|
353 |
-
elif b3:
|
354 |
-
st.session_state.counters["letter_count"] = 1
|
355 |
-
letter_count = st.session_state.counters["letter_count"]
|
356 |
-
st.session_state.counters["word_count"] += 1
|
357 |
-
word_count = st.session_state.counters["word_count"]
|
358 |
-
#write_bot(f'The next word starts with {st.session_state.results["results"][word_count][:letter_count]}', remember=False)
|
359 |
-
if letter_count < len(target):
|
360 |
-
write_bot(f'The next word starts with {st.session_state.results["results"][word_count][:letter_count]}. \n Does this help you remember the word?', remember=False)
|
361 |
-
#ask_if_helped()
|
362 |
-
st.session_state.is_helpful['ask'] = True
|
363 |
-
else:
|
364 |
-
write_bot(f'This is my predicted word: "{target}". Does this match your query?')
|
365 |
-
#ask_if_helped()
|
366 |
-
st.session_state.is_helpful['ask'] = True
|
367 |
-
|
368 |
-
#elif get_available_cues(target) and "Synonyms" in cues_buttons and cues_buttons['Synonyms']:
|
369 |
-
#write_bot(f'Here are synonyms for the current word: {", ".join(avail_cues["Synonyms"])}', remember=False)
|
370 |
-
|
371 |
-
#elif get_available_cues(target) and "Hypernyms" in cues_buttons and cues_buttons['Hypernyms']:
|
372 |
-
#write_bot(f'Here are hypernyms for the current word: {", ".join(avail_cues["Hypernyms"])}', remember=False)
|
373 |
-
|
374 |
-
#elif get_available_cues(target) and "Hyponyms" in cues_buttons and cues_buttons['Hyponyms']:
|
375 |
-
#write_bot(f'Here are hyponyms for the current word: {", ".join(avail_cues["Hyponyms"])}', remember=False)
|
376 |
-
|
377 |
-
#elif get_available_cues(target) and "Examples" in cues_buttons and cues_buttons['Examples']:
|
378 |
-
#write_bot(f'Here are example contexts for the current word: {", ".join(avail_cues["Examples"])}', remember=False)
|
379 |
-
|
380 |
-
elif b4:
|
381 |
-
write_bot(f"Here are all my guesses about your word: {st.session_state.results['results_print']}")
|
382 |
-
|
383 |
-
elif b5:
|
384 |
-
write_bot("Yay! I am happy I could be of help!")
|
385 |
-
st.session_state.counters["word_count"] = 0
|
386 |
-
st.session_state.counters["letter_count"] = 0
|
387 |
-
new = st.button('Play again', key=63)
|
388 |
-
if new:
|
389 |
-
write_bot("Please describe your word!")
|
390 |
-
guessed = True
|
391 |
-
|
392 |
-
break
|
393 |
-
|
394 |
-
elif b6:
|
395 |
-
write_bot("I am sorry I couldn't help you this time. See you soon!")
|
396 |
-
st.session_state.counters["word_count"] = 0
|
397 |
-
st.session_state.counters["letter_count"] = 0
|
398 |
-
st.session_state.actions.append('cue')
|
399 |
-
|
400 |
-
if new:
|
401 |
-
write_bot("Please describe your word!")
|
402 |
-
st.session_state.counters["word_count"] = 0
|
403 |
-
st.session_state.counters["letter_count"] = 0
|
404 |
-
|
405 |
-
break
|
406 |
-
|
407 |
-
# elif prompt == 'results':
|
408 |
-
# st.text("results")
|
409 |
-
# st.write("results")
|
410 |
-
# st.session_state.actions.append({'result': True})
|
411 |
-
# st.write(st.session_state.actions)
|
412 |
-
# with st.chat_message('user'):
|
413 |
-
# custom_response = "Results"
|
414 |
-
# st.markdown(custom_response)
|
415 |
-
# st.session_state.messages.append({'role': 'user', 'content': custom_response})
|
416 |
-
|
417 |
-
# with st.chat_message('assistant'):
|
418 |
-
# message_placeholder = st.empty()
|
419 |
-
# response = f"Here are my guesses about your word: {result_print}"
|
420 |
-
# message_placeholder.markdown(response + "|")
|
421 |
-
# st.session_state.messages.append({'role': 'assistant', 'content': response})
|
422 |
-
# elif st.button('Cue'):
|
423 |
-
# response = "Cue"
|
424 |
-
# with st.chat_message('user'):
|
425 |
-
# st.markdown(response)
|
426 |
-
# st.session_state.messages.append({'role': 'user', 'content': response})
|
427 |
-
# text = f'The first letter is {result[0][0]}.'
|
428 |
-
# bot.write(text)
|
429 |
-
# st.session_state.messages.append({'role': 'assistant', 'content': text})
|
430 |
-
# letter_count = 1
|
431 |
-
# word_count = 0
|
432 |
-
# elif prompt == 'Results':
|
433 |
-
# with st.chat_message('assistant'):
|
434 |
-
# message_placeholder = st.empty()
|
435 |
-
# response = f"Here are my guesses about your word: {result_print}"
|
436 |
-
# message_placeholder.markdown(response + "|")
|
437 |
-
# st.session_state.messages.append({'role': 'assistant', 'content': response})
|
438 |
-
|
439 |
-
# #if you don't wanna practice word naming
|
440 |
-
# else:
|
441 |
-
# with st.chat_message('assistant'):
|
442 |
-
# message_placeholder = st.empty()
|
443 |
-
# response = "See you next time!"
|
444 |
-
# message_placeholder.markdown(response + "|")
|
445 |
-
# st.session_state.messages.append({'role': 'assistant', 'content': response})
|
446 |
-
|
447 |
-
|
448 |
-
|
449 |
-
# if st.button('Results'):
|
450 |
-
# bot.write("Here are my guesses about your word:")
|
451 |
-
# bot.write(result_print)
|
452 |
-
# elif st.button('Cue'):
|
453 |
-
# bot.write(f'The first letter is {result[0][0]}.')
|
454 |
-
# letter_count = 1
|
455 |
-
# word_count = 0
|
456 |
-
# answer = st.chat_input('Does it help you remember the word? Type yes or no')
|
457 |
-
# if answer == "no":
|
458 |
-
# bot.write("What do you want to see?")
|
459 |
-
# if st.button('Next letter'):
|
460 |
-
# letter_count += 1
|
461 |
-
# bot.write(f'The word starts with {result[word_count][:letter_count]}')
|
462 |
-
# elif st.button('Next word'):
|
463 |
-
# letter_count = 1
|
464 |
-
# bot.write(f'The next word starts with {result[word_count][:letter_count]}')
|
465 |
-
# word_count += 1
|
466 |
-
# elif st.button('All words'):
|
467 |
-
# bot.write("Here are all my guesses about your word:")
|
468 |
-
# bot.write(result_print)
|
469 |
-
# bot.write("Does this help you remember your word?")
|
470 |
-
# answer = st.chat_input('Type yes/no/exit')
|
471 |
-
# if answer == 'Exit':
|
472 |
-
# st.write("I am sorry I couldn't help you. See you next time!")
|
473 |
-
|
474 |
-
|
475 |
-
#write down assistant's responses
|
476 |
-
#response = f'Echo: {prompt}' #echoes prompt
|
477 |
-
# with st.chat_message('assistant'):
|
478 |
-
# message_placeholder = st.empty()
|
479 |
-
# full_response = "yeee"
|
480 |
-
# #here insert the loop with the model answers (for response in...)
|
481 |
-
# #this to imitate a cursor
|
482 |
-
# message_placeholder.markdown(full_response + "|")
|
483 |
-
|
484 |
-
# #add to history
|
485 |
-
# st.session_state.messages.append({'role': 'assistant', 'content': full_response})
|
486 |
-
|
487 |
-
|
488 |
-
|
489 |
-
##TODO: a button to delete history
|
490 |
-
# if prompt == 'Yes':
|
491 |
-
# bot.write("Great! Please describe the word you have in mind.")
|
492 |
-
# sent = st.chat_input('Description of your word')
|
493 |
-
|
494 |
-
|
495 |
-
# # adding the text that will show in the text box as default
|
496 |
-
# default_value = "Type the description of the word you have in mind!"
|
497 |
-
|
498 |
-
# sent = st.text_area("Text", default_value, height = 50)
|
499 |
-
# result = return_top_k(sent)
|
500 |
-
# result = ['animal', 'monster', 'creature', 'bird', 'cat', 'human', 'dog', 'spider', 'alien', 'meow']
|
501 |
-
# result = return_top_k(sent)
|
502 |
-
# result_print = dict(zip(range(1, 11), result))
|
503 |
-
|
504 |
-
# if st.button('Results'):
|
505 |
-
# st.write("Here are my guesses about your word:")
|
506 |
-
# st.write(result_print)
|
507 |
-
# elif st.button('Cue'):
|
508 |
-
# st.write(f'The first letter is {result[0][0]}.')
|
509 |
-
# letter_count = 1
|
510 |
-
# word_count = 0
|
511 |
-
# answer = st.text_area("Text", 'Does it help you remember the word? Type yes or no', height = 50)
|
512 |
-
# if answer == 'No':
|
513 |
-
# while answer == 'No':
|
514 |
-
# option = st.selectbox(
|
515 |
-
# 'What do you want to see?',
|
516 |
-
# ('Next letter', 'Next word', 'All words'))
|
517 |
-
# if option == 'Next letter':
|
518 |
-
# letter_count += 1
|
519 |
-
# st.write(f'The word starts with {result[word_count][:letter_count]}')
|
520 |
-
# elif option == 'Next word':
|
521 |
-
# letter_count = 1
|
522 |
-
# st.write(f'The next word starts with {result[word_count][:letter_count]}')
|
523 |
-
# word_count += 1
|
524 |
-
# else:
|
525 |
-
# st.write("Here are all my guesses about your word:")
|
526 |
-
# st.write(result_print)
|
527 |
-
# answer = st.selectbox(
|
528 |
-
# 'Does it help you remember the word??',
|
529 |
-
# ('Yes', 'No', 'Exit'))
|
530 |
-
# if answer == 'Exit':
|
531 |
-
# st.write("I am sorry I couldn't help you. See you next time!")
|
532 |
-
# break
|
533 |
-
# else:
|
534 |
-
# st.write("I am happy I could be of help!")
|
535 |
-
# else:
|
536 |
-
# st.write('Do you want to see my guesses or do you want a cue?')
|
537 |
-
|
538 |
-
|
539 |
-
#2
|
540 |
-
|
541 |
-
# option = st.selectbox(
|
542 |
-
# 'Do you want to see my guesses or do you want a cue?',
|
543 |
-
# ('Results', 'Cue'))
|
544 |
-
|
545 |
-
# st.write('You selected:', option)
|
546 |
-
|
547 |
-
# if option == 'Results':
|
548 |
-
# st.write("Here are my guesses about your word:")
|
549 |
-
# st.write(result_print)
|
550 |
-
# elif option == 'Cue':
|
551 |
-
# st.write(f'The first letter is {result[0][0]}.')
|
552 |
-
# letter_count = 1
|
553 |
-
# word_count = 0
|
554 |
-
# answer = st.selectbox(
|
555 |
-
# 'Does it help you remember the word??',
|
556 |
-
# ('Yes', 'No'))
|
557 |
-
# if answer == 'No':
|
558 |
-
# while answer == 'No':
|
559 |
-
# option = st.selectbox(
|
560 |
-
# 'What do you want to see?',
|
561 |
-
# ('Next letter', 'Next word', 'All words'))
|
562 |
-
# if option == 'Next letter':
|
563 |
-
# letter_count += 1
|
564 |
-
# st.write(f'The word starts with {result[word_count][:letter_count]}')
|
565 |
-
# elif option == 'Next word':
|
566 |
-
# letter_count = 1
|
567 |
-
# st.write(f'The next word starts with {result[word_count][:letter_count]}')
|
568 |
-
# word_count += 1
|
569 |
-
# else:
|
570 |
-
# st.write("Here are all my guesses about your word:")
|
571 |
-
# st.write(result_print)
|
572 |
-
# answer = st.selectbox(
|
573 |
-
# 'Does it help you remember the word??',
|
574 |
-
# ('Yes', 'No', 'Exit'))
|
575 |
-
# if answer == 'Exit':
|
576 |
-
# st.write("I am sorry I couldn't help you. See you next time!")
|
577 |
-
# break
|
578 |
-
# else:
|
579 |
-
# st.write("I am happy I could be of help!")
|
|
|
1 |
import streamlit as st
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
+
st.set_page_config(
|
4 |
+
page_title="You Name It!",
|
5 |
+
page_icon="π",
|
6 |
+
)
|
7 |
+
|
8 |
+
st.write("# Welcome to YouNameIt chatbot! π")
|
9 |
+
|
10 |
+
st.sidebar.success("Select a chatbot mode above.")
|
11 |
+
|
12 |
+
st.markdown(
|
13 |
+
"""
|
14 |
+
YouNameIt is a project helping people with aphasia practice their word retrieval skill and assisting them to remember words on a daily basis.
|
15 |
+
**π Select a chatbot mode from the sidebar** to test our app!
|
16 |
+
### What new features are planned?
|
17 |
+
- Adaptation to German language and more;
|
18 |
+
- Speech-to-text suppport;
|
19 |
+
- Android & IOS mobile apps.
|
20 |
+
### For any suggestions or ideas please contact us.
|
21 |
+
- Julian []()
|
22 |
+
- Nursulu []()
|
23 |
+
"""
|
24 |
+
)
|
25 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pages/App.py
DELETED
@@ -1,25 +0,0 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
|
3 |
-
st.set_page_config(
|
4 |
-
page_title="You Name It!",
|
5 |
-
page_icon="π",
|
6 |
-
)
|
7 |
-
|
8 |
-
st.write("# Welcome to YouNameIt chatbot! π")
|
9 |
-
|
10 |
-
st.sidebar.success("Select a chatbot mode above.")
|
11 |
-
|
12 |
-
st.markdown(
|
13 |
-
"""
|
14 |
-
YouNameIt is a project helping people with aphasia practice their word retrieval skill and assisting them to remember words on a daily basis.
|
15 |
-
**π Select a chatbot mode from the sidebar** to test our app!
|
16 |
-
### What new features are planned?
|
17 |
-
- Adaptation to German language and more;
|
18 |
-
- Speech-to-text suppport;
|
19 |
-
- Android & IOS mobile apps.
|
20 |
-
### For any suggestions or ideas please contact us.
|
21 |
-
- Julian []()
|
22 |
-
- Nursulu []()
|
23 |
-
"""
|
24 |
-
)
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|