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 |
-
|
40 |
-
|
41 |
|
42 |
# Function to toggle acknowledgment visibility
|
43 |
def toggle_acknowledgment():
|
@@ -77,25 +77,20 @@ button[type="submit"],
|
|
77 |
background-color: #fafbff !important;
|
78 |
border-color: #c5cae9 !important;
|
79 |
}
|
80 |
-
/* Special styling for thank you button
|
81 |
-
.thank-you-button {
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
}
|
86 |
-
.thank-you-button > div > button {
|
87 |
-
background-color: #fff0f0 !important;
|
88 |
-
color: #3f51b5 !important;
|
89 |
-
border: 1px solid #e1e4f2 !important;
|
90 |
-
border-radius: 8px !important;
|
91 |
-
padding: 8px 16px !important;
|
92 |
-
box-shadow: 0 1px 2px rgba(0,0,0,0.03) !important;
|
93 |
font-weight: normal !important;
|
94 |
-
|
|
|
|
|
|
|
95 |
}
|
96 |
-
.thank-you-button >
|
97 |
-
background-color: #
|
98 |
-
|
99 |
}
|
100 |
/* Input field styling */
|
101 |
div[data-baseweb="input"] {
|
@@ -185,9 +180,9 @@ if not st.session_state.initialized:
|
|
185 |
init_message.info("Hang in there! We are setting the system up for you. 😊")
|
186 |
try:
|
187 |
# Setup authentication and preload heavy resources
|
188 |
-
|
189 |
-
|
190 |
-
|
191 |
st.session_state.initialized = True
|
192 |
st.session_state.init_time = time.time()
|
193 |
init_message.success("System initialized successfully!")
|
@@ -201,17 +196,19 @@ elif st.session_state.init_time is not None:
|
|
201 |
init_message.empty()
|
202 |
st.session_state.init_time = None
|
203 |
|
204 |
-
#
|
205 |
-
st.
|
206 |
-
|
207 |
-
|
208 |
-
if st.session_state.
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
st.
|
|
|
|
|
215 |
|
216 |
if st.session_state.show_acknowledgment:
|
217 |
st.markdown('<div class="acknowledgment-container">', unsafe_allow_html=True)
|
@@ -328,9 +325,7 @@ if st.session_state.submit_clicked and st.session_state.last_query:
|
|
328 |
st.session_state.submit_clicked = False
|
329 |
with st.spinner("Processing your question..."):
|
330 |
try:
|
331 |
-
|
332 |
-
# Simulated result for testing
|
333 |
-
result = {"answer_with_rag": "This is a sample answer.", "citations": "Sample citation 1\nSample citation 2"}
|
334 |
st.session_state.last_answer = result # Store result in session state
|
335 |
except Exception as e:
|
336 |
st.session_state.last_answer = {"answer_with_rag": f"Error processing query: {str(e)}", "citations": ""}
|
|
|
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():
|
|
|
77 |
background-color: #fafbff !important;
|
78 |
border-color: #c5cae9 !important;
|
79 |
}
|
80 |
+
/* Special styling for thank you button */
|
81 |
+
.thank-you-button > button {
|
82 |
+
background-color: #f8e6ff !important;
|
83 |
+
border-radius: 8px !important;
|
84 |
+
padding: 10px 20px !important;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
85 |
font-weight: normal !important;
|
86 |
+
box-shadow: 0 2px 4px rgba(0,0,0,0.1) !important;
|
87 |
+
transition: all 0.3s ease !important;
|
88 |
+
border: 1px solid #d8b9ff !important;
|
89 |
+
color: #6a1b9a !important;
|
90 |
}
|
91 |
+
.thank-you-button > button:hover {
|
92 |
+
background-color: #f0d6ff !important;
|
93 |
+
transform: translateY(-1px) !important;
|
94 |
}
|
95 |
/* Input field styling */
|
96 |
div[data-baseweb="input"] {
|
|
|
180 |
init_message.info("Hang in there! We are setting the system up for you. 😊")
|
181 |
try:
|
182 |
# Setup authentication and preload heavy resources
|
183 |
+
setup_all_auth()
|
184 |
+
load_model() # This uses cached_load_model via alias
|
185 |
+
cached_load_data_files() # Preload FAISS index, text chunks, and metadata
|
186 |
st.session_state.initialized = True
|
187 |
st.session_state.init_time = time.time()
|
188 |
init_message.success("System initialized successfully!")
|
|
|
196 |
init_message.empty()
|
197 |
st.session_state.init_time = None
|
198 |
|
199 |
+
# Heartfelt acknowledgment section with toggle - improved button text and disabled during processing
|
200 |
+
if st.session_state.show_acknowledgment:
|
201 |
+
st.markdown('<div class="thank-you-button">', unsafe_allow_html=True)
|
202 |
+
# Debouncing applied: disabled if processing
|
203 |
+
if st.button("Hide Thank You Note", on_click=toggle_acknowledgment, disabled=st.session_state.is_processing):
|
204 |
+
pass
|
205 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
206 |
+
else:
|
207 |
+
st.markdown('<div class="thank-you-button">', unsafe_allow_html=True)
|
208 |
+
# Debouncing applied: disabled if processing
|
209 |
+
if st.button("Show Thank You Note", on_click=toggle_acknowledgment, disabled=st.session_state.is_processing):
|
210 |
+
pass
|
211 |
+
st.markdown('</div>', unsafe_allow_html=True)
|
212 |
|
213 |
if st.session_state.show_acknowledgment:
|
214 |
st.markdown('<div class="acknowledgment-container">', unsafe_allow_html=True)
|
|
|
325 |
st.session_state.submit_clicked = False
|
326 |
with st.spinner("Processing your question..."):
|
327 |
try:
|
328 |
+
result = process_query(st.session_state.last_query, top_k=top_k, word_limit=word_limit)
|
|
|
|
|
329 |
st.session_state.last_answer = result # Store result in session state
|
330 |
except Exception as e:
|
331 |
st.session_state.last_answer = {"answer_with_rag": f"Error processing query: {str(e)}", "citations": ""}
|