Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -19,8 +19,7 @@ def get_models():
|
|
19 |
|
20 |
st.session_state.model['model'] = model
|
21 |
st.session_state.model['tokenizer'] = tokenizer
|
22 |
-
|
23 |
-
st.write("The assistant is loaded and ready to use!")
|
24 |
|
25 |
def return_top_k(sentence, k=10):
|
26 |
|
@@ -79,12 +78,12 @@ if 'model' not in st.session_state:
|
|
79 |
|
80 |
if st.session_state.model['model'] == False:
|
81 |
get_models()
|
|
|
82 |
|
83 |
st.title("You name it!")
|
84 |
|
85 |
-
|
86 |
-
|
87 |
-
st.write("Hey assistant! All good?")
|
88 |
|
89 |
bot = st.chat_message('assistant')
|
90 |
bot.write("Hello human! Wanna practice naming some words?")
|
@@ -98,17 +97,18 @@ def get_text():
|
|
98 |
input_text = st.chat_input()
|
99 |
return input_text
|
100 |
|
101 |
-
def write_bot(input, remember=True):
|
102 |
with st.chat_message('assistant'):
|
103 |
message_placeholder = st.empty()
|
104 |
full_response = input
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
|
|
112 |
message_placeholder.markdown(full_response)
|
113 |
if remember == True:
|
114 |
st.session_state.messages.append({'role': 'assistant', 'content': full_response})
|
@@ -121,6 +121,7 @@ def ask_if_helped():
|
|
121 |
write_bot("I am happy to help!")
|
122 |
elif n:
|
123 |
st.session_state.actions.append('cue')
|
|
|
124 |
|
125 |
if st.session_state.actions[-1] == "result":
|
126 |
a1 = st.button('Results', key=10)
|
@@ -128,12 +129,12 @@ if st.session_state.actions[-1] == "result":
|
|
128 |
if a1:
|
129 |
write_bot("Here are my guesses about your word:")
|
130 |
st.write(st.session_state.results['results_print'])
|
131 |
-
time.sleep(
|
132 |
write_bot('Does it help you remember the word?', remember=False)
|
133 |
st.session_state.is_helpful['ask'] = True
|
134 |
elif a2:
|
135 |
write_bot(f'The first letter is {st.session_state.results["results"][0][0]}.')
|
136 |
-
time.sleep(
|
137 |
write_bot('Does it help you remember the word?', remember=False)
|
138 |
st.session_state.is_helpful['ask'] = True
|
139 |
|
@@ -143,7 +144,7 @@ ask_if_helped()
|
|
143 |
|
144 |
if st.session_state.actions[-1] == 'cue':
|
145 |
guessed = False
|
146 |
-
write_bot('What do you want to see?', remember=False)
|
147 |
b1 = st.button("Next letter", key="1")
|
148 |
b2 = st.button("Next word", key="2")
|
149 |
b3 = st.button("All words", key="3")
|
@@ -154,14 +155,14 @@ if st.session_state.actions[-1] == 'cue':
|
|
154 |
st.session_state.counters["letter_count"] += 1
|
155 |
word_count = st.session_state.counters["word_count"]
|
156 |
letter_count = st.session_state.counters["letter_count"]
|
157 |
-
write_bot(f'The word starts with {st.session_state.results["results"][word_count][:letter_count]}')
|
158 |
|
159 |
elif b2:
|
160 |
st.session_state.counters["letter_count"] = 1
|
161 |
letter_count = st.session_state.counters["letter_count"]
|
162 |
st.session_state.counters["word_count"] += 1
|
163 |
word_count = st.session_state.counters["word_count"]
|
164 |
-
write_bot(f'The next word starts with {st.session_state.results["results"][word_count][:letter_count]}')
|
165 |
|
166 |
elif b3:
|
167 |
write_bot(f"Here are all my guesses about your word: {st.session_state.results['results_print']}")
|
@@ -183,8 +184,8 @@ if prompt:
|
|
183 |
st.markdown(prompt)
|
184 |
#add to history
|
185 |
st.session_state.messages.append({'role': 'user', 'content': prompt})
|
186 |
-
yes =
|
187 |
-
if prompt
|
188 |
write_bot("Please describe your word!")
|
189 |
#if previously we asked to give a prompt
|
190 |
elif (st.session_state.messages[-2]['content'] == "Please describe your word!") & (st.session_state.messages[-1]['content'] != "no"):
|
@@ -367,10 +368,4 @@ if prompt:
|
|
367 |
# break
|
368 |
# else:
|
369 |
# st.write("I am happy I could be of help!")
|
370 |
-
|
371 |
-
|
372 |
-
|
373 |
-
|
374 |
-
|
375 |
-
|
376 |
-
|
|
|
19 |
|
20 |
st.session_state.model['model'] = model
|
21 |
st.session_state.model['tokenizer'] = tokenizer
|
22 |
+
|
|
|
23 |
|
24 |
def return_top_k(sentence, k=10):
|
25 |
|
|
|
78 |
|
79 |
if st.session_state.model['model'] == False:
|
80 |
get_models()
|
81 |
+
st.write("The assistant is loaded and ready to use!")
|
82 |
|
83 |
st.title("You name it!")
|
84 |
|
85 |
+
with st.chat_message('user'):
|
86 |
+
st.write("Hey assistant!")
|
|
|
87 |
|
88 |
bot = st.chat_message('assistant')
|
89 |
bot.write("Hello human! Wanna practice naming some words?")
|
|
|
97 |
input_text = st.chat_input()
|
98 |
return input_text
|
99 |
|
100 |
+
def write_bot(input, remember=True, blink=True):
|
101 |
with st.chat_message('assistant'):
|
102 |
message_placeholder = st.empty()
|
103 |
full_response = input
|
104 |
+
if blink == True:
|
105 |
+
response = ''
|
106 |
+
for chunk in full_response.split():
|
107 |
+
response += chunk + " "
|
108 |
+
time.sleep(0.05)
|
109 |
+
# Add a blinking cursor to simulate typing
|
110 |
+
message_placeholder.markdown(response + "β")
|
111 |
+
time.sleep(0.5)
|
112 |
message_placeholder.markdown(full_response)
|
113 |
if remember == True:
|
114 |
st.session_state.messages.append({'role': 'assistant', 'content': full_response})
|
|
|
121 |
write_bot("I am happy to help!")
|
122 |
elif n:
|
123 |
st.session_state.actions.append('cue')
|
124 |
+
st.session_state.is_helpful['ask'] = False
|
125 |
|
126 |
if st.session_state.actions[-1] == "result":
|
127 |
a1 = st.button('Results', key=10)
|
|
|
129 |
if a1:
|
130 |
write_bot("Here are my guesses about your word:")
|
131 |
st.write(st.session_state.results['results_print'])
|
132 |
+
time.sleep(1)
|
133 |
write_bot('Does it help you remember the word?', remember=False)
|
134 |
st.session_state.is_helpful['ask'] = True
|
135 |
elif a2:
|
136 |
write_bot(f'The first letter is {st.session_state.results["results"][0][0]}.')
|
137 |
+
time.sleep(1)
|
138 |
write_bot('Does it help you remember the word?', remember=False)
|
139 |
st.session_state.is_helpful['ask'] = True
|
140 |
|
|
|
144 |
|
145 |
if st.session_state.actions[-1] == 'cue':
|
146 |
guessed = False
|
147 |
+
write_bot('What do you want to see?', remember=False, blink=False)
|
148 |
b1 = st.button("Next letter", key="1")
|
149 |
b2 = st.button("Next word", key="2")
|
150 |
b3 = st.button("All words", key="3")
|
|
|
155 |
st.session_state.counters["letter_count"] += 1
|
156 |
word_count = st.session_state.counters["word_count"]
|
157 |
letter_count = st.session_state.counters["letter_count"]
|
158 |
+
write_bot(f'The word starts with {st.session_state.results["results"][word_count][:letter_count]}', remember=False)
|
159 |
|
160 |
elif b2:
|
161 |
st.session_state.counters["letter_count"] = 1
|
162 |
letter_count = st.session_state.counters["letter_count"]
|
163 |
st.session_state.counters["word_count"] += 1
|
164 |
word_count = st.session_state.counters["word_count"]
|
165 |
+
write_bot(f'The next word starts with {st.session_state.results["results"][word_count][:letter_count]}', remember=False)
|
166 |
|
167 |
elif b3:
|
168 |
write_bot(f"Here are all my guesses about your word: {st.session_state.results['results_print']}")
|
|
|
184 |
st.markdown(prompt)
|
185 |
#add to history
|
186 |
st.session_state.messages.append({'role': 'user', 'content': prompt})
|
187 |
+
yes = ['yes', 'again', 'Yes', 'sure']
|
188 |
+
if prompt in yes:
|
189 |
write_bot("Please describe your word!")
|
190 |
#if previously we asked to give a prompt
|
191 |
elif (st.session_state.messages[-2]['content'] == "Please describe your word!") & (st.session_state.messages[-1]['content'] != "no"):
|
|
|
368 |
# break
|
369 |
# else:
|
370 |
# st.write("I am happy I could be of help!")
|
371 |
+
|
|
|
|
|
|
|
|
|
|
|
|