Download src/populate.py from JMullings/LLM-XRay: direct link, hf CLI and curl.
- Browser
- Download file 2.51 kB
-
https://huggingface.co/spaces/JMullings/LLM-XRay/resolve/main/src/populate.py
- Command line
-
hf download hf://spaces/JMullings/LLM-XRay/src/populate.py
-
curl -L -o populate.py https://huggingface.co/spaces/JMullings/LLM-XRay/resolve/main/src/populate.py
2.51 kB
| import os | |
| import pandas as pd | |
| try: | |
| from src.display.utils import fields | |
| except ImportError: | |
| try: | |
| from src.utils import fields | |
| except ImportError: | |
| try: | |
| from display.utils import fields | |
| except ImportError: | |
| from utils import fields | |
| try: | |
| from src.leaderboard.read_evals import get_raw_eval_results | |
| except ImportError: | |
| try: | |
| from src.read_evals import get_raw_eval_results | |
| except ImportError: | |
| try: | |
| from leaderboard.read_evals import get_raw_eval_results | |
| except ImportError: | |
| from read_evals import get_raw_eval_results | |
| def get_leaderboard_df(results_path: str, requests_path: str, cols: list, benchmark_cols: list) -> pd.DataFrame: | |
| raw_data = get_raw_eval_results(results_path, requests_path) | |
| all_col_contents = fields() | |
| all_col_names = [c.name for c in all_col_contents] | |
| if not raw_data: | |
| return pd.DataFrame(columns=all_col_names) | |
| all_data_json = [v.to_dict() for v in raw_data] | |
| df = pd.DataFrame.from_records(all_data_json) | |
| # Ensure all expected columns exist and are strictly typed | |
| for col_content in all_col_contents: | |
| if col_content.name not in df.columns: | |
| df[col_content.name] = 0.0 if col_content.type == "number" else "" | |
| elif col_content.type == "number": | |
| df[col_content.name] = pd.to_numeric(df[col_content.name], errors="coerce").fillna(0.0) | |
| else: | |
| df[col_content.name] = df[col_content.name].fillna("").astype(str) | |
| df = df[all_col_names] | |
| # Sort ascending by risk/composite score (lower score = lower risk = rank higher) | |
| for col in all_col_names: | |
| if "composite" in col.lower() or "risk" in col.lower() or "score" in col.lower(): | |
| df = df.sort_values(by=[col], ascending=True) | |
| break | |
| return df.reset_index(drop=True) | |
| def get_top_3_eval_cards(results_path: str): | |
| raw_data = get_raw_eval_results(results_path, "") | |
| if not raw_data: | |
| return [] | |
| sorted_res = sorted(raw_data, key=lambda x: x.composite_score) | |
| top_3 = [] | |
| for r in sorted_res[:3]: | |
| top_3.append({ | |
| "model_name": r.full_model, | |
| "org": r.org, | |
| "factuality": r.results.get("factuality", 0.0), | |
| "blind_fraction": r.results.get("blind_fraction", 0.0), | |
| "composite_score": r.composite_score, | |
| "run_id": f"REV-{r.revision}", | |
| "date": r.date, | |
| }) | |
| return top_3 |