ankanghosh commited on
Commit
c5ce3c5
·
verified ·
1 Parent(s): 6f49dc1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -36
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():
@@ -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 - Modified to match Get Answer */
81
- .thank-you-button {
82
- display: flex;
83
- justify-content: center;
84
- margin: 10px 0;
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
- min-width: 150px !important;
 
 
 
95
  }
96
- .thank-you-button > div > button:hover {
97
- background-color: #fafbff !important;
98
- border-color: #c5cae9 !important;
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
- # setup_all_auth()
189
- # load_model() # This uses cached_load_model via alias
190
- # cached_load_data_files() # Preload FAISS index, text chunks, and metadata
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
- # Thank You button that matches Get Answer button styling
205
- st.markdown('<div class="thank-you-button">', unsafe_allow_html=True)
206
- col1, col2, col3 = st.columns([1, 2, 1])
207
- with col2:
208
- if st.session_state.show_acknowledgment:
209
- button_text = "Hide Thank You Note"
210
- else:
211
- button_text = "Show Thank You Note"
212
- if st.button(button_text, key="thank_you_button", use_container_width=True, disabled=st.session_state.is_processing):
213
- toggle_acknowledgment()
214
- st.markdown('</div>', unsafe_allow_html=True)
 
 
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
- # result = process_query(st.session_state.last_query, top_k=top_k, word_limit=word_limit)
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": ""}