Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,7 +2,7 @@ import streamlit as st
|
|
2 |
import time
|
3 |
|
4 |
# FIRST: Set page config before ANY other Streamlit command
|
5 |
-
st.set_page_config(page_title="Spirituality Q&A")
|
6 |
|
7 |
# Initialize ALL session state variables right at the beginning
|
8 |
if 'initialized' not in st.session_state:
|
@@ -25,33 +25,14 @@ if 'is_processing' not in st.session_state:
|
|
25 |
# Store the answer so that it persists on screen
|
26 |
if 'last_answer' not in st.session_state:
|
27 |
st.session_state.last_answer = None
|
|
|
|
|
|
|
28 |
|
29 |
# THEN: Import your modules
|
30 |
from rag_engine import process_query, load_model, cached_load_data_files
|
31 |
from utils import setup_all_auth
|
32 |
|
33 |
-
# Preload resources during initialization
|
34 |
-
init_message = st.empty()
|
35 |
-
if not st.session_state.initialized:
|
36 |
-
init_message.info("Hang in there! We are setting the system up for you. 😊")
|
37 |
-
try:
|
38 |
-
# Setup authentication and preload heavy resources
|
39 |
-
setup_all_auth()
|
40 |
-
load_model() # This uses cached_load_model via alias
|
41 |
-
cached_load_data_files() # Preload FAISS index, text chunks, and metadata
|
42 |
-
st.session_state.initialized = True
|
43 |
-
st.session_state.init_time = time.time()
|
44 |
-
init_message.success("System initialized successfully!")
|
45 |
-
time.sleep(2)
|
46 |
-
init_message.empty()
|
47 |
-
except Exception as e:
|
48 |
-
init_message.error(f"Error initializing: {str(e)}")
|
49 |
-
elif st.session_state.init_time is not None:
|
50 |
-
elapsed_time = time.time() - st.session_state.init_time
|
51 |
-
if elapsed_time >= 2.0:
|
52 |
-
init_message.empty()
|
53 |
-
st.session_state.init_time = None
|
54 |
-
|
55 |
# Custom styling (pure CSS)
|
56 |
st.markdown("""
|
57 |
<style>
|
@@ -136,10 +117,82 @@ div.stInfo {
|
|
136 |
min-width: 120px;
|
137 |
margin: 0 5px;
|
138 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
139 |
</style>
|
140 |
<div class="main-title">Spirituality Q&A</div>
|
141 |
""", unsafe_allow_html=True)
|
142 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
143 |
# Function to handle query selection from the common questions buttons
|
144 |
def set_query(query):
|
145 |
# If already processing, ignore further input
|
@@ -250,6 +303,9 @@ if st.session_state.last_answer is not None:
|
|
250 |
st.markdown("---")
|
251 |
st.markdown("""
|
252 |
### About this app
|
253 |
-
This application uses a Retrieval-Augmented Generation (RAG) system to answer questions about
|
254 |
It searches through a database of texts to find relevant passages and generates answers based on those passages.
|
|
|
|
|
|
|
255 |
""")
|
|
|
2 |
import time
|
3 |
|
4 |
# FIRST: Set page config before ANY other Streamlit command
|
5 |
+
st.set_page_config(page_title="Spirituality Q&A", page_icon="🕉️")
|
6 |
|
7 |
# Initialize ALL session state variables right at the beginning
|
8 |
if 'initialized' not in st.session_state:
|
|
|
25 |
# Store the answer so that it persists on screen
|
26 |
if 'last_answer' not in st.session_state:
|
27 |
st.session_state.last_answer = None
|
28 |
+
# Add new session state for showing/hiding acknowledgment
|
29 |
+
if 'show_acknowledgment' not in st.session_state:
|
30 |
+
st.session_state.show_acknowledgment = False
|
31 |
|
32 |
# THEN: Import your modules
|
33 |
from rag_engine import process_query, load_model, cached_load_data_files
|
34 |
from utils import setup_all_auth
|
35 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
36 |
# Custom styling (pure CSS)
|
37 |
st.markdown("""
|
38 |
<style>
|
|
|
117 |
min-width: 120px;
|
118 |
margin: 0 5px;
|
119 |
}
|
120 |
+
/* Acknowledgment section styling */
|
121 |
+
.acknowledgment-container {
|
122 |
+
background-color: #fff0f0;
|
123 |
+
border: 1px solid #e1e4f2;
|
124 |
+
border-radius: 8px;
|
125 |
+
padding: 15px;
|
126 |
+
margin: 20px 0;
|
127 |
+
box-shadow: 0 2px 5px rgba(0,0,0,0.05);
|
128 |
+
}
|
129 |
+
.acknowledgment-header {
|
130 |
+
color: #c0392b;
|
131 |
+
font-size: 1.3rem;
|
132 |
+
margin-bottom: 10px;
|
133 |
+
text-align: center;
|
134 |
+
}
|
135 |
+
.more-info-link {
|
136 |
+
text-align: center;
|
137 |
+
margin-top: 10px;
|
138 |
+
font-style: italic;
|
139 |
+
}
|
140 |
</style>
|
141 |
<div class="main-title">Spirituality Q&A</div>
|
142 |
""", unsafe_allow_html=True)
|
143 |
|
144 |
+
# Preload resources during initialization
|
145 |
+
init_message = st.empty()
|
146 |
+
if not st.session_state.initialized:
|
147 |
+
init_message.info("Hang in there! We are setting the system up for you. 😊")
|
148 |
+
try:
|
149 |
+
# Setup authentication and preload heavy resources
|
150 |
+
setup_all_auth()
|
151 |
+
load_model() # This uses cached_load_model via alias
|
152 |
+
cached_load_data_files() # Preload FAISS index, text chunks, and metadata
|
153 |
+
st.session_state.initialized = True
|
154 |
+
st.session_state.init_time = time.time()
|
155 |
+
init_message.success("System initialized successfully!")
|
156 |
+
time.sleep(2)
|
157 |
+
init_message.empty()
|
158 |
+
except Exception as e:
|
159 |
+
init_message.error(f"Error initializing: {str(e)}")
|
160 |
+
elif st.session_state.init_time is not None:
|
161 |
+
elapsed_time = time.time() - st.session_state.init_time
|
162 |
+
if elapsed_time >= 2.0:
|
163 |
+
init_message.empty()
|
164 |
+
st.session_state.init_time = None
|
165 |
+
|
166 |
+
# Heartfelt acknowledgment section with toggle
|
167 |
+
acknowledgment_button = st.button("❤️ Show Gratitude & Acknowledgments" if not st.session_state.show_acknowledgment else "❤️ Hide Acknowledgments")
|
168 |
+
if acknowledgment_button:
|
169 |
+
st.session_state.show_acknowledgment = not st.session_state.show_acknowledgment
|
170 |
+
|
171 |
+
if st.session_state.show_acknowledgment:
|
172 |
+
st.markdown('<div class="acknowledgment-container">', unsafe_allow_html=True)
|
173 |
+
st.markdown('<div class="acknowledgment-header">A Heartfelt Thank You</div>', unsafe_allow_html=True)
|
174 |
+
st.markdown("""
|
175 |
+
With deepest reverence, we express our gratitude to:
|
176 |
+
|
177 |
+
**The Saints and Spiritual Masters** whose timeless wisdom illuminates this application. From ancient sages to modern masters,
|
178 |
+
their selfless dedication to uplift humanity through spiritual knowledge continues to guide seekers on the path.
|
179 |
+
|
180 |
+
**The Sacred Texts** that have preserved the eternal truths across millennia, offering light in times of darkness
|
181 |
+
and clarity in times of confusion.
|
182 |
+
|
183 |
+
**The Publishers** who have diligently preserved and disseminated these precious teachings, making them accessible
|
184 |
+
to spiritual aspirants worldwide. Their work ensures these wisdom traditions endure for future generations.
|
185 |
+
|
186 |
+
**The Authors** who have dedicated their lives to interpreting and explaining complex spiritual concepts,
|
187 |
+
making them accessible to modern readers.
|
188 |
+
|
189 |
+
This application is merely a humble vessel for the ocean of wisdom they have shared with the world. We claim no
|
190 |
+
ownership of these teachings—only profound gratitude for the opportunity to help make them more accessible.
|
191 |
+
""")
|
192 |
+
|
193 |
+
st.markdown('<div class="more-info-link">For detailed information about our sources, please visit the "Sources" page in the navigation menu.</div>', unsafe_allow_html=True)
|
194 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
195 |
+
|
196 |
# Function to handle query selection from the common questions buttons
|
197 |
def set_query(query):
|
198 |
# If already processing, ignore further input
|
|
|
303 |
st.markdown("---")
|
304 |
st.markdown("""
|
305 |
### About this app
|
306 |
+
This application uses a Retrieval-Augmented Generation (RAG) system to answer questions about Indian spiritual texts.
|
307 |
It searches through a database of texts to find relevant passages and generates answers based on those passages.
|
308 |
+
|
309 |
+
For detailed information about the sources used in this application, including saints, sacred texts, and publishers,
|
310 |
+
please visit the "Sources" page in the navigation menu.
|
311 |
""")
|