annikwag commited on
Commit
2155b3d
·
verified ·
1 Parent(s): 4bb94c0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +36 -21
app.py CHANGED
@@ -202,7 +202,7 @@ with col5_2:
202
  ###########################################
203
  # Filter Controls - Row 3 (Remaining Filter)
204
  ###########################################
205
- col_left, col_right = st.columns([9, 1])
206
  with col_left:
207
  # Place the "Show only exact matches" checkbox here (or any other widgets)
208
  show_exact_matches = st.checkbox("Show only exact matches", key="show_exact_matches")
@@ -290,9 +290,8 @@ else:
290
  )
291
 
292
  # 3) Display results
293
- # Lexical Search Results Branch
294
  if show_exact_matches:
295
- st.write("Showing **Top Lexical Search results**")
296
  query_substring = var.strip().lower()
297
  lexical_substring_filtered = [
298
  r for r in filtered_lexical
@@ -303,19 +302,31 @@ else:
303
  st.write('No exact matches, consider unchecking "Show only exact matches"')
304
  else:
305
  top_results = filtered_lexical_no_dupe # Show all matching lexical results
306
-
307
- # --- Pagination (Above Lexical Results) ---
308
  page_size = 15
309
  total_results = len(top_results)
310
  total_pages = (total_results - 1) // page_size + 1
311
  if "page" not in st.session_state:
312
  st.session_state.page = 1
313
  current_page = st.session_state.page
314
- # Top pagination widget (right aligned, 1/7 width)
315
- col_pag_top = st.columns([6, 1])[1]
316
- new_page_top = col_pag_top.selectbox("Select Page", list(range(1, total_pages + 1)), index=current_page - 1, key="page_top")
317
- st.session_state.page = new_page_top
318
-
 
 
 
 
 
 
 
 
 
 
 
 
319
  start_index = (st.session_state.page - 1) * page_size
320
  end_index = start_index + page_size
321
  paged_results = top_results[start_index:end_index]
@@ -395,7 +406,7 @@ else:
395
  st.divider()
396
 
397
  # Bottom pagination widget
398
- col_pag_bot = st.columns([6, 1])[1]
399
  new_page_bot = col_pag_bot.selectbox("Select Page", list(range(1, total_pages + 1)), index=st.session_state.page - 1, key="page_bot")
400
  st.session_state.page = new_page_bot
401
 
@@ -436,15 +447,19 @@ else:
436
  st.markdown(formatted_rag_answer, unsafe_allow_html=True)
437
 
438
  st.divider()
439
- # Top pagination widget (right aligned, 1/7 width)
440
- col_pag_top = st.columns([6, 1])[1]
441
- new_page_top = col_pag_top.selectbox("Select Page", list(range(1, total_pages + 1)), index=current_page - 1, key="page_top_sem")
442
- st.session_state.page = new_page_top
443
-
444
- # Prominent page info with bold numbers and green highlight if current page is not 1
445
- page_num = f"<b style='color: green;'>{st.session_state.page}</b>" if st.session_state.page != 1 else f"<b>{st.session_state.page}</b>"
446
- total_pages_str = f"<b>{total_pages}</b>"
447
- st.markdown(f"Showing **{len(top_results)}** Semantic Search results (Page {page_num} of {total_pages_str})", unsafe_allow_html=True)
 
 
 
 
448
 
449
  for i, res in enumerate(top_results, start=start_index+1):
450
  metadata = res.payload.get('metadata', {})
@@ -518,6 +533,6 @@ else:
518
  st.divider()
519
 
520
  # Bottom pagination widget (right aligned, 1/7 width)
521
- col_pag_bot = st.columns([6, 1])[1]
522
  new_page_bot = col_pag_bot.selectbox("Select Page", list(range(1, total_pages + 1)), index=st.session_state.page - 1, key="page_bot_sem")
523
  st.session_state.page = new_page_bot
 
202
  ###########################################
203
  # Filter Controls - Row 3 (Remaining Filter)
204
  ###########################################
205
+ col_left, col_right = st.columns([15, 1])
206
  with col_left:
207
  # Place the "Show only exact matches" checkbox here (or any other widgets)
208
  show_exact_matches = st.checkbox("Show only exact matches", key="show_exact_matches")
 
290
  )
291
 
292
  # 3) Display results
293
+ # --- Lexical Search Results Branch ---
294
  if show_exact_matches:
 
295
  query_substring = var.strip().lower()
296
  lexical_substring_filtered = [
297
  r for r in filtered_lexical
 
302
  st.write('No exact matches, consider unchecking "Show only exact matches"')
303
  else:
304
  top_results = filtered_lexical_no_dupe # Show all matching lexical results
305
+
306
+ # --- Pagination (Above Lexical Results) in one row ---
307
  page_size = 15
308
  total_results = len(top_results)
309
  total_pages = (total_results - 1) // page_size + 1
310
  if "page" not in st.session_state:
311
  st.session_state.page = 1
312
  current_page = st.session_state.page
313
+
314
+ # Format the page numbers (highlight current page if not 1)
315
+ page_num = f"<b style='color: green;'>{current_page}</b>" if current_page != 1 else f"<b>{current_page}</b>"
316
+ total_pages_str = f"<b>{total_pages}</b>"
317
+
318
+ # Create two columns: one for the title and one for the selectbox
319
+ col_title, col_pag = st.columns([8, 4])
320
+ with col_title:
321
+ st.markdown(
322
+ f"Showing **{total_results}** Lexical Search results (Page {page_num} of {total_pages_str})",
323
+ unsafe_allow_html=True
324
+ )
325
+ with col_pag:
326
+ new_page_top = st.selectbox("Select Page", list(range(1, total_pages + 1)),
327
+ index=current_page - 1, key="page_top")
328
+ st.session_state.page = new_page_top
329
+
330
  start_index = (st.session_state.page - 1) * page_size
331
  end_index = start_index + page_size
332
  paged_results = top_results[start_index:end_index]
 
406
  st.divider()
407
 
408
  # Bottom pagination widget
409
+ col_pag_bot = st.columns([11, 1])[1]
410
  new_page_bot = col_pag_bot.selectbox("Select Page", list(range(1, total_pages + 1)), index=st.session_state.page - 1, key="page_bot")
411
  st.session_state.page = new_page_bot
412
 
 
447
  st.markdown(formatted_rag_answer, unsafe_allow_html=True)
448
 
449
  st.divider()
450
+ # Use two columns: one for the page info and one for the selectbox.
451
+ col_title, col_pag = st.columns([8, 4])
452
+ with col_title:
453
+ # Format page numbers with bold formatting (green if not the first page)
454
+ page_num = f"<b style='color: green;'>{current_page}</b>" if current_page != 1 else f"<b>{current_page}</b>"
455
+ total_pages_str = f"<b>{total_pages}</b>"
456
+ st.markdown(
457
+ f"Showing **{total_results}** Semantic Search results (Page {page_num} of {total_pages_str})",
458
+ unsafe_allow_html=True
459
+ )
460
+ with col_pag:
461
+ new_page_top = st.selectbox("Select Page", list(range(1, total_pages + 1)), index=current_page - 1, key="page_top_sem")
462
+ st.session_state.page = new_page_top
463
 
464
  for i, res in enumerate(top_results, start=start_index+1):
465
  metadata = res.payload.get('metadata', {})
 
533
  st.divider()
534
 
535
  # Bottom pagination widget (right aligned, 1/7 width)
536
+ col_pag_bot = st.columns([11, 1])[1]
537
  new_page_bot = col_pag_bot.selectbox("Select Page", list(range(1, total_pages + 1)), index=st.session_state.page - 1, key="page_bot_sem")
538
  st.session_state.page = new_page_bot