Spaces:
Running
Running
Update app,py
Browse files
app.py
CHANGED
@@ -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
|
55 |
const sourcesLink = Array.from(document.querySelectorAll('a.css-z5fcl4')).find(el => el.innerText === 'Sources');
|
56 |
if (sourcesLink) {
|
57 |
sourcesLink.click();
|
@@ -65,13 +65,14 @@ def navigate_to_sources():
|
|
65 |
# Custom styling (pure CSS)
|
66 |
st.markdown("""
|
67 |
<style>
|
68 |
-
/* Change sidebar labels */
|
69 |
-
[data-testid="stSidebarNav"] ul li:first-child
|
70 |
font-size: 0px;
|
71 |
}
|
72 |
-
[data-testid="stSidebarNav"] ul li:first-child
|
73 |
content: "Home";
|
74 |
font-size: 14px;
|
|
|
75 |
}
|
76 |
|
77 |
/* Button styling */
|
@@ -86,7 +87,6 @@ st.markdown("""
|
|
86 |
overflow: hidden !important;
|
87 |
text-overflow: ellipsis !important;
|
88 |
}
|
89 |
-
/* Form submit button specific styling */
|
90 |
button[type="submit"],
|
91 |
.stFormSubmit>button,
|
92 |
[data-testid="stFormSubmitButton"]>button {
|
@@ -275,7 +275,6 @@ 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 |
-
# Link to Sources using Streamlit's built-in way
|
279 |
st.markdown('<div class="more-info-link">', unsafe_allow_html=True)
|
280 |
st.write("For detailed information about our sources, please visit the *Sources* page in the navigation menu.")
|
281 |
st.markdown('</div>', unsafe_allow_html=True)
|
@@ -283,7 +282,6 @@ if st.session_state.show_acknowledgment:
|
|
283 |
|
284 |
# Function to handle query selection from the common questions buttons
|
285 |
def set_query(query):
|
286 |
-
# If already processing, ignore further input
|
287 |
if st.session_state.is_processing:
|
288 |
return
|
289 |
st.session_state.last_query = query
|
@@ -297,7 +295,6 @@ def group_buttons(questions, max_chars_per_row=100):
|
|
297 |
current_row = []
|
298 |
current_length = 0
|
299 |
for q in questions:
|
300 |
-
# Add some buffer for button padding/margins
|
301 |
q_length = len(q) + 5
|
302 |
if current_length + q_length > max_chars_per_row and current_row:
|
303 |
rows.append(current_row)
|
@@ -338,14 +335,12 @@ for row_idx, row in enumerate(question_rows):
|
|
338 |
|
339 |
# Function to handle form submission
|
340 |
def handle_form_submit():
|
341 |
-
# If already processing, ignore further input
|
342 |
if st.session_state.is_processing:
|
343 |
return
|
344 |
if st.session_state.query_input and st.session_state.query_input.strip():
|
345 |
st.session_state.last_query = st.session_state.query_input.strip()
|
346 |
st.session_state.submit_clicked = True
|
347 |
st.session_state.is_processing = True
|
348 |
-
# Increment the form key to force a reset
|
349 |
st.session_state.form_key += 1
|
350 |
|
351 |
# Create a form with a dynamic key (to allow resetting)
|
@@ -372,10 +367,9 @@ if st.session_state.submit_clicked and st.session_state.last_query:
|
|
372 |
with st.spinner("Processing your question..."):
|
373 |
try:
|
374 |
result = process_query(st.session_state.last_query, top_k=top_k, word_limit=word_limit)
|
375 |
-
st.session_state.last_answer = result
|
376 |
except Exception as e:
|
377 |
st.session_state.last_answer = {"answer_with_rag": f"Error processing query: {str(e)}", "citations": ""}
|
378 |
-
# Reset debouncing after processing and force a rerun to re-enable buttons
|
379 |
st.session_state.is_processing = False
|
380 |
st.experimental_rerun()
|
381 |
|
@@ -389,24 +383,20 @@ if st.session_state.last_answer is not None:
|
|
389 |
|
390 |
# Add helpful information
|
391 |
st.markdown("---")
|
392 |
-
|
393 |
-
# About section with enhanced explanations
|
394 |
st.markdown("""
|
395 |
### About this app
|
396 |
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.
|
397 |
|
398 |
**Important to note:**
|
399 |
-
- This is not a general chatbot. It is specifically designed to answer spiritual questions based on referenced texts
|
400 |
-
- You may receive slightly different answers when asking the same question multiple times. This variation
|
401 |
-
- While you can select a specific number of citations and word limit, the actual response may contain fewer citations based on relevance and
|
402 |
- We apologize for any inconsistencies or misinterpretations that may occur. This application is educational in nature and continuously improving.
|
403 |
|
404 |
We value your feedback to enhance this application. Please visit the *Contacts* page to share your suggestions or report any issues.
|
405 |
|
406 |
For more information about the source texts used, see *Sources* in the navigation menu.
|
407 |
""")
|
408 |
-
|
409 |
-
# Citation note at the bottom - improved with support message
|
410 |
st.markdown('<div class="citation-note">', unsafe_allow_html=True)
|
411 |
st.markdown("""
|
412 |
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 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 |
# 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 */
|
|
|
87 |
overflow: hidden !important;
|
88 |
text-overflow: ellipsis !important;
|
89 |
}
|
|
|
90 |
button[type="submit"],
|
91 |
.stFormSubmit>button,
|
92 |
[data-testid="stFormSubmitButton"]>button {
|
|
|
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 |
|
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
|
|
|
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 |
|
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 |
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 |
|
|
|
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.
|