Manel commited on
Commit
57af1e0
·
verified ·
1 Parent(s): 8112ebb

update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -16
app.py CHANGED
@@ -160,12 +160,12 @@ def generate_response(query, model, template):
160
  progress_text = "Running Inference. Please wait."
161
  my_bar = st.progress(0, text=progress_text)
162
  # fill those as appropriate
163
- my_bar.progress(0.3, "Loading Model. Please wait.")
164
- time.sleep(1)
165
- my_bar.progress(0.5, "Running RAG. Please wait.")
166
  context = fetch_context(db, model, model_name, query, template)
167
 
168
- my_bar.progress(0.7, "Generating Answer. Please wait.")
169
  response = llm_chain_with_context(model, model_name, query, context, template)
170
 
171
  logger.info(f"Total Execution Time: {time.time() - start_time}")
@@ -249,6 +249,16 @@ if __name__=="__main__":
249
  model_name = "llama" if device=="cpu" else "mistral"
250
  logger.info(f"Running {model_name} model for inference on {device}")
251
 
 
 
 
 
 
 
 
 
 
 
252
  all_templates = { "llama_prompt_template" : """<s>[INST]\n<<SYS>>\nYou are a stoic teacher that provide guidance and advice inspired by Stoic philosophy on navigating life's challenges with resilience and inner peace. Emphasize the importance of focusing on what is within one's control and accepting what is not. Encourage the cultivation of virtue, mindfulness, and self-awareness as tools for achieving eudaimonia. Advocate for enduring hardships with fortitude and maintaining emotional balance in all situations. Your response should reflect Stoic principles of living in accordance with nature and embracing the rational order of the universe.
253
  You should guide the reader towards a fulfilling life focused on virtue rather than external things because living in accordance with virtue leads to eudaimonia or flourishing.\n\n
254
  Give a precise answer to the question based on the context. Don't be verbose.\n\n
@@ -285,21 +295,12 @@ if __name__=="__main__":
285
  Question: {question}\n> Context:\n>>>\n{context}\n>>>\nRelevant parts"""}
286
 
287
 
288
- # Loading and caching db and model
289
- bar = st.progress(0, "Loading Database. Please wait.")
290
- bar.progress(0.1, "Loading Embedding & Database. Please wait.")
291
- db = load_db(device)
292
- bar.progress(0.7, "Loading Model. Please wait.")
293
- model, tokenizer = load_model(model_name)
294
- bar.progress(1.0, "Ready to ask? Go ahead and type your question.")
295
- time.sleep(2)
296
- bar.empty()
297
 
298
-
299
- user_question = st.chat_input('What do you want to ask ..')
300
 
 
301
 
302
- # streamlit chat
303
  if user_question is not None and user_question!="":
304
  with st.chat_message("Human", avatar="🧔🏻"):
305
  st.write(user_question)
 
160
  progress_text = "Running Inference. Please wait."
161
  my_bar = st.progress(0, text=progress_text)
162
  # fill those as appropriate
163
+ my_bar.progress(0.1, "Loading Model. Please wait.")
164
+ time.sleep(2)
165
+ my_bar.progress(0.4, "Running RAG. Please wait.")
166
  context = fetch_context(db, model, model_name, query, template)
167
 
168
+ my_bar.progress(0.6, "Generating Answer. Please wait.")
169
  response = llm_chain_with_context(model, model_name, query, context, template)
170
 
171
  logger.info(f"Total Execution Time: {time.time() - start_time}")
 
249
  model_name = "llama" if device=="cpu" else "mistral"
250
  logger.info(f"Running {model_name} model for inference on {device}")
251
 
252
+ # Loading and caching db and model
253
+ bar = st.progress(0, "Loading Database. Please wait.")
254
+ bar.progress(0.05, "Loading Embedding & Database. Please wait.")
255
+ db = load_db(device)
256
+ bar.progress(0.5, "Loading Model. Please wait.")
257
+ model, tokenizer = load_model(model_name)
258
+ bar.progress(0.9, "Ready to ask? Go ahead and type your question.")
259
+ time.sleep(2)
260
+ bar.empty()
261
+
262
  all_templates = { "llama_prompt_template" : """<s>[INST]\n<<SYS>>\nYou are a stoic teacher that provide guidance and advice inspired by Stoic philosophy on navigating life's challenges with resilience and inner peace. Emphasize the importance of focusing on what is within one's control and accepting what is not. Encourage the cultivation of virtue, mindfulness, and self-awareness as tools for achieving eudaimonia. Advocate for enduring hardships with fortitude and maintaining emotional balance in all situations. Your response should reflect Stoic principles of living in accordance with nature and embracing the rational order of the universe.
263
  You should guide the reader towards a fulfilling life focused on virtue rather than external things because living in accordance with virtue leads to eudaimonia or flourishing.\n\n
264
  Give a precise answer to the question based on the context. Don't be verbose.\n\n
 
295
  Question: {question}\n> Context:\n>>>\n{context}\n>>>\nRelevant parts"""}
296
 
297
 
298
+
 
 
 
 
 
 
 
 
299
 
300
+ # streamlit chat
 
301
 
302
+ user_question = st.chat_input('What do you want to ask ..')
303
 
 
304
  if user_question is not None and user_question!="":
305
  with st.chat_message("Human", avatar="🧔🏻"):
306
  st.write(user_question)