Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -36,8 +36,8 @@ if 'page_loaded' not in st.session_state:
|
|
36 |
st.session_state.last_answer = None
|
37 |
|
38 |
# THEN: Import your modules
|
39 |
-
from rag_engine import process_query, load_model, cached_load_data_files
|
40 |
-
from utils import setup_all_auth
|
41 |
|
42 |
# Function to toggle acknowledgment visibility
|
43 |
def toggle_acknowledgment():
|
@@ -178,6 +178,15 @@ div.stInfo {
|
|
178 |
margin: 0 auto;
|
179 |
width: 100%;
|
180 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
181 |
</style>
|
182 |
<div class="main-title">Spirituality Q&A</div>
|
183 |
""", unsafe_allow_html=True)
|
@@ -202,9 +211,9 @@ if not st.session_state.initialized:
|
|
202 |
init_message.info("Hang in there! We are setting the system up for you. 😊")
|
203 |
try:
|
204 |
# Setup authentication and preload heavy resources
|
205 |
-
setup_all_auth()
|
206 |
-
load_model() # This uses cached_load_model via alias
|
207 |
-
cached_load_data_files() # Preload FAISS index, text chunks, and metadata
|
208 |
st.session_state.initialized = True
|
209 |
st.session_state.init_time = time.time()
|
210 |
init_message.success("System initialized successfully!")
|
@@ -222,25 +231,28 @@ if st.session_state.show_acknowledgment:
|
|
222 |
st.markdown('<div class="acknowledgment-container">', unsafe_allow_html=True)
|
223 |
st.markdown('<div class="acknowledgment-header">A Heartfelt Thank You</div>', unsafe_allow_html=True)
|
224 |
st.markdown("""
|
225 |
-
|
|
|
|
|
226 |
|
227 |
-
**The Saints and Spiritual Masters** whose timeless wisdom illuminates this application. From ancient sages to modern masters,
|
228 |
-
their selfless dedication to uplift humanity through spiritual knowledge continues to guide seekers on the path.
|
229 |
|
230 |
-
**The Sacred Texts** that have preserved the eternal truths across millennia, offering light in times of darkness
|
231 |
-
and clarity in times of confusion.
|
232 |
|
233 |
-
**The Publishers** who have diligently preserved and disseminated these precious teachings, making them accessible
|
234 |
-
to spiritual aspirants worldwide. Their work ensures these wisdom traditions endure for future generations.
|
235 |
|
236 |
-
**The Authors** who have dedicated their lives to interpreting and explaining complex spiritual concepts,
|
237 |
-
making them accessible to modern readers.
|
238 |
|
239 |
-
This application is merely a humble vessel for the ocean of wisdom they have shared with the world. We claim no
|
240 |
-
ownership of these teachings—only profound gratitude for the opportunity to help make them more accessible.
|
241 |
""")
|
242 |
|
243 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
244 |
st.markdown('</div>', unsafe_allow_html=True)
|
245 |
|
246 |
# Function to handle query selection from the common questions buttons
|
@@ -333,7 +345,7 @@ if st.session_state.submit_clicked and st.session_state.last_query:
|
|
333 |
st.session_state.submit_clicked = False
|
334 |
with st.spinner("Processing your question..."):
|
335 |
try:
|
336 |
-
result = process_query(st.session_state.last_query, top_k=top_k, word_limit=word_limit)
|
337 |
st.session_state.last_answer = result # Store result in session state
|
338 |
except Exception as e:
|
339 |
st.session_state.last_answer = {"answer_with_rag": f"Error processing query: {str(e)}", "citations": ""}
|
@@ -351,14 +363,15 @@ if st.session_state.last_answer is not None:
|
|
351 |
|
352 |
# Add helpful information
|
353 |
st.markdown("---")
|
354 |
-
st.markdown("""
|
355 |
-
### About this app
|
356 |
-
This application uses a Retrieval-Augmented Generation (RAG) system to answer questions about Indian spiritual texts.
|
357 |
-
It searches through a database of texts to find relevant passages and generates answers based on those passages.
|
358 |
|
359 |
-
|
360 |
-
|
361 |
-
|
|
|
|
|
|
|
|
|
|
|
362 |
|
363 |
# Citation note at the bottom - improved with support message
|
364 |
st.markdown('<div class="citation-note">', unsafe_allow_html=True)
|
@@ -366,6 +379,6 @@ st.markdown("""
|
|
366 |
The answers presented in this application are re-presented summaries of relevant passages from the listed citations.
|
367 |
For the original works in their complete and authentic form, users are respectfully encouraged to purchase
|
368 |
the original print or digital works from their respective publishers. Your purchase helps support these publishers
|
369 |
-
who have brought such important spiritual works
|
370 |
""")
|
371 |
st.markdown('</div>', unsafe_allow_html=True)
|
|
|
36 |
st.session_state.last_answer = None
|
37 |
|
38 |
# THEN: Import your modules
|
39 |
+
# from rag_engine import process_query, load_model, cached_load_data_files
|
40 |
+
# from utils import setup_all_auth
|
41 |
|
42 |
# Function to toggle acknowledgment visibility
|
43 |
def toggle_acknowledgment():
|
|
|
178 |
margin: 0 auto;
|
179 |
width: 100%;
|
180 |
}
|
181 |
+
/* Source link styling */
|
182 |
+
.source-link {
|
183 |
+
color: #3f51b5;
|
184 |
+
text-decoration: underline;
|
185 |
+
cursor: pointer;
|
186 |
+
}
|
187 |
+
.source-link:hover {
|
188 |
+
color: #6a1b9a;
|
189 |
+
}
|
190 |
</style>
|
191 |
<div class="main-title">Spirituality Q&A</div>
|
192 |
""", unsafe_allow_html=True)
|
|
|
211 |
init_message.info("Hang in there! We are setting the system up for you. 😊")
|
212 |
try:
|
213 |
# Setup authentication and preload heavy resources
|
214 |
+
# setup_all_auth()
|
215 |
+
# load_model() # This uses cached_load_model via alias
|
216 |
+
# cached_load_data_files() # Preload FAISS index, text chunks, and metadata
|
217 |
st.session_state.initialized = True
|
218 |
st.session_state.init_time = time.time()
|
219 |
init_message.success("System initialized successfully!")
|
|
|
231 |
st.markdown('<div class="acknowledgment-container">', unsafe_allow_html=True)
|
232 |
st.markdown('<div class="acknowledgment-header">A Heartfelt Thank You</div>', unsafe_allow_html=True)
|
233 |
st.markdown("""
|
234 |
+
It is believed that one cannot be in a spiritual path without the will of the Lord. One need not be a believer or a non-believer, merely proceeding to thoughtlessness and observation is enough to evolve and shape perspectives. But that happens through Grace. It is believed that without the will of the Lord, one cannot be blessed by real Saints, and without the will of the Saints, one cannot get close to them or God.
|
235 |
+
|
236 |
+
Therefore, with deepest reverence, we express our gratitude to:
|
237 |
|
238 |
+
**The Saints and Spiritual Masters** whose timeless wisdom illuminates this application. From ancient sages to modern masters, their selfless dedication to uplift humanity through selfless love and spiritual knowledge continues to guide seekers on the path.
|
|
|
239 |
|
240 |
+
**The Sacred Texts** that have preserved the eternal truths across millennia, offering light in times of darkness and clarity in times of confusion.
|
|
|
241 |
|
242 |
+
**The Publishers** who have diligently preserved and disseminated these precious teachings, making them accessible to spiritual aspirants worldwide. Their work ensures these wisdom traditions endure for future generations.
|
|
|
243 |
|
244 |
+
**The Authors** who have dedicated their lives to interpreting and explaining complex spiritual concepts, making them accessible to modern readers.
|
|
|
245 |
|
246 |
+
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.
|
|
|
247 |
""")
|
248 |
|
249 |
+
# Create a source link that works with Streamlit navigation
|
250 |
+
sources_link = """
|
251 |
+
<div class="more-info-link">
|
252 |
+
For detailed information about our sources, please visit the <span class="source-link" onclick="parent.window.location.href='Sources'">Sources</span> page in the navigation menu.
|
253 |
+
</div>
|
254 |
+
"""
|
255 |
+
st.markdown(sources_link, unsafe_allow_html=True)
|
256 |
st.markdown('</div>', unsafe_allow_html=True)
|
257 |
|
258 |
# Function to handle query selection from the common questions buttons
|
|
|
345 |
st.session_state.submit_clicked = False
|
346 |
with st.spinner("Processing your question..."):
|
347 |
try:
|
348 |
+
# result = process_query(st.session_state.last_query, top_k=top_k, word_limit=word_limit)
|
349 |
st.session_state.last_answer = result # Store result in session state
|
350 |
except Exception as e:
|
351 |
st.session_state.last_answer = {"answer_with_rag": f"Error processing query: {str(e)}", "citations": ""}
|
|
|
363 |
|
364 |
# Add helpful information
|
365 |
st.markdown("---")
|
|
|
|
|
|
|
|
|
366 |
|
367 |
+
# About section with working sources link
|
368 |
+
about_text = """
|
369 |
+
### About this app
|
370 |
+
This application uses a Retrieval-Augmented Generation (RAG) system to answer questions about spirituality based on insights from Indian spiritual texts.
|
371 |
+
It searches through a database of texts to find relevant passages and generates answers based on those passages.
|
372 |
+
For more information about the texts, see <span class="source-link" onclick="parent.window.location.href='Sources'">sources</span>.
|
373 |
+
"""
|
374 |
+
st.markdown(about_text, unsafe_allow_html=True)
|
375 |
|
376 |
# Citation note at the bottom - improved with support message
|
377 |
st.markdown('<div class="citation-note">', unsafe_allow_html=True)
|
|
|
379 |
The answers presented in this application are re-presented summaries of relevant passages from the listed citations.
|
380 |
For the original works in their complete and authentic form, users are respectfully encouraged to purchase
|
381 |
the original print or digital works from their respective publishers. Your purchase helps support these publishers
|
382 |
+
who have brought the world closer to such important spiritual works.
|
383 |
""")
|
384 |
st.markdown('</div>', unsafe_allow_html=True)
|