Upload app.py
Browse files
app.py
CHANGED
@@ -202,11 +202,20 @@ def set_as_background_img(png_file):
|
|
202 |
|
203 |
|
204 |
def stream_to_screen(response):
|
205 |
-
print(response)
|
206 |
for word in response.split():
|
207 |
yield word + " "
|
208 |
time.sleep(0.15)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
209 |
|
|
|
|
|
|
|
210 |
|
211 |
if __name__=="__main__":
|
212 |
|
@@ -275,21 +284,15 @@ if __name__=="__main__":
|
|
275 |
Question: {question}\n> Context:\n>>>\n{context}\n>>>\nRelevant parts"""}
|
276 |
|
277 |
# Loading and caching db and model
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
Here are a few practical steps to cultivate mindfulness in accordance with Stoic principles:
|
288 |
-
|
289 |
-
1. Observe your thoughts and emotions without judgment. As the ancient Stoic philosopher Epictetus once said, "The things within our control, are those over which we have the power of decision; and those things are external to us, over which we have no control." Recognize that which lies within thy control and accept what is not.
|
290 |
-
|
291 |
-
2. Practice meditation and inner reflection. Meditation allows thee to quiet the mind and listen to the whispers of thy inner being. Observe thy thoughts and emotions with detachment, as if observing a passing cloud. Through this practice, thou shalt become attuned to the ebb and flow of life, ever-aware of the present moment.
|
292 |
-
"""
|
293 |
|
294 |
user_question = st.chat_input('What do you want to ask ..')
|
295 |
|
@@ -299,10 +302,10 @@ if __name__=="__main__":
|
|
299 |
with st.chat_message("Human", avatar="π§π»"):
|
300 |
st.write(user_question)
|
301 |
|
302 |
-
|
303 |
|
304 |
with st.chat_message("AI", avatar="ποΈ"):
|
305 |
-
st.
|
306 |
-
#st.
|
307 |
|
308 |
|
|
|
202 |
|
203 |
|
204 |
def stream_to_screen(response):
|
|
|
205 |
for word in response.split():
|
206 |
yield word + " "
|
207 |
time.sleep(0.15)
|
208 |
+
|
209 |
+
def post_process(response):
|
210 |
+
"""Remove if last sentence is unfinished"""
|
211 |
+
if response[-1] != '.':
|
212 |
+
sentences = response.split('.')
|
213 |
+
del sentences[-1]
|
214 |
+
return '.'.join(sentences) + '.'
|
215 |
|
216 |
+
return response
|
217 |
+
|
218 |
+
|
219 |
|
220 |
if __name__=="__main__":
|
221 |
|
|
|
284 |
Question: {question}\n> Context:\n>>>\n{context}\n>>>\nRelevant parts"""}
|
285 |
|
286 |
# Loading and caching db and model
|
287 |
+
bar = st.progress(0, "Loading Database. Please wait.")
|
288 |
+
bar.progress(0.1, "Loading Embedding & Database. Please wait.")
|
289 |
+
db = load_db(device)
|
290 |
+
bar.progress(0.7, "Loading Model. Please wait.")
|
291 |
+
model, tokenizer = load_model(model_name)
|
292 |
+
bar.progress(1.0, "Now you can type your question.")
|
293 |
+
time.sleep(1)
|
294 |
+
bar.empty()
|
295 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
296 |
|
297 |
user_question = st.chat_input('What do you want to ask ..')
|
298 |
|
|
|
302 |
with st.chat_message("Human", avatar="π§π»"):
|
303 |
st.write(user_question)
|
304 |
|
305 |
+
response = generate_response(user_question, model, all_templates)
|
306 |
|
307 |
with st.chat_message("AI", avatar="ποΈ"):
|
308 |
+
st.write(response)
|
309 |
+
#st.write_stream(stream_to_screen(response))
|
310 |
|
311 |
|