import os import html as html_lib import json import numpy as np import streamlit as st import streamlit.components.v1 as components import plotly.graph_objects as go from system1_baseline import ask_baseline from system2_rag import ask_rag, load_vectorstore, build_vectorstore st.set_page_config( page_title="CodeSage", page_icon="๐ง", layout="wide" ) # โโ Session state โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ if "ratings" not in st.session_state: st.session_state.ratings = [] if "last_results" not in st.session_state: st.session_state.last_results = None if "rating_submitted" not in st.session_state: st.session_state.rating_submitted = False if "input_question" not in st.session_state: st.session_state.input_question = "" if "auto_run" not in st.session_state: st.session_state.auto_run = False if "auto_metrics" not in st.session_state: st.session_state.auto_metrics = {} if "benchmark_results" not in st.session_state: _bm_cache = "data/benchmark_cache.json" if os.path.exists(_bm_cache): with open(_bm_cache, encoding="utf-8") as _f: st.session_state.benchmark_results = json.load(_f) else: st.session_state.benchmark_results = [] if "winner" not in st.session_state: st.session_state.winner = None if "halluc_flags" not in st.session_state: st.session_state.halluc_flags = {} # โโ CSS โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ st.markdown("""""", unsafe_allow_html=True) # โโ Hero โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ st.markdown("""
| Metric | โก System 1 Baseline LLM |
๐ System 2 RAG Chatbot |
๐ง System 3 Fine-Tuned |
Best | Unit |
|---|---|---|---|---|---|
| Answer Accuracy | {bm_acc[0]} | {bm_acc[1]} | {bm_acc[2]} | {_best_high_badge(_acc) if _bm else _dash} | {_unit('%')} |
| Groundedness Score | {bm_grd[0]} | {bm_grd[1]} | {bm_grd[2]} | {_best_high_badge(_grd) if _bm else _dash} | {_unit('0โ1')} |
| Hallucination Rate | {bm_hr[0]} | {bm_hr[1]} | {bm_hr[2]} | {_best_low_badge(_hr) if _bm else _dash} | {_unit('%')} |
| Answer Relevance | {bm_rel[0]} | {bm_rel[1]} | {bm_rel[2]} | {_best_high_badge(_rel) if _bm else _dash} | {_unit('0โ1')} |
| Faithfulness | {bm_fth[0]} | {bm_fth[1]} | {bm_fth[2]} | {_best_high_badge(_fth) if _bm else _dash} | {_unit('0โ1')} |
| Avg Response Time | {bm_tm[0]} | {bm_tm[1]} | {bm_tm[2]} | {_best_low_badge(_tm) if _bm else _dash} | {_unit('sec')} |
| Cost per Query | {bm_cst[0]} | {bm_cst[1]} | {bm_cst[2]} | {_best_low_badge(_cst) if _bm else _dash} | {_unit('USD')} |
| Overall Score (1โ5) | {bm_ov[0]} | {bm_ov[1]} | {bm_ov[2]} | {_best_high_badge(_ov) if _bm else _dash} | {_unit('rating')} |