annikwag commited on
Commit
c68b7af
·
verified ·
1 Parent(s): 6bc08d6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -14
app.py CHANGED
@@ -291,6 +291,24 @@ else:
291
  unsafe_allow_html=True
292
  )
293
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
294
  # 3) Display results
295
  # Lexical Search Results Branch
296
  if show_exact_matches:
@@ -377,17 +395,19 @@ else:
377
  except Exception:
378
  formatted_succ = successor
379
  parts.append(f"**Successor Project:** {formatted_succ}")
380
- extra_line = "<br>" + " | ".join(parts) if parts else ""
381
 
 
382
  additional_text = (
383
  f"**Objective:** {highlight_query(objective, var)}<br>"
384
  f"**Commissioned by:** {metadata.get('client', 'Unknown Client')}<br>"
385
  f"**Projekt duration:** {start_year_str}-{end_year_str}<br>"
386
- f"**Budget:** Project: <b>{formatted_project_budget}</b>, Total volume: <b>{formatted_total_volume}</b><br>"
387
- + extra_line +
388
- f"<br>**Country:** {country_raw}<br>"
389
- f"**Sector:** {crs_combined}"
390
  )
 
 
 
 
391
  contact = metadata.get("contact", "").strip()
392
  if contact and contact.lower() != "[email protected]":
393
  additional_text += f"<br>**Contact:** [email protected]"
@@ -426,14 +446,19 @@ else:
426
  total_pages_str = f"<b>{total_pages}</b>"
427
  st.markdown(f"Showing **{len(top_results)}** Semantic Search results (Page {page_num} of {total_pages_str})", unsafe_allow_html=True)
428
 
429
- # --- RAG Answer (Left aligned, bullet points, bold numbers) ---
430
  rag_answer = get_rag_answer(var, top_results, DEDICATED_ENDPOINT, WRITE_ACCESS_TOKEN)
431
  bullet_lines = []
432
  for line in rag_answer.splitlines():
433
  if line.strip():
434
  line_bold = re.sub(r'(\d+)', r'<b>\1</b>', line)
435
- bullet_lines.append(f"<li>{line_bold}</li>")
436
- formatted_rag_answer = "<ul style='text-align: left; list-style-position: inside;'>" + "".join(bullet_lines) + "</ul>"
 
 
 
 
 
437
  st.markdown(formatted_rag_answer, unsafe_allow_html=True)
438
  st.divider()
439
 
@@ -490,17 +515,18 @@ else:
490
  except Exception:
491
  formatted_succ = successor
492
  parts.append(f"**Successor Project:** {formatted_succ}")
493
- extra_line = "<br>" + " | ".join(parts) if parts else ""
494
 
495
  additional_text = (
496
  f"**Objective:** {metadata.get('objective', '')}<br>"
497
  f"**Commissioned by:** {metadata.get('client', 'Unknown Client')}<br>"
498
  f"**Projekt duration:** {start_year_str}-{end_year_str}<br>"
499
- f"**Budget:** Project: <b>{formatted_project_budget}</b>, Total volume: <b>{formatted_total_volume}</b><br>"
500
- + extra_line +
501
- f"<br>**Country:** {country_raw}<br>"
502
- f"**Sector:** {crs_combined}"
503
  )
 
 
 
 
504
  contact = metadata.get("contact", "").strip()
505
  if contact and contact.lower() != "[email protected]":
506
  additional_text += f"<br>**Contact:** [email protected]"
@@ -510,4 +536,4 @@ else:
510
  # Bottom pagination widget (right aligned, 1/7 width)
511
  col_pag_bot = st.columns([6, 1])[1]
512
  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")
513
- st.session_state.page = new_page_bot
 
291
  unsafe_allow_html=True
292
  )
293
 
294
+ # --- RAG Answer Block (Left aligned, fully bold, highlighted in grey) ---
295
+ # Retrieve the RAG answer and process each non-empty line
296
+ rag_answer = get_rag_answer(var, filtered_semantic_no_dupe if not show_exact_matches else filtered_lexical_no_dupe, DEDICATED_ENDPOINT, WRITE_ACCESS_TOKEN)
297
+ bullet_lines = []
298
+ for line in rag_answer.splitlines():
299
+ if line.strip():
300
+ # Bold the entire line (numbers remain bold as part of the overall bold)
301
+ line_bold = re.sub(r'(\d+)', r'<b>\1</b>', line)
302
+ bullet_lines.append(f"<li><b>{line_bold}</b></li>")
303
+ formatted_rag_answer = (
304
+ "<div style='background-color: #f0f0f0; padding: 10px;'>"
305
+ "<ul style='text-align: left; list-style-position: inside;'>"
306
+ + "".join(bullet_lines) +
307
+ "</ul></div>"
308
+ )
309
+ st.markdown(formatted_rag_answer, unsafe_allow_html=True)
310
+ st.divider()
311
+
312
  # 3) Display results
313
  # Lexical Search Results Branch
314
  if show_exact_matches:
 
395
  except Exception:
396
  formatted_succ = successor
397
  parts.append(f"**Successor Project:** {formatted_succ}")
398
+ extra_line = " | ".join(parts) if parts else ""
399
 
400
+ # Build additional text with no extra blank row between Budget and predecessor/successor info
401
  additional_text = (
402
  f"**Objective:** {highlight_query(objective, var)}<br>"
403
  f"**Commissioned by:** {metadata.get('client', 'Unknown Client')}<br>"
404
  f"**Projekt duration:** {start_year_str}-{end_year_str}<br>"
405
+ f"**Budget:** Project: <b>{formatted_project_budget}</b>, Total volume: <b>{formatted_total_volume}</b>"
 
 
 
406
  )
407
+ if extra_line:
408
+ additional_text += f"<br>{extra_line}"
409
+ additional_text += f"<br>**Country:** {country_raw}<br>**Sector:** {crs_combined}"
410
+
411
  contact = metadata.get("contact", "").strip()
412
  if contact and contact.lower() != "[email protected]":
413
  additional_text += f"<br>**Contact:** [email protected]"
 
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
+ # --- RAG Answer (Left aligned, fully bold, highlighted in grey) ---
450
  rag_answer = get_rag_answer(var, top_results, DEDICATED_ENDPOINT, WRITE_ACCESS_TOKEN)
451
  bullet_lines = []
452
  for line in rag_answer.splitlines():
453
  if line.strip():
454
  line_bold = re.sub(r'(\d+)', r'<b>\1</b>', line)
455
+ bullet_lines.append(f"<li><b>{line_bold}</b></li>")
456
+ formatted_rag_answer = (
457
+ "<div style='background-color: #f0f0f0; padding: 10px;'>"
458
+ "<ul style='text-align: left; list-style-position: inside;'>"
459
+ + "".join(bullet_lines) +
460
+ "</ul></div>"
461
+ )
462
  st.markdown(formatted_rag_answer, unsafe_allow_html=True)
463
  st.divider()
464
 
 
515
  except Exception:
516
  formatted_succ = successor
517
  parts.append(f"**Successor Project:** {formatted_succ}")
518
+ extra_line = " | ".join(parts) if parts else ""
519
 
520
  additional_text = (
521
  f"**Objective:** {metadata.get('objective', '')}<br>"
522
  f"**Commissioned by:** {metadata.get('client', 'Unknown Client')}<br>"
523
  f"**Projekt duration:** {start_year_str}-{end_year_str}<br>"
524
+ f"**Budget:** Project: <b>{formatted_project_budget}</b>, Total volume: <b>{formatted_total_volume}</b>"
 
 
 
525
  )
526
+ if extra_line:
527
+ additional_text += f"<br>{extra_line}"
528
+ additional_text += f"<br>**Country:** {country_raw}<br>**Sector:** {crs_combined}"
529
+
530
  contact = metadata.get("contact", "").strip()
531
  if contact and contact.lower() != "[email protected]":
532
  additional_text += f"<br>**Contact:** [email protected]"
 
536
  # Bottom pagination widget (right aligned, 1/7 width)
537
  col_pag_bot = st.columns([6, 1])[1]
538
  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")
539
+ st.session_state.page = new_page_bot