ankanghosh commited on
Commit
aa64522
·
verified ·
1 Parent(s): fa8fb93

Update app.py and rename to App.py

Browse files
Files changed (1) hide show
  1. app.py → App.py +18 -17
app.py → App.py RENAMED
@@ -51,7 +51,7 @@ def navigate_to_sources():
51
  <script>
52
  // Wait for the page to fully load
53
  document.addEventListener('DOMContentLoaded', (event) => {
54
- // This selects the nav item for the Sources page in the sidebar
55
  const sourcesLink = Array.from(document.querySelectorAll('a.css-z5fcl4')).find(el => el.innerText === 'Sources');
56
  if (sourcesLink) {
57
  sourcesLink.click();
@@ -65,16 +65,6 @@ def navigate_to_sources():
65
  # Custom styling (pure CSS)
66
  st.markdown("""
67
  <style>
68
- /* Change sidebar labels: hide default text and add "Home" using the anchor element */
69
- [data-testid="stSidebarNav"] ul li:first-child a {
70
- font-size: 0px;
71
- }
72
- [data-testid="stSidebarNav"] ul li:first-child a::after {
73
- content: "Home";
74
- font-size: 14px;
75
- display: block;
76
- }
77
-
78
  /* Button styling */
79
  .stButton>button {
80
  background-color: #fff0f0 !important;
@@ -87,6 +77,7 @@ st.markdown("""
87
  overflow: hidden !important;
88
  text-overflow: ellipsis !important;
89
  }
 
90
  button[type="submit"],
91
  .stFormSubmit>button,
92
  [data-testid="stFormSubmitButton"]>button {
@@ -275,6 +266,7 @@ if st.session_state.show_acknowledgment:
275
  This application is merely a humble vessel for the ocean of wisdom they have shared with the world. We claim no ownership of these teachings - only profound gratitude for the opportunity to help make them more accessible.
276
  """)
277
 
 
278
  st.markdown('<div class="more-info-link">', unsafe_allow_html=True)
279
  st.write("For detailed information about our sources, please visit the *Sources* page in the navigation menu.")
280
  st.markdown('</div>', unsafe_allow_html=True)
@@ -282,12 +274,13 @@ if st.session_state.show_acknowledgment:
282
 
283
  # Function to handle query selection from the common questions buttons
284
  def set_query(query):
 
285
  if st.session_state.is_processing:
286
  return
287
  st.session_state.last_query = query
288
  st.session_state.submit_clicked = True
289
  st.session_state.is_processing = True
290
- st.experimental_rerun()
291
 
292
  # Function to group questions into rows based on length
293
  def group_buttons(questions, max_chars_per_row=100):
@@ -295,6 +288,7 @@ def group_buttons(questions, max_chars_per_row=100):
295
  current_row = []
296
  current_length = 0
297
  for q in questions:
 
298
  q_length = len(q) + 5
299
  if current_length + q_length > max_chars_per_row and current_row:
300
  rows.append(current_row)
@@ -335,12 +329,14 @@ for row_idx, row in enumerate(question_rows):
335
 
336
  # Function to handle form submission
337
  def handle_form_submit():
 
338
  if st.session_state.is_processing:
339
  return
340
  if st.session_state.query_input and st.session_state.query_input.strip():
341
  st.session_state.last_query = st.session_state.query_input.strip()
342
  st.session_state.submit_clicked = True
343
  st.session_state.is_processing = True
 
344
  st.session_state.form_key += 1
345
 
346
  # Create a form with a dynamic key (to allow resetting)
@@ -367,11 +363,12 @@ if st.session_state.submit_clicked and st.session_state.last_query:
367
  with st.spinner("Processing your question..."):
368
  try:
369
  result = process_query(st.session_state.last_query, top_k=top_k, word_limit=word_limit)
370
- st.session_state.last_answer = result
371
  except Exception as e:
372
  st.session_state.last_answer = {"answer_with_rag": f"Error processing query: {str(e)}", "citations": ""}
 
373
  st.session_state.is_processing = False
374
- st.experimental_rerun()
375
 
376
  # Display the answer if available
377
  if st.session_state.last_answer is not None:
@@ -383,20 +380,24 @@ if st.session_state.last_answer is not None:
383
 
384
  # Add helpful information
385
  st.markdown("---")
 
 
386
  st.markdown("""
387
  ### About this app
388
  This application uses a Retrieval-Augmented Generation (RAG) system to answer questions about spirituality based on insights from Indian spiritual texts. It searches through a database of texts to find relevant passages and generates answers based on those passages.
389
 
390
  **Important to note:**
391
- - This is not a general chatbot. It is specifically designed to answer spiritual questions based on referenced texts.
392
- - You may receive slightly different answers when asking the same question multiple times. This variation reflects the nuanced nature of spiritual teachings across different traditions.
393
- - While you can select a specific number of citations and word limit, the actual response may contain fewer citations based on relevance and available information.
394
  - We apologize for any inconsistencies or misinterpretations that may occur. This application is educational in nature and continuously improving.
395
 
396
  We value your feedback to enhance this application. Please visit the *Contacts* page to share your suggestions or report any issues.
397
 
398
  For more information about the source texts used, see *Sources* in the navigation menu.
399
  """)
 
 
400
  st.markdown('<div class="citation-note">', unsafe_allow_html=True)
401
  st.markdown("""
402
  The answers presented in this application are re-presented summaries of relevant passages from the listed citations.
 
51
  <script>
52
  // Wait for the page to fully load
53
  document.addEventListener('DOMContentLoaded', (event) => {
54
+ // This select the nav item for the Sources page in the sidebar
55
  const sourcesLink = Array.from(document.querySelectorAll('a.css-z5fcl4')).find(el => el.innerText === 'Sources');
56
  if (sourcesLink) {
57
  sourcesLink.click();
 
65
  # Custom styling (pure CSS)
66
  st.markdown("""
67
  <style>
 
 
 
 
 
 
 
 
 
 
68
  /* Button styling */
69
  .stButton>button {
70
  background-color: #fff0f0 !important;
 
77
  overflow: hidden !important;
78
  text-overflow: ellipsis !important;
79
  }
80
+ /* Form submit button specific styling */
81
  button[type="submit"],
82
  .stFormSubmit>button,
83
  [data-testid="stFormSubmitButton"]>button {
 
266
  This application is merely a humble vessel for the ocean of wisdom they have shared with the world. We claim no ownership of these teachings - only profound gratitude for the opportunity to help make them more accessible.
267
  """)
268
 
269
+ # Link to Sources using Streamlit's built-in way
270
  st.markdown('<div class="more-info-link">', unsafe_allow_html=True)
271
  st.write("For detailed information about our sources, please visit the *Sources* page in the navigation menu.")
272
  st.markdown('</div>', unsafe_allow_html=True)
 
274
 
275
  # Function to handle query selection from the common questions buttons
276
  def set_query(query):
277
+ # If already processing, ignore further input
278
  if st.session_state.is_processing:
279
  return
280
  st.session_state.last_query = query
281
  st.session_state.submit_clicked = True
282
  st.session_state.is_processing = True
283
+ st.rerun()
284
 
285
  # Function to group questions into rows based on length
286
  def group_buttons(questions, max_chars_per_row=100):
 
288
  current_row = []
289
  current_length = 0
290
  for q in questions:
291
+ # Add some buffer for button padding/margins
292
  q_length = len(q) + 5
293
  if current_length + q_length > max_chars_per_row and current_row:
294
  rows.append(current_row)
 
329
 
330
  # Function to handle form submission
331
  def handle_form_submit():
332
+ # If already processing, ignore further input
333
  if st.session_state.is_processing:
334
  return
335
  if st.session_state.query_input and st.session_state.query_input.strip():
336
  st.session_state.last_query = st.session_state.query_input.strip()
337
  st.session_state.submit_clicked = True
338
  st.session_state.is_processing = True
339
+ # Increment the form key to force a reset
340
  st.session_state.form_key += 1
341
 
342
  # Create a form with a dynamic key (to allow resetting)
 
363
  with st.spinner("Processing your question..."):
364
  try:
365
  result = process_query(st.session_state.last_query, top_k=top_k, word_limit=word_limit)
366
+ st.session_state.last_answer = result # Store result in session state
367
  except Exception as e:
368
  st.session_state.last_answer = {"answer_with_rag": f"Error processing query: {str(e)}", "citations": ""}
369
+ # Reset debouncing after processing and force a rerun to re-enable buttons
370
  st.session_state.is_processing = False
371
+ st.rerun()
372
 
373
  # Display the answer if available
374
  if st.session_state.last_answer is not None:
 
380
 
381
  # Add helpful information
382
  st.markdown("---")
383
+
384
+ # About section with enhanced explanations
385
  st.markdown("""
386
  ### About this app
387
  This application uses a Retrieval-Augmented Generation (RAG) system to answer questions about spirituality based on insights from Indian spiritual texts. It searches through a database of texts to find relevant passages and generates answers based on those passages.
388
 
389
  **Important to note:**
390
+ - This is not a general chatbot. It is specifically designed to answer spiritual questions based on referenced texts, not to generate historical information or reproduce stories of saints or spiritual leaders.
391
+ - You may receive slightly different answers when asking the same question multiple times. This variation is intentional and reflects the nuanced nature of spiritual teachings across different traditions.
392
+ - While you can select a specific number of citations and word limit, the actual response may contain fewer citations based on relevance and availability of information. Similarly, explanations may be shorter than the selected word limit if the retrieved information is concise.
393
  - We apologize for any inconsistencies or misinterpretations that may occur. This application is educational in nature and continuously improving.
394
 
395
  We value your feedback to enhance this application. Please visit the *Contacts* page to share your suggestions or report any issues.
396
 
397
  For more information about the source texts used, see *Sources* in the navigation menu.
398
  """)
399
+
400
+ # Citation note at the bottom - improved with support message
401
  st.markdown('<div class="citation-note">', unsafe_allow_html=True)
402
  st.markdown("""
403
  The answers presented in this application are re-presented summaries of relevant passages from the listed citations.