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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -17
app.py CHANGED
@@ -28,10 +28,16 @@ if 'last_answer' not in st.session_state:
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
  # Function to toggle acknowledgment visibility
37
  def toggle_acknowledgment():
@@ -71,6 +77,26 @@ button[type="submit"],
71
  background-color: #fafbff !important;
72
  border-color: #c5cae9 !important;
73
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
  /* Input field styling */
75
  div[data-baseweb="input"] {
76
  border: 1px solid #fff0f0 !important;
@@ -121,17 +147,17 @@ div.stInfo {
121
  min-width: 120px;
122
  margin: 0 5px;
123
  }
124
- /* Acknowledgment section styling */
125
  .acknowledgment-container {
126
- background: #ffffff;
127
- border: 1px solid #e1e4f2;
128
  border-radius: 8px;
129
  padding: 15px;
130
  margin: 20px 0;
131
  box-shadow: 0 2px 5px rgba(0,0,0,0.05);
132
  }
133
  .acknowledgment-header {
134
- color: #c0392b;
135
  font-size: 1.3rem;
136
  margin-bottom: 10px;
137
  text-align: center;
@@ -159,9 +185,9 @@ if not st.session_state.initialized:
159
  init_message.info("Hang in there! We are setting the system up for you. 😊")
160
  try:
161
  # Setup authentication and preload heavy resources
162
- setup_all_auth()
163
- load_model() # This uses cached_load_model via alias
164
- cached_load_data_files() # Preload FAISS index, text chunks, and metadata
165
  st.session_state.initialized = True
166
  st.session_state.init_time = time.time()
167
  init_message.success("System initialized successfully!")
@@ -175,13 +201,17 @@ elif st.session_state.init_time is not None:
175
  init_message.empty()
176
  st.session_state.init_time = None
177
 
178
- # Heartfelt acknowledgment section with toggle - improved button text
179
- if st.session_state.show_acknowledgment:
180
- if st.button("Hide Gratitude and Acknowledgments", on_click=toggle_acknowledgment):
181
- pass
182
- else:
183
- if st.button("Show Gratitude and Acknowledgments", on_click=toggle_acknowledgment):
184
- pass
 
 
 
 
185
 
186
  if st.session_state.show_acknowledgment:
187
  st.markdown('<div class="acknowledgment-container">', unsafe_allow_html=True)
@@ -298,7 +328,9 @@ if st.session_state.submit_clicked and st.session_state.last_query:
298
  st.session_state.submit_clicked = False
299
  with st.spinner("Processing your question..."):
300
  try:
301
- result = process_query(st.session_state.last_query, top_k=top_k, word_limit=word_limit)
 
 
302
  st.session_state.last_answer = result # Store result in session state
303
  except Exception as e:
304
  st.session_state.last_answer = {"answer_with_rag": f"Error processing query: {str(e)}", "citations": ""}
 
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
+ # Add page change detection
32
+ if 'page_loaded' not in st.session_state:
33
+ st.session_state.page_loaded = True
34
+ # Reset query state when returning to home page
35
+ st.session_state.last_query = ""
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 - 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"] {
102
  border: 1px solid #fff0f0 !important;
 
147
  min-width: 120px;
148
  margin: 0 5px;
149
  }
150
+ /* Acknowledgment section styling - fully fixed */
151
  .acknowledgment-container {
152
+ background-color: #f8f5ff;
153
+ border: 1px solid #e0d6fe;
154
  border-radius: 8px;
155
  padding: 15px;
156
  margin: 20px 0;
157
  box-shadow: 0 2px 5px rgba(0,0,0,0.05);
158
  }
159
  .acknowledgment-header {
160
+ color: #6a1b9a;
161
  font-size: 1.3rem;
162
  margin-bottom: 10px;
163
  text-align: center;
 
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
  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
  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": ""}