Inframat-x commited on
Commit
5765b46
·
verified ·
1 Parent(s): 49373c5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +48 -10
app.py CHANGED
@@ -6,7 +6,8 @@
6
  # - Stable categoricals ("NA"); no over-strict completeness gate
7
  # - Fixed [[PAGE=...]] regex
8
  # - NEW: Lightweight instrumentation (JSONL logs per RAG turn)
9
- # - UPDATED UI COLORS: Dark-blue theme for tabs + Evaluate k-slider
 
10
  # ================================================================
11
 
12
  # ---------------------- Runtime flags (HF-safe) ----------------------
@@ -18,7 +19,7 @@ os.environ["TOKENIZERS_PARALLELISM"] = "false"
18
  # ------------------------------- Imports ------------------------------
19
  import re, joblib, warnings, json, traceback, time, uuid, subprocess, sys
20
  from pathlib import Path
21
- from typing import List, Dict, Any, Optional, Tuple
22
 
23
  import numpy as np
24
  import pandas as pd
@@ -741,7 +742,7 @@ def rag_reply(
741
  "retrieval": {"hits": retr_list, "latency_ms_retriever": latency_ms_retriever},
742
  "output": {
743
  "final_answer": final,
744
- "used_sentences": [{"sent": s["sent"], "doc": s["doc"], "page": s["page"]} for s in selected]
745
  },
746
  "latency_ms_total": total_ms,
747
  "latency_ms_llm": llm_latency_ms,
@@ -819,7 +820,7 @@ input[type="checkbox"], .gr-checkbox, .gr-checkbox > * { pointer-events: auto !i
819
  color: #eef6ff !important;
820
  }
821
 
822
- /* NEW — Evaluate tab dark/high-contrast styling */
823
  #eval-tab .block, #eval-tab .group, #eval-tab .accordion {
824
  background: linear-gradient(165deg, #0a0f1f 0%, #0d1a31 60%, #0a1c2e 100%) !important;
825
  border-radius: 12px;
@@ -851,7 +852,7 @@ input[type="checkbox"], .gr-checkbox, .gr-checkbox > * { pointer-events: auto !i
851
  /* Predictor output emphasis */
852
  #pred-out .wrap { font-size: 20px; font-weight: 700; color: #ecfdf5; }
853
 
854
- /* === (ADDED) Tab header: darker blue theme for all tabs === */
855
  .gradio-container .tab-nav button[role="tab"] {
856
  background: #0b1b34 !important;
857
  color: #cfe6ff !important;
@@ -863,7 +864,7 @@ input[type="checkbox"], .gr-checkbox, .gr-checkbox > * { pointer-events: auto !i
863
  border-color: #3b82f6 !important;
864
  }
865
 
866
- /* === (ADDED) Evaluate tab: enforce dark-blue text for labels/marks === */
867
  #eval-tab .label,
868
  #eval-tab label,
869
  #eval-tab .gr-slider .label,
@@ -872,10 +873,10 @@ input[type="checkbox"], .gr-checkbox, .gr-checkbox > * { pointer-events: auto !i
872
  #eval-tab .markdown,
873
  #eval-tab p,
874
  #eval-tab span {
875
- color: #cfe6ff !important; /* soft, not pure white */
876
  }
877
 
878
- /* === (ADDED) Target the specific k-slider label strongly === */
879
  #k-slider .label,
880
  #k-slider label,
881
  #k-slider .wrap .label {
@@ -883,7 +884,7 @@ input[type="checkbox"], .gr-checkbox, .gr-checkbox > * { pointer-events: auto !i
883
  text-shadow: 0 1px 0 rgba(0,0,0,0.35);
884
  }
885
 
886
- /* === (ADDED) Slider track/thumb (dark blue gradient + blue thumb) === */
887
  #eval-tab input[type="range"] {
888
  accent-color: #3b82f6 !important; /* fallback */
889
  }
@@ -916,6 +917,15 @@ input[type="checkbox"], .gr-checkbox, .gr-checkbox > * { pointer-events: auto !i
916
  border: 1px solid #60a5fa;
917
  border-radius: 50%;
918
  }
 
 
 
 
 
 
 
 
 
919
  """
920
 
921
  theme = gr.themes.Soft(
@@ -933,6 +943,34 @@ theme = gr.themes.Soft(
933
  )
934
 
935
  with gr.Blocks(css=CSS, theme=theme, fill_height=True) as demo:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
936
  gr.Markdown(
937
  "<h1 style='margin:0'>Self-Sensing Concrete Assistant</h1>"
938
  "<p style='opacity:.9'>"
@@ -1054,7 +1092,7 @@ with gr.Blocks(css=CSS, theme=theme, fill_height=True) as demo:
1054
  gr.Markdown("Upload your **gold.csv** and compute metrics against the app logs.")
1055
  with gr.Row():
1056
  gold_file = gr.File(label="gold.csv", file_types=[".csv"], interactive=True)
1057
- # (ADDED elem_id to target k slider with CSS)
1058
  k_slider = gr.Slider(3, 12, value=8, step=1, label="k for Hit/Recall/nDCG", elem_id="k-slider")
1059
  with gr.Row():
1060
  btn_eval = gr.Button("Compute Metrics", variant="primary")
 
6
  # - Stable categoricals ("NA"); no over-strict completeness gate
7
  # - Fixed [[PAGE=...]] regex
8
  # - NEW: Lightweight instrumentation (JSONL logs per RAG turn)
9
+ # - UPDATED THEME: Dark-blue tabs + Evaluate tab + k-slider styling
10
+ # - OPTIONAL JS: Adds .eval-active class when Evaluate tab is selected
11
  # ================================================================
12
 
13
  # ---------------------- Runtime flags (HF-safe) ----------------------
 
19
  # ------------------------------- Imports ------------------------------
20
  import re, joblib, warnings, json, traceback, time, uuid, subprocess, sys
21
  from pathlib import Path
22
+ from typing import List, Dict, Any
23
 
24
  import numpy as np
25
  import pandas as pd
 
742
  "retrieval": {"hits": retr_list, "latency_ms_retriever": latency_ms_retriever},
743
  "output": {
744
  "final_answer": final,
745
+ "used_sentences": [{"sent": s['sent'], "doc": s['doc'], "page": s['page']} for s in selected]
746
  },
747
  "latency_ms_total": total_ms,
748
  "latency_ms_llm": llm_latency_ms,
 
820
  color: #eef6ff !important;
821
  }
822
 
823
+ /* Evaluate tab dark/high-contrast styling */
824
  #eval-tab .block, #eval-tab .group, #eval-tab .accordion {
825
  background: linear-gradient(165deg, #0a0f1f 0%, #0d1a31 60%, #0a1c2e 100%) !important;
826
  border-radius: 12px;
 
852
  /* Predictor output emphasis */
853
  #pred-out .wrap { font-size: 20px; font-weight: 700; color: #ecfdf5; }
854
 
855
+ /* Tab header: darker blue theme for all tabs */
856
  .gradio-container .tab-nav button[role="tab"] {
857
  background: #0b1b34 !important;
858
  color: #cfe6ff !important;
 
864
  border-color: #3b82f6 !important;
865
  }
866
 
867
+ /* Evaluate tab: enforce dark-blue text for labels/marks */
868
  #eval-tab .label,
869
  #eval-tab label,
870
  #eval-tab .gr-slider .label,
 
873
  #eval-tab .markdown,
874
  #eval-tab p,
875
  #eval-tab span {
876
+ color: #cfe6ff !important; /* softer than pure white */
877
  }
878
 
879
+ /* Target the specific k-slider label strongly */
880
  #k-slider .label,
881
  #k-slider label,
882
  #k-slider .wrap .label {
 
884
  text-shadow: 0 1px 0 rgba(0,0,0,0.35);
885
  }
886
 
887
+ /* Slider track/thumb (dark blue gradient + blue thumb) */
888
  #eval-tab input[type="range"] {
889
  accent-color: #3b82f6 !important; /* fallback */
890
  }
 
917
  border: 1px solid #60a5fa;
918
  border-radius: 50%;
919
  }
920
+
921
+ /* When Evaluate tab is active and JS has added .eval-active, bump contrast subtly */
922
+ #eval-tab.eval-active .block,
923
+ #eval-tab.eval-active .group {
924
+ border-color: #60a5fa !important;
925
+ }
926
+ #eval-tab.eval-active .label {
927
+ color: #e6f2ff !important;
928
+ }
929
  """
930
 
931
  theme = gr.themes.Soft(
 
943
  )
944
 
945
  with gr.Blocks(css=CSS, theme=theme, fill_height=True) as demo:
946
+ # Optional: JS to toggle .eval-active when Evaluate tab selected
947
+ gr.HTML("""
948
+ <script>
949
+ (function(){
950
+ const applyEvalActive = () => {
951
+ const selected = document.querySelector('.tab-nav button[role="tab"][aria-selected="true"]');
952
+ const evalPanel = document.querySelector('#eval-tab');
953
+ if (!evalPanel) return;
954
+ if (selected && /Evaluate/.test(selected.textContent)) {
955
+ evalPanel.classList.add('eval-active');
956
+ } else {
957
+ evalPanel.classList.remove('eval-active');
958
+ }
959
+ };
960
+ // After tab clicks
961
+ document.addEventListener('click', function(e) {
962
+ if (e.target && e.target.getAttribute('role') === 'tab') {
963
+ setTimeout(applyEvalActive, 50);
964
+ }
965
+ }, true);
966
+ // On initial load
967
+ document.addEventListener('DOMContentLoaded', applyEvalActive);
968
+ // Fallback timer in case of hydration delays
969
+ setTimeout(applyEvalActive, 300);
970
+ })();
971
+ </script>
972
+ """)
973
+
974
  gr.Markdown(
975
  "<h1 style='margin:0'>Self-Sensing Concrete Assistant</h1>"
976
  "<p style='opacity:.9'>"
 
1092
  gr.Markdown("Upload your **gold.csv** and compute metrics against the app logs.")
1093
  with gr.Row():
1094
  gold_file = gr.File(label="gold.csv", file_types=[".csv"], interactive=True)
1095
+ # Add elem_id so CSS can target this slider
1096
  k_slider = gr.Slider(3, 12, value=8, step=1, label="k for Hit/Recall/nDCG", elem_id="k-slider")
1097
  with gr.Row():
1098
  btn_eval = gr.Button("Compute Metrics", variant="primary")