Spaces:
Runtime error
Runtime error
Fix column headers and stale cache via demo.load()
Browse files
app.py
CHANGED
|
@@ -4,6 +4,8 @@ Reads EvalEval instance-level records from a HuggingFace dataset and
|
|
| 4 |
renders a sortable comparison table across models and skills.
|
| 5 |
"""
|
| 6 |
import json
|
|
|
|
|
|
|
| 7 |
from pathlib import Path
|
| 8 |
|
| 9 |
import gradio as gr
|
|
@@ -14,53 +16,55 @@ DATASET_REPO = "webchick/eval-results-poc"
|
|
| 14 |
|
| 15 |
|
| 16 |
def load_results() -> pd.DataFrame:
|
| 17 |
-
"""Download the dataset and flatten instance records into a DataFrame."""
|
| 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 |
def build_ui():
|
| 62 |
-
df = load_results()
|
| 63 |
-
|
| 64 |
with gr.Blocks(title="Drupal AI Eval Dashboard (POC)") as demo:
|
| 65 |
gr.Markdown(
|
| 66 |
"# Drupal AI Eval Dashboard (POC)\n\n"
|
|
@@ -71,48 +75,83 @@ def build_ui():
|
|
| 71 |
"(https://github.com/evaleval/every_eval_ever)."
|
| 72 |
)
|
| 73 |
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
)
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
)
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 108 |
)
|
| 109 |
-
# populate on load
|
| 110 |
-
init_summary, init_table, init_agg = update("(all)")
|
| 111 |
-
summary.value = init_summary
|
| 112 |
-
results_table.value = init_table
|
| 113 |
|
| 114 |
-
|
| 115 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 116 |
|
| 117 |
return demo
|
| 118 |
|
|
|
|
| 4 |
renders a sortable comparison table across models and skills.
|
| 5 |
"""
|
| 6 |
import json
|
| 7 |
+
import shutil
|
| 8 |
+
import tempfile
|
| 9 |
from pathlib import Path
|
| 10 |
|
| 11 |
import gradio as gr
|
|
|
|
| 16 |
|
| 17 |
|
| 18 |
def load_results() -> pd.DataFrame:
|
| 19 |
+
"""Download the dataset fresh and flatten instance records into a DataFrame."""
|
| 20 |
+
tmp = tempfile.mkdtemp()
|
| 21 |
+
try:
|
| 22 |
+
local_dir = snapshot_download(
|
| 23 |
+
repo_id=DATASET_REPO,
|
| 24 |
+
repo_type="dataset",
|
| 25 |
+
local_dir=tmp,
|
| 26 |
+
)
|
| 27 |
+
rows = []
|
| 28 |
+
for jsonl_file in sorted(Path(local_dir).rglob("*_samples.jsonl")):
|
| 29 |
+
with open(jsonl_file) as f:
|
| 30 |
+
for line in f:
|
| 31 |
+
line = line.strip()
|
| 32 |
+
if not line:
|
| 33 |
+
continue
|
| 34 |
+
try:
|
| 35 |
+
rec = json.loads(line)
|
| 36 |
+
except json.JSONDecodeError:
|
| 37 |
+
continue
|
| 38 |
+
if not rec.get("schema_version", "").startswith("instance_level_eval"):
|
| 39 |
+
continue
|
| 40 |
+
|
| 41 |
+
meta = rec.get("metadata") or {}
|
| 42 |
+
perf = rec.get("performance") or {}
|
| 43 |
+
usage = rec.get("token_usage") or {}
|
| 44 |
+
ev = rec.get("evaluation") or {}
|
| 45 |
+
|
| 46 |
+
raw_prompt = (rec.get("input") or {}).get("raw", "")
|
| 47 |
+
task = (raw_prompt[:97] + "…") if len(raw_prompt) > 100 else raw_prompt
|
| 48 |
+
|
| 49 |
+
rows.append({
|
| 50 |
+
"Namespace": meta.get("eval_namespace", "?"),
|
| 51 |
+
"Skill": meta.get("skill_name", "?"),
|
| 52 |
+
"Case": meta.get("case_id", "?"),
|
| 53 |
+
"Task": task,
|
| 54 |
+
"Model": rec.get("model_id", "?"),
|
| 55 |
+
"Passed": "✅" if ev.get("is_correct") else "❌",
|
| 56 |
+
"Latency (ms)": round(perf.get("latency_ms") or 0, 0),
|
| 57 |
+
"Input tokens": usage.get("input_tokens", 0),
|
| 58 |
+
"Output tokens": usage.get("output_tokens", 0),
|
| 59 |
+
"Cost (USD)": round(float(meta.get("cost_usd") or 0), 6),
|
| 60 |
+
"Run timestamp": meta.get("timestamp_run", ""),
|
| 61 |
+
})
|
| 62 |
+
return pd.DataFrame(rows)
|
| 63 |
+
finally:
|
| 64 |
+
shutil.rmtree(tmp, ignore_errors=True)
|
| 65 |
|
| 66 |
|
| 67 |
def build_ui():
|
|
|
|
|
|
|
| 68 |
with gr.Blocks(title="Drupal AI Eval Dashboard (POC)") as demo:
|
| 69 |
gr.Markdown(
|
| 70 |
"# Drupal AI Eval Dashboard (POC)\n\n"
|
|
|
|
| 75 |
"(https://github.com/evaleval/every_eval_ever)."
|
| 76 |
)
|
| 77 |
|
| 78 |
+
namespace_filter = gr.Dropdown(
|
| 79 |
+
choices=["(all)"],
|
| 80 |
+
value="(all)",
|
| 81 |
+
label="Filter by namespace",
|
| 82 |
+
)
|
| 83 |
+
summary = gr.Markdown("_Loading results…_")
|
| 84 |
+
results_table = gr.Dataframe(interactive=False, wrap=True)
|
| 85 |
+
gr.Markdown("## Pass rate by model")
|
| 86 |
+
pass_rate_table = gr.Dataframe(interactive=False)
|
| 87 |
+
|
| 88 |
+
def filter_data(ns, df_json):
|
| 89 |
+
df = pd.read_json(df_json, orient="split")
|
| 90 |
+
filtered = df if ns == "(all)" else df[df["Namespace"] == ns]
|
| 91 |
+
if filtered.empty:
|
| 92 |
+
return "_No results found._", pd.DataFrame(), pd.DataFrame()
|
| 93 |
+
summary_text = (
|
| 94 |
+
f"**{len(filtered)} result(s)** across "
|
| 95 |
+
f"{filtered['Model'].nunique()} model(s) and "
|
| 96 |
+
f"{filtered['Case'].nunique()} case(s)."
|
| 97 |
)
|
| 98 |
+
filtered = filtered.copy()
|
| 99 |
+
filtered["_passed_int"] = (filtered["Passed"] == "✅").astype(int)
|
| 100 |
+
agg = (
|
| 101 |
+
filtered.groupby("Model")["_passed_int"]
|
| 102 |
+
.agg(["mean", "count"])
|
| 103 |
+
.reset_index()
|
| 104 |
+
.rename(columns={"mean": "Pass rate", "count": "Cases run"})
|
| 105 |
+
)
|
| 106 |
+
agg["Pass rate"] = agg["Pass rate"].round(2)
|
| 107 |
+
return summary_text, filtered.drop(columns=["_passed_int"]), agg
|
| 108 |
+
|
| 109 |
+
# Hidden state holds the full DataFrame so filter_data is pure
|
| 110 |
+
data_store = gr.State()
|
| 111 |
+
|
| 112 |
+
def on_load():
|
| 113 |
+
df = load_results()
|
| 114 |
+
if df.empty:
|
| 115 |
+
return (
|
| 116 |
+
gr.Dropdown(choices=["(all)"], value="(all)"),
|
| 117 |
+
df.to_json(orient="split"),
|
| 118 |
+
"_No results found in the dataset yet._",
|
| 119 |
+
pd.DataFrame(),
|
| 120 |
+
pd.DataFrame(),
|
| 121 |
)
|
| 122 |
+
namespaces = sorted(df["Namespace"].unique().tolist())
|
| 123 |
+
summary_text = (
|
| 124 |
+
f"**{len(df)} result(s)** across "
|
| 125 |
+
f"{df['Model'].nunique()} model(s) and "
|
| 126 |
+
f"{df['Case'].nunique()} case(s)."
|
| 127 |
+
)
|
| 128 |
+
df_copy = df.copy()
|
| 129 |
+
df_copy["_passed_int"] = (df_copy["Passed"] == "✅").astype(int)
|
| 130 |
+
agg = (
|
| 131 |
+
df_copy.groupby("Model")["_passed_int"]
|
| 132 |
+
.agg(["mean", "count"])
|
| 133 |
+
.reset_index()
|
| 134 |
+
.rename(columns={"mean": "Pass rate", "count": "Cases run"})
|
| 135 |
+
)
|
| 136 |
+
agg["Pass rate"] = agg["Pass rate"].round(2)
|
| 137 |
+
return (
|
| 138 |
+
gr.Dropdown(choices=["(all)"] + namespaces, value="(all)"),
|
| 139 |
+
df.to_json(orient="split"),
|
| 140 |
+
summary_text,
|
| 141 |
+
df,
|
| 142 |
+
agg,
|
| 143 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 144 |
|
| 145 |
+
demo.load(
|
| 146 |
+
fn=on_load,
|
| 147 |
+
outputs=[namespace_filter, data_store, summary, results_table, pass_rate_table],
|
| 148 |
+
)
|
| 149 |
+
|
| 150 |
+
namespace_filter.change(
|
| 151 |
+
fn=filter_data,
|
| 152 |
+
inputs=[namespace_filter, data_store],
|
| 153 |
+
outputs=[summary, results_table, pass_rate_table],
|
| 154 |
+
)
|
| 155 |
|
| 156 |
return demo
|
| 157 |
|