ankanghosh commited on
Commit
72c917c
·
verified ·
1 Parent(s): 01c3615

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -22
app.py CHANGED
@@ -110,12 +110,6 @@ div.stInfo {
110
  min-width: 120px;
111
  margin: 0 5px;
112
  }
113
- /* Hide "Press Enter to submit form" text */
114
- .stTextInput label + div + div small,
115
- [data-testid="stForm"] small,
116
- form small {
117
- display: none !important;
118
- }
119
  </style>
120
  <div class="main-title">Spirituality Q&A</div>
121
  """, unsafe_allow_html=True)
@@ -123,6 +117,7 @@ form small {
123
  # Function to handle query selection
124
  def set_query(query):
125
  if not st.session_state.processing:
 
126
  st.session_state.last_query = query
127
  st.session_state.submit_clicked = True
128
  st.rerun()
@@ -206,6 +201,7 @@ for row_idx, row in enumerate(question_rows):
206
  # Function to handle form submission
207
  def handle_form_submit():
208
  if st.session_state.query_input and st.session_state.query_input.strip() and not st.session_state.processing:
 
209
  st.session_state.last_query = st.session_state.query_input.strip()
210
  st.session_state.submit_clicked = True
211
  # Increment the form key to force a reset
@@ -215,7 +211,7 @@ def handle_form_submit():
215
  with st.form(key=f"query_form_{st.session_state.form_key}"):
216
  query = st.text_input("Ask your question:", key="query_input",
217
  placeholder="Press enter to submit your question")
218
- submit_button = st.form_submit_button("Get Answer", on_click=handle_form_submit, disabled=st.session_state.processing)
219
 
220
  # Display the current question if there is one
221
  if st.session_state.last_query:
@@ -229,34 +225,22 @@ with col1:
229
  with col2:
230
  word_limit = st.slider("Word limit:", 50, 500, 200)
231
 
232
- # Only process the query if explicitly submitted and not already processing
233
- if st.session_state.submit_clicked and st.session_state.last_query and not st.session_state.processing:
234
  st.session_state.submit_clicked = False
235
- st.session_state.processing = True
236
 
237
  with st.spinner("Processing your question..."):
238
  try:
239
- progress_bar = st.progress(0)
240
- progress_bar.progress(25, "Generating embeddings...")
241
-
242
- # Call processing function with progress tracking
243
- progress_bar.progress(50, "Retrieving relevant passages...")
244
-
245
  result = process_query(st.session_state.last_query, top_k=top_k, word_limit=word_limit)
246
-
247
- progress_bar.progress(75, "Generating answer...")
248
- time.sleep(0.5) # Small delay for visual feedback
249
- progress_bar.progress(100)
250
-
251
  st.subheader("Answer:")
252
  st.write(result["answer_with_rag"])
253
  st.subheader("Sources:")
254
  for citation in result["citations"].split("\n"):
255
  st.write(citation)
256
-
257
  except Exception as e:
258
  st.error(f"Error processing query: {str(e)}")
259
  finally:
 
260
  st.session_state.processing = False
261
 
262
  # Add helpful information
 
110
  min-width: 120px;
111
  margin: 0 5px;
112
  }
 
 
 
 
 
 
113
  </style>
114
  <div class="main-title">Spirituality Q&A</div>
115
  """, unsafe_allow_html=True)
 
117
  # Function to handle query selection
118
  def set_query(query):
119
  if not st.session_state.processing:
120
+ st.session_state.processing = True
121
  st.session_state.last_query = query
122
  st.session_state.submit_clicked = True
123
  st.rerun()
 
201
  # Function to handle form submission
202
  def handle_form_submit():
203
  if st.session_state.query_input and st.session_state.query_input.strip() and not st.session_state.processing:
204
+ st.session_state.processing = True
205
  st.session_state.last_query = st.session_state.query_input.strip()
206
  st.session_state.submit_clicked = True
207
  # Increment the form key to force a reset
 
211
  with st.form(key=f"query_form_{st.session_state.form_key}"):
212
  query = st.text_input("Ask your question:", key="query_input",
213
  placeholder="Press enter to submit your question")
214
+ submit_button = st.form_submit_button("Get Answer", on_click=handle_form_submit)
215
 
216
  # Display the current question if there is one
217
  if st.session_state.last_query:
 
225
  with col2:
226
  word_limit = st.slider("Word limit:", 50, 500, 200)
227
 
228
+ # Only process the query if explicitly submitted
229
+ if st.session_state.submit_clicked and st.session_state.last_query:
230
  st.session_state.submit_clicked = False
 
231
 
232
  with st.spinner("Processing your question..."):
233
  try:
 
 
 
 
 
 
234
  result = process_query(st.session_state.last_query, top_k=top_k, word_limit=word_limit)
 
 
 
 
 
235
  st.subheader("Answer:")
236
  st.write(result["answer_with_rag"])
237
  st.subheader("Sources:")
238
  for citation in result["citations"].split("\n"):
239
  st.write(citation)
 
240
  except Exception as e:
241
  st.error(f"Error processing query: {str(e)}")
242
  finally:
243
+ # Reset the processing flag when done
244
  st.session_state.processing = False
245
 
246
  # Add helpful information