File size: 2,769 Bytes
81050d0 715bd5c 81050d0 715bd5c 81050d0 cea76ed 81050d0 cea76ed 715bd5c cea76ed 715bd5c cea76ed 715bd5c cea76ed 715bd5c cea76ed 715bd5c cea76ed 715bd5c cea76ed 81050d0 715bd5c cea76ed 715bd5c cea76ed 715bd5c cea76ed 715bd5c cea76ed 715bd5c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
import gradio as gr
from gradio_leaderboard import Leaderboard, SelectColumns
import pandas as pd
from pathlib import Path
from src.about import (
CITATION_BUTTON_LABEL,
CITATION_BUTTON_TEXT,
INTRODUCTION_TEXT,
LLM_BENCHMARKS_TEXT,
TITLE,
)
from src.display.css_html_js import custom_css
# -----------------------------
# Load your local JSON
# -----------------------------
USER_JSON = Path(__file__).parent / "leaderboard_data.json"
try:
USER_DF = pd.read_json(USER_JSON)
except Exception:
# Build with an empty frame if file missing so the Space still loads
USER_DF = pd.DataFrame(
columns=[
"Model",
"Average",
"Assistant Traits",
"Relationship & Intimacy",
"Emotional Investment",
"User Vulnerabilities",
]
)
# Ensure types (Model=str, others=float)
if "Model" in USER_DF.columns:
USER_DF["Model"] = USER_DF["Model"].astype(str)
for col in USER_DF.columns:
if col != "Model":
USER_DF[col] = pd.to_numeric(USER_DF[col], errors="coerce")
def init_simple_leaderboard(df: pd.DataFrame):
# Show Model + up to 6 metrics by default
metrics = [c for c in df.columns if c != "Model"]
default_cols = ["Model"] + metrics[:6] if "Model" in df.columns else list(df.columns)[:7]
cant_hide = ["Model"] if "Model" in df.columns else []
return Leaderboard(
value=df,
select_columns=SelectColumns(
default_selection=default_cols if default_cols else list(df.columns),
cant_deselect=cant_hide,
label="Select Columns to Display:",
),
search_columns=["Model"] if "Model" in df.columns else [],
hide_columns=[], # keep everything visible
filter_columns=[], # add later if you introduce typed columns to filter on
interactive=False,
)
# -----------------------------
# UI
# -----------------------------
demo = gr.Blocks(css=custom_css)
with demo:
gr.HTML(TITLE)
gr.Markdown(INTRODUCTION_TEXT, elem_classes="markdown-text")
with gr.Tabs(elem_classes="tab-buttons"):
with gr.TabItem("📊 INTIMA Leaderboard", elem_id="intima-leaderboard-tab", id=0):
_ = init_simple_leaderboard(USER_DF)
with gr.TabItem("📝 About", elem_id="about-tab", id=1):
gr.Markdown(LLM_BENCHMARKS_TEXT, elem_classes="markdown-text")
with gr.Row():
with gr.Accordion("📙 Citation", open=False):
gr.Textbox(
value=CITATION_BUTTON_TEXT,
label=CITATION_BUTTON_LABEL,
lines=20,
elem_id="citation-button",
show_copy_button=True,
)
if __name__ == "__main__":
demo.launch() |