Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,35 +1,31 @@
|
|
| 1 |
"""
|
| 2 |
-
FINAL Bench Auto-Evaluator v1.0
|
| 3 |
-
================================
|
| 4 |
-
|
| 5 |
|
| 6 |
-
-
|
| 7 |
-
-
|
| 8 |
-
-
|
|
|
|
| 9 |
|
| 10 |
-
Author: Ginigen AI
|
| 11 |
-
License: Apache 2.0
|
| 12 |
"""
|
| 13 |
|
| 14 |
-
import json, os, time, csv, io, re,
|
| 15 |
from datetime import datetime
|
| 16 |
from dataclasses import dataclass, field, asdict
|
| 17 |
-
from typing import
|
|
|
|
| 18 |
import requests
|
| 19 |
import numpy as np
|
| 20 |
-
import pandas as pd
|
| 21 |
import gradio as gr
|
| 22 |
|
| 23 |
-
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 24 |
-
# PART 1: λ²€μΉλ§ν¬ λ°μ΄ν° ꡬ쑰 + 루λΈλ¦
|
| 25 |
-
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 26 |
-
|
| 27 |
PILLAR_INFO = {
|
| 28 |
-
"P1_Emergence":
|
| 29 |
-
"P2_Metacognition":
|
| 30 |
-
"P3_SelfEvolution":
|
| 31 |
-
"P4_Orchestration":
|
| 32 |
-
"P5_SynergyAntagonism":{"name": "μμμκ·Ή", "icon": "β―", "color": "#E63946", "weight": 0.25},
|
| 33 |
}
|
| 34 |
|
| 35 |
@dataclass
|
|
@@ -37,970 +33,432 @@ class EvalTask:
|
|
| 37 |
task_id: str; pillar: str; sub_dimension: str; difficulty: str
|
| 38 |
prompt: str; context: Optional[str] = None; expected_behavior: Optional[str] = None
|
| 39 |
scoring_rubric: Dict = field(default_factory=dict); metadata: Dict = field(default_factory=dict)
|
| 40 |
-
def to_dict(self): return asdict(self)
|
| 41 |
-
|
| 42 |
-
def load_tasks_from_parquet(path="full_v2.parquet"):
|
| 43 |
-
df = pd.read_parquet(path)
|
| 44 |
-
tasks = []
|
| 45 |
-
for _, row in df.iterrows():
|
| 46 |
-
rubric = row["scoring_rubric"]
|
| 47 |
-
if isinstance(rubric, str):
|
| 48 |
-
rubric = json.loads(rubric)
|
| 49 |
-
meta = row.get("metadata") or {}
|
| 50 |
-
if isinstance(meta, str):
|
| 51 |
-
try: meta = json.loads(meta)
|
| 52 |
-
except: meta = {}
|
| 53 |
-
tasks.append(EvalTask(
|
| 54 |
-
task_id=row["task_id"], pillar=row["pillar"],
|
| 55 |
-
sub_dimension=row["sub_dimension"], difficulty=row["difficulty"],
|
| 56 |
-
prompt=row["prompt"], context=row.get("context"),
|
| 57 |
-
expected_behavior=row.get("expected_behavior"),
|
| 58 |
-
scoring_rubric=rubric, metadata=meta,
|
| 59 |
-
))
|
| 60 |
-
return tasks
|
| 61 |
-
|
| 62 |
-
ALL_TASKS = load_tasks_from_parquet()
|
| 63 |
-
|
| 64 |
-
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 65 |
-
# PART 2: ALL Bench λͺ¨λΈ λͺ©λ‘ (HF Inference API μ§μ)
|
| 66 |
-
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 67 |
-
|
| 68 |
-
# HF Inference APIλ‘ νκ° κ°λ₯ν ALL Bench λ±μ¬ λͺ¨λΈ
|
| 69 |
-
HF_MODELS = {
|
| 70 |
-
# ββ Open-Source (HF Inference API) ββ
|
| 71 |
-
"Qwen3.5-397B": "Qwen/Qwen3.5-397B-A17B",
|
| 72 |
-
"Qwen3.5-122B": "Qwen/Qwen3.5-122B-A10B",
|
| 73 |
-
"Qwen3.5-27B": "Qwen/Qwen3.5-27B",
|
| 74 |
-
"Qwen3.5-35B": "Qwen/Qwen3.5-35B-A3B",
|
| 75 |
-
"Qwen3.5-9B": "Qwen/Qwen3.5-9B",
|
| 76 |
-
"Qwen3.5-4B": "Qwen/Qwen3.5-4B",
|
| 77 |
-
"DeepSeek V3.2": "deepseek-ai/DeepSeek-V3-0324",
|
| 78 |
-
"DeepSeek R1": "deepseek-ai/DeepSeek-R1",
|
| 79 |
-
"Llama 4 Scout": "meta-llama/Llama-4-Scout-17B-16E-Instruct",
|
| 80 |
-
"Llama 4 Maverick": "meta-llama/Llama-4-Maverick-17B-128E-Instruct",
|
| 81 |
-
"Phi-4": "microsoft/phi-4",
|
| 82 |
-
"Mistral Large 3": "mistralai/Mistral-Large-Instruct-2501",
|
| 83 |
-
"Qwen3-Next-80B": "Qwen/Qwen3-Next-80B-A3B-Thinking",
|
| 84 |
-
}
|
| 85 |
|
| 86 |
-
#
|
| 87 |
-
OPENAI_MODELS = {
|
| 88 |
-
"GPT-5.2": "gpt-5.2",
|
| 89 |
-
"GPT-5.4": "gpt-5.4",
|
| 90 |
-
"GPT-5.1": "gpt-5.1",
|
| 91 |
-
"GPT-5.3 Codex": "gpt-5.3-codex",
|
| 92 |
-
}
|
| 93 |
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
}
|
| 99 |
|
| 100 |
-
# ββββ
|
| 101 |
-
# PART 3: LLM νΈμΆ β HF Inference API + OpenAI
|
| 102 |
-
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 103 |
|
| 104 |
-
def
|
| 105 |
if not text: return text
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
text = re.sub(r'<reasoning>.*?</reasoning>', '', text, flags=re.DOTALL)
|
| 109 |
-
text = re.sub(r'<reflection>.*?</reflection>', '', text, flags=re.DOTALL)
|
| 110 |
return text.strip()
|
| 111 |
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
payload = {
|
| 122 |
-
"model": model_id,
|
| 123 |
-
"messages": messages,
|
| 124 |
-
"max_tokens": max_tokens,
|
| 125 |
-
"temperature": temperature,
|
| 126 |
-
"stream": False,
|
| 127 |
-
}
|
| 128 |
-
headers = {
|
| 129 |
-
"Content-Type": "application/json",
|
| 130 |
-
"Authorization": f"Bearer {api_key}",
|
| 131 |
-
}
|
| 132 |
-
|
| 133 |
for attempt in range(3):
|
| 134 |
try:
|
| 135 |
-
r = requests.post(
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
if r.status_code == 429:
|
| 140 |
-
time.sleep(5 * (attempt + 1)); continue
|
| 141 |
-
if r.status_code == 503:
|
| 142 |
-
# Model loading
|
| 143 |
-
time.sleep(10 * (attempt + 1)); continue
|
| 144 |
-
r.raise_for_status()
|
| 145 |
-
content = r.json()["choices"][0]["message"]["content"]
|
| 146 |
-
content = _strip_think_tags(content)
|
| 147 |
-
return content
|
| 148 |
-
except Exception as e:
|
| 149 |
-
if attempt < 2:
|
| 150 |
-
time.sleep(3 * (attempt + 1))
|
| 151 |
-
else:
|
| 152 |
-
return f"[API_ERROR] HF Inference: {e}"
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
def call_llm_openai(prompt, system="", api_key="", model="gpt-5.2",
|
| 156 |
-
max_tokens=4096, temperature=0.6, base_url="https://api.openai.com/v1"):
|
| 157 |
-
"""OpenAI-compatible API νΈμΆ (GPT, Claude λ±)"""
|
| 158 |
-
messages = []
|
| 159 |
-
if system:
|
| 160 |
-
messages.append({"role": "system", "content": system})
|
| 161 |
-
messages.append({"role": "user", "content": prompt})
|
| 162 |
-
|
| 163 |
-
payload = {
|
| 164 |
-
"model": model,
|
| 165 |
-
"messages": messages,
|
| 166 |
-
"max_tokens": max_tokens,
|
| 167 |
-
"temperature": temperature,
|
| 168 |
-
}
|
| 169 |
-
headers = {
|
| 170 |
-
"Content-Type": "application/json",
|
| 171 |
-
"Authorization": f"Bearer {api_key}",
|
| 172 |
-
}
|
| 173 |
-
|
| 174 |
-
for attempt in range(2):
|
| 175 |
-
try:
|
| 176 |
-
r = requests.post(
|
| 177 |
-
f"{base_url}/chat/completions",
|
| 178 |
-
headers=headers, json=payload, timeout=120,
|
| 179 |
-
)
|
| 180 |
-
if r.status_code == 429:
|
| 181 |
-
time.sleep(5 * (attempt + 1)); continue
|
| 182 |
r.raise_for_status()
|
| 183 |
-
|
| 184 |
-
content = _strip_think_tags(content)
|
| 185 |
-
return content
|
| 186 |
except Exception as e:
|
| 187 |
-
if attempt <
|
| 188 |
-
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
score_props = {}
|
| 208 |
-
for k in rubric_keys:
|
| 209 |
-
score_props[k] = {"type": "number", "enum": [0.0, 0.25, 0.5, 0.75, 1.0]}
|
| 210 |
-
return {
|
| 211 |
-
"type": "object",
|
| 212 |
-
"properties": {
|
| 213 |
-
"scores": {
|
| 214 |
-
"type": "object", "properties": score_props,
|
| 215 |
-
"required": list(rubric_keys), "additionalProperties": False,
|
| 216 |
-
},
|
| 217 |
-
"comment": {"type": "string"}
|
| 218 |
-
},
|
| 219 |
-
"required": ["scores", "comment"], "additionalProperties": False,
|
| 220 |
-
}
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
def call_judge_structured(prompt, system="", api_key="", model="gpt-5.2",
|
| 224 |
-
rubric_keys=None, temperature=0.1, max_tokens=4096):
|
| 225 |
-
if not rubric_keys:
|
| 226 |
-
return {"scores": {}, "comment": "루λΈλ¦ν€ μμ"}
|
| 227 |
-
messages = []
|
| 228 |
-
if system:
|
| 229 |
-
messages.append({"role": "system", "content": system})
|
| 230 |
-
messages.append({"role": "user", "content": prompt})
|
| 231 |
-
schema = _build_judge_schema(rubric_keys)
|
| 232 |
-
payload = {
|
| 233 |
-
"model": model, "max_completion_tokens": max_tokens,
|
| 234 |
-
"temperature": temperature, "messages": messages,
|
| 235 |
-
"response_format": {
|
| 236 |
-
"type": "json_schema",
|
| 237 |
-
"json_schema": {"name": "JudgeResult", "strict": True, "schema": schema}
|
| 238 |
-
}
|
| 239 |
-
}
|
| 240 |
-
headers = {"Content-Type": "application/json", "Authorization": f"Bearer {api_key}"}
|
| 241 |
-
|
| 242 |
for attempt in range(3):
|
| 243 |
try:
|
| 244 |
-
r = requests.post("https://api.openai.com/v1/chat/completions",
|
| 245 |
-
|
| 246 |
-
if r.status_code == 429:
|
| 247 |
-
time.sleep(5 * (attempt + 1)); continue
|
| 248 |
r.raise_for_status()
|
| 249 |
-
content = r.json()["choices"][0]["message"]["content"]
|
| 250 |
if not content:
|
| 251 |
-
if attempt < 2: time.sleep(
|
| 252 |
return None
|
| 253 |
-
if "<think>" in content:
|
| 254 |
-
content = re.sub(r'<think>.*?</think>', '', content, flags=re.DOTALL).strip()
|
| 255 |
data = json.loads(content)
|
| 256 |
-
if "scores" in data
|
| 257 |
for k in rubric_keys:
|
| 258 |
if k not in data["scores"]: data["scores"][k] = 0.5
|
| 259 |
-
return
|
| 260 |
-
except
|
| 261 |
-
if attempt < 2: time.sleep(
|
| 262 |
-
return None
|
| 263 |
-
except Exception:
|
| 264 |
-
if attempt < 2: time.sleep(3 * (attempt + 1)); continue
|
| 265 |
return None
|
| 266 |
return None
|
| 267 |
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
| 283 |
-
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
| 287 |
-
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
{
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
def parse_judge_response(text, rubric_keys):
|
| 302 |
-
"""6λ¨κ³ λ°©μ΄ νμ"""
|
| 303 |
-
if not text or text.startswith("[API_ERROR"):
|
| 304 |
-
return {"scores": {k: 0.0 for k in rubric_keys}, "comment": "APIμ€λ₯", "failed": True}
|
| 305 |
-
|
| 306 |
-
cleaned = _strip_think_tags(text)
|
| 307 |
-
cleaned = re.sub(r'```(?:json)?\s*', '', cleaned)
|
| 308 |
-
cleaned = re.sub(r'```\s*$', '', cleaned)
|
| 309 |
-
cleaned = cleaned.strip()
|
| 310 |
-
|
| 311 |
-
def _validate(scores):
|
| 312 |
-
result = {}
|
| 313 |
-
for k in rubric_keys:
|
| 314 |
-
v = scores.get(k)
|
| 315 |
-
if v is not None:
|
| 316 |
-
try: result[k] = min(max(float(v), 0.0), 1.0)
|
| 317 |
-
except: result[k] = 0.5
|
| 318 |
-
else: result[k] = 0.5
|
| 319 |
-
return result
|
| 320 |
-
|
| 321 |
-
# Pattern 1: standard JSON
|
| 322 |
-
try:
|
| 323 |
-
brace_depth = 0; start = -1
|
| 324 |
-
for i, c in enumerate(cleaned):
|
| 325 |
-
if c == '{':
|
| 326 |
-
if brace_depth == 0: start = i
|
| 327 |
-
brace_depth += 1
|
| 328 |
-
elif c == '}':
|
| 329 |
-
brace_depth -= 1
|
| 330 |
-
if brace_depth == 0 and start >= 0:
|
| 331 |
-
data = json.loads(cleaned[start:i+1])
|
| 332 |
-
if "scores" in data:
|
| 333 |
-
return {"scores": _validate(data["scores"]), "comment": data.get("comment", "")}
|
| 334 |
-
except: pass
|
| 335 |
-
|
| 336 |
-
# Pattern 2: regex
|
| 337 |
-
try:
|
| 338 |
-
m = re.search(r'"scores"\s*:\s*\{([^}]+)\}', cleaned, re.DOTALL)
|
| 339 |
-
if m:
|
| 340 |
-
pairs = re.findall(r'"([^"]+)"\s*:\s*([\d.]+)', '{' + m.group(1) + '}')
|
| 341 |
-
if pairs:
|
| 342 |
-
raw = {k: float(v) for k, v in pairs}
|
| 343 |
-
validated = _validate(raw)
|
| 344 |
-
if any(v != 0.5 for v in validated.values()):
|
| 345 |
-
return {"scores": validated, "comment": "ν¨ν΄2"}
|
| 346 |
-
except: pass
|
| 347 |
-
|
| 348 |
-
return {"scores": {k: 0.0 for k in rubric_keys}, "comment": "νμ±μ€ν¨", "failed": True}
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
def compute_weighted_score(scores, rubric):
|
| 352 |
-
return round(sum(scores.get(k, 0.5) * v["weight"] for k, v in rubric.items()) * 100, 2)
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 356 |
-
# PART 5: λ€μ€ λΌμ΄λ κ³Όμ μ€νκΈ°
|
| 357 |
-
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 358 |
-
|
| 359 |
-
def _run_mutual_verification(topic, api_key, model_id, api_type):
|
| 360 |
-
rounds = []
|
| 361 |
-
r1 = call_llm(f"[R1-μμ] '{topic}'μ λν΄ 500λ¨μ΄ λΆμ λ³΄κ³ μλ₯Ό μμ±νμΈμ.",
|
| 362 |
-
api_key=api_key, model_id=model_id, api_type=api_type)
|
| 363 |
-
rounds.append(f"[R1-μμ]\n{r1}")
|
| 364 |
-
r2 = call_llm(f"[R2-μκ·Ή] μλ λ³΄κ³ μλ₯Ό λμ² νκ² λΉννμΈμ.\n--- μλ¬Έ ---\n{r1[:2000]}",
|
| 365 |
-
api_key=api_key, model_id=model_id, api_type=api_type)
|
| 366 |
-
rounds.append(f"[R2-μκ·Ή]\n{r2}")
|
| 367 |
-
r3 = call_llm(f"[R3-μμ ] λΉνμ λ°μνμ¬ μμ νμΈμ.\n--- μλ¬Έ ---\n{r1[:1500]}\n--- λΉν ---\n{r2[:1500]}",
|
| 368 |
-
api_key=api_key, model_id=model_id, api_type=api_type)
|
| 369 |
-
rounds.append(f"[R3-μμ ]\n{r3}")
|
| 370 |
-
r4 = call_llm(f"[R4-λ©ν] 3λΌμ΄λ λ©ν λΆμ:\n--- R1 ---\n{r1[:800]}\n--- R2 ---\n{r2[:800]}\n--- R3 ---\n{r3[:800]}",
|
| 371 |
-
api_key=api_key, model_id=model_id, api_type=api_type)
|
| 372 |
-
rounds.append(f"[R4-λ©ν]\n{r4}")
|
| 373 |
-
return "\n\n".join(rounds)
|
| 374 |
-
|
| 375 |
-
|
| 376 |
-
def _run_feedback(prompt_json, api_key, model_id, api_type):
|
| 377 |
-
try: data = json.loads(prompt_json)
|
| 378 |
-
except: return call_llm(prompt_json, api_key=api_key, model_id=model_id, api_type=api_type)
|
| 379 |
-
topic = data.get("topic", "")
|
| 380 |
-
rounds_spec = data.get("rounds", [])
|
| 381 |
-
outputs, prev = [], ""
|
| 382 |
-
for i, rd in enumerate(rounds_spec):
|
| 383 |
-
instruction = rd.get("instruction", "")
|
| 384 |
-
feedback = rd.get("feedback")
|
| 385 |
-
if i == 0: p = f"'{topic}' β {instruction}."
|
| 386 |
-
elif feedback: p = f"νΌλλ°± λ°μ: {instruction}.\n--- μ΄μ ---\n{prev[:2000]}\n--- νΌλλ°± ---\n{feedback}"
|
| 387 |
-
else: p = f"{instruction}.\n--- μ΅μ’
---\n{prev[:2500]}"
|
| 388 |
-
resp = call_llm(p, api_key=api_key, model_id=model_id, api_type=api_type)
|
| 389 |
-
outputs.append(f"[R{i+1}]\n{resp}")
|
| 390 |
-
prev = resp
|
| 391 |
-
return "\n\n".join(outputs)
|
| 392 |
-
|
| 393 |
-
|
| 394 |
-
def execute_task(task, api_key, model_id, api_type):
|
| 395 |
-
"""λ¨μΌ LLM μμ νκ° (Proto-AGI OFF)"""
|
| 396 |
if task.sub_dimension == "mutual_verification":
|
| 397 |
-
|
| 398 |
-
return _run_mutual_verification(topic, api_key, model_id, api_type)
|
| 399 |
elif task.sub_dimension == "feedback_incorporation":
|
| 400 |
-
return
|
| 401 |
-
|
| 402 |
-
|
| 403 |
-
|
| 404 |
-
|
| 405 |
-
|
| 406 |
-
|
| 407 |
-
|
| 408 |
-
|
| 409 |
-
|
| 410 |
-
|
| 411 |
-
|
| 412 |
-
|
| 413 |
-
|
| 414 |
-
|
| 415 |
-
|
| 416 |
-
def
|
| 417 |
-
|
| 418 |
-
|
| 419 |
-
|
| 420 |
-
|
| 421 |
-
|
| 422 |
-
|
| 423 |
-
|
| 424 |
-
def save_final_scores(model_name, pillar_scores, aether_score, total_tasks, completed):
|
| 425 |
-
"""ALL Bench μ°λμ© final_scores.json μ
λ°μ΄νΈ"""
|
| 426 |
-
data = load_final_scores()
|
| 427 |
-
data["updated"] = datetime.now().isoformat()
|
| 428 |
-
data["models"][model_name] = {
|
| 429 |
-
"final_score": aether_score,
|
| 430 |
-
"pillar_scores": {p: round(s, 2) for p, s in pillar_scores.items()},
|
| 431 |
-
"total_tasks": total_tasks,
|
| 432 |
-
"completed_tasks": completed,
|
| 433 |
-
"evaluated_at": datetime.now().isoformat(),
|
| 434 |
-
"mode": "pure_llm",
|
| 435 |
-
}
|
| 436 |
-
with open(SCORES_FILE, "w") as f:
|
| 437 |
-
json.dump(data, f, indent=2, ensure_ascii=False)
|
| 438 |
-
return data
|
| 439 |
-
|
| 440 |
-
|
| 441 |
-
def upload_scores_to_hf(data):
|
| 442 |
-
"""final_scores.jsonμ HF Datasetμ μ
λ‘λ"""
|
| 443 |
-
hf_token = os.getenv("HF_TOKEN", "")
|
| 444 |
-
if not hf_token:
|
| 445 |
-
return "β οΈ HF_TOKEN λ―Έμ€μ "
|
| 446 |
try:
|
| 447 |
-
|
| 448 |
-
|
| 449 |
-
|
| 450 |
-
|
| 451 |
-
|
| 452 |
-
|
| 453 |
-
|
| 454 |
-
|
| 455 |
-
|
| 456 |
-
|
| 457 |
-
|
| 458 |
-
return f"β μ
λ‘λ μ€ν¨: {e}"
|
| 459 |
-
|
| 460 |
-
|
| 461 |
-
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 462 |
-
# PART 7: 체ν¬ν¬μΈνΈ DB
|
| 463 |
-
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 464 |
-
|
| 465 |
-
DB_PATH = "final_bench_eval.db"
|
| 466 |
-
|
| 467 |
-
def _init_db():
|
| 468 |
-
conn = sqlite3.connect(DB_PATH)
|
| 469 |
-
conn.execute("""CREATE TABLE IF NOT EXISTS eval_results (
|
| 470 |
-
run_id TEXT, task_id TEXT, model_response TEXT, judge_response TEXT,
|
| 471 |
-
weighted_score REAL, timestamp REAL,
|
| 472 |
-
PRIMARY KEY (run_id, task_id))""")
|
| 473 |
-
conn.commit(); conn.close()
|
| 474 |
-
|
| 475 |
-
def _make_run_id(model): return hashlib.md5(model.encode()).hexdigest()[:12]
|
| 476 |
-
|
| 477 |
-
def _get_cached(run_id, task_id):
|
| 478 |
-
conn = sqlite3.connect(DB_PATH)
|
| 479 |
-
cur = conn.execute("SELECT model_response, judge_response, weighted_score FROM eval_results WHERE run_id=? AND task_id=?", (run_id, task_id))
|
| 480 |
-
row = cur.fetchone(); conn.close()
|
| 481 |
-
return row
|
| 482 |
-
|
| 483 |
-
def _save_result(run_id, task_id, response, judge_resp, score):
|
| 484 |
-
conn = sqlite3.connect(DB_PATH)
|
| 485 |
-
conn.execute("INSERT OR REPLACE INTO eval_results VALUES (?,?,?,?,?,?)",
|
| 486 |
-
(run_id, task_id, response, judge_resp, score, time.time()))
|
| 487 |
-
conn.commit(); conn.close()
|
| 488 |
-
|
| 489 |
-
def _load_all(run_id):
|
| 490 |
-
conn = sqlite3.connect(DB_PATH)
|
| 491 |
-
cur = conn.execute("SELECT task_id, model_response, judge_response, weighted_score FROM eval_results WHERE run_id=?", (run_id,))
|
| 492 |
-
rows = cur.fetchall(); conn.close()
|
| 493 |
-
return {r[0]: {"response": r[1], "judge": r[2], "score": r[3]} for r in rows}
|
| 494 |
-
|
| 495 |
-
def _clear_run(run_id):
|
| 496 |
-
conn = sqlite3.connect(DB_PATH)
|
| 497 |
-
conn.execute("DELETE FROM eval_results WHERE run_id=?", (run_id,))
|
| 498 |
-
conn.commit(); conn.close()
|
| 499 |
-
|
| 500 |
-
_init_db()
|
| 501 |
-
|
| 502 |
-
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 503 |
-
# PART 8: CSV μμ± + HF μ
λ‘λ
|
| 504 |
-
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 505 |
-
|
| 506 |
-
def generate_csv(results, model_name):
|
| 507 |
-
output = io.StringIO()
|
| 508 |
-
writer = csv.writer(output)
|
| 509 |
-
writer.writerow(["task_id","pillar","sub_dimension","difficulty","model",
|
| 510 |
-
"weighted_score","judge_comment","rubric_scores_json","timestamp"])
|
| 511 |
-
task_map = {t.task_id: t for t in ALL_TASKS}
|
| 512 |
-
for tid, data in sorted(results.items()):
|
| 513 |
-
task = task_map.get(tid)
|
| 514 |
-
if not task: continue
|
| 515 |
-
jd = {}
|
| 516 |
-
try: jd = json.loads(data["judge"]) if isinstance(data["judge"], str) else (data["judge"] or {})
|
| 517 |
-
except: pass
|
| 518 |
-
score = data["score"]
|
| 519 |
-
comment = (jd.get("comment","") if isinstance(jd,dict) else "")[:200]
|
| 520 |
-
if score < 0:
|
| 521 |
-
score = -1
|
| 522 |
-
if not comment.startswith("JUDGE_FAILED"): comment = f"JUDGE_FAILED:{comment}"
|
| 523 |
-
writer.writerow([
|
| 524 |
-
tid, task.pillar, task.sub_dimension, task.difficulty, model_name,
|
| 525 |
-
score, comment,
|
| 526 |
-
json.dumps(jd.get("scores",{}) if isinstance(jd,dict) else {}, ensure_ascii=False),
|
| 527 |
-
datetime.now().isoformat(),
|
| 528 |
-
])
|
| 529 |
-
return output.getvalue()
|
| 530 |
-
|
| 531 |
-
|
| 532 |
-
def upload_csv_to_hf(csv_content, model_name):
|
| 533 |
-
hf_token = os.getenv("HF_TOKEN", "")
|
| 534 |
-
if not hf_token:
|
| 535 |
-
return "β οΈ HF_TOKEN λ―Έμ€μ "
|
| 536 |
try:
|
| 537 |
from huggingface_hub import HfApi
|
| 538 |
-
api = HfApi(token=
|
| 539 |
-
|
| 540 |
-
|
| 541 |
-
|
| 542 |
-
|
| 543 |
-
|
| 544 |
-
path_or_fileobj=csv_content.encode("utf-8"),
|
| 545 |
-
path_in_repo=filename, repo_id=repo_id, repo_type="dataset",
|
| 546 |
-
commit_message=f"FINAL Bench eval: {safe_model}",
|
| 547 |
-
)
|
| 548 |
-
return f"β
CSV μ
λ‘λ: {filename}"
|
| 549 |
-
except Exception as e:
|
| 550 |
-
return f"β CSV μ
λ‘λ μ€ν¨: {e}"
|
| 551 |
-
|
| 552 |
-
|
| 553 |
-
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 554 |
-
# PART 9: HTML λΉλ
|
| 555 |
-
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 556 |
-
|
| 557 |
-
CSS = """<style>
|
| 558 |
-
.eval-table{width:100%;border-collapse:collapse;font-size:0.85em}
|
| 559 |
-
.eval-table th{background:#f0f4f8;padding:8px;text-align:left;border-bottom:2px solid #ccc}
|
| 560 |
-
.eval-table td{padding:6px 8px;border-bottom:1px solid #eee}
|
| 561 |
-
.score-bar{background:#e0e0e0;border-radius:8px;height:18px;overflow:hidden;min-width:80px}
|
| 562 |
-
.score-fill{height:100%;border-radius:8px;transition:width .4s}
|
| 563 |
-
.summary-card{background:linear-gradient(135deg,#1a1a2e,#16213e);border-radius:14px;padding:20px;color:#fff;margin:8px 0}
|
| 564 |
-
.pillar-row{display:flex;align-items:center;gap:10px;margin:6px 0}
|
| 565 |
-
.pillar-bar{flex:1;background:#333;border-radius:6px;height:16px;overflow:hidden}
|
| 566 |
-
.pillar-fill{height:100%;border-radius:6px}
|
| 567 |
-
.progress-bar{background:#e0e0e0;border-radius:8px;height:22px;margin:12px 0;overflow:hidden}
|
| 568 |
-
.progress-fill{height:100%;border-radius:8px;background:linear-gradient(90deg,#6366f1,#4caf50)}
|
| 569 |
-
</style>"""
|
| 570 |
-
|
| 571 |
-
def _sc(s):
|
| 572 |
-
if s >= 80: return "#4caf50"
|
| 573 |
-
if s >= 60: return "#ff9800"
|
| 574 |
-
return "#f44336"
|
| 575 |
-
|
| 576 |
-
def _build_progress_table(results, tasks):
|
| 577 |
-
rows = ""
|
| 578 |
-
for t in tasks:
|
| 579 |
-
info = PILLAR_INFO.get(t.pillar, {})
|
| 580 |
-
if t.task_id in results:
|
| 581 |
-
s = results[t.task_id]["score"]
|
| 582 |
-
if s < 0:
|
| 583 |
-
rows += f'<tr style="background:#fff3e0"><td>{t.task_id}</td><td>{info.get("icon","")} {info.get("name","")}</td><td>{t.sub_dimension}</td><td>{t.difficulty}</td><td style="color:#ff9800">β Judgeμ€ν¨</td><td>β</td></tr>'
|
| 584 |
-
continue
|
| 585 |
-
c = _sc(s)
|
| 586 |
-
cls = "color:#2e7d32;font-weight:700" if s>=70 else "color:#c62828;font-weight:700"
|
| 587 |
-
rows += f'<tr><td>{t.task_id}</td><td>{info.get("icon","")} {info.get("name","")}</td><td>{t.sub_dimension}</td><td>{t.difficulty}</td><td><div class="score-bar"><div class="score-fill" style="width:{min(s,100)}%;background:{c}"></div></div></td><td style="{cls}">{s:.1f}</td></tr>'
|
| 588 |
-
else:
|
| 589 |
-
rows += f'<tr style="opacity:0.4"><td>{t.task_id}</td><td>{info.get("icon","")}</td><td>{t.sub_dimension}</td><td>{t.difficulty}</td><td>β³</td><td>β</td></tr>'
|
| 590 |
-
return f'{CSS}<table class="eval-table"><thead><tr><th>ID</th><th>κΈ°λ₯</th><th>μ°¨μ</th><th>λμ΄λ</th><th>μ μ</th><th>κ°</th></tr></thead><tbody>{rows}</tbody></table>'
|
| 591 |
-
|
| 592 |
-
def _build_summary(results, tasks, pillar_scores, aether, model_name, hf_status):
|
| 593 |
-
if aether >= 80: grade = "A (AGI-Level)"
|
| 594 |
-
elif aether >= 70: grade = "B+ (Near-AGI)"
|
| 595 |
-
elif aether >= 60: grade = "B (Advanced)"
|
| 596 |
-
elif aether >= 50: grade = "C+ (Competent)"
|
| 597 |
-
else: grade = "C-F"
|
| 598 |
-
ph = ""
|
| 599 |
-
for p, info in PILLAR_INFO.items():
|
| 600 |
-
s = pillar_scores.get(p, 0)
|
| 601 |
-
c = _sc(s); w = int(info["weight"] * 100)
|
| 602 |
-
ph += f'<div class="pillar-row"><span style="width:130px">{info["icon"]} {info["name"]} ({w}%)</span><div class="pillar-bar"><div class="pillar-fill" style="width:{min(s,100)}%;background:{c}"></div></div><span style="width:55px;text-align:right;font-weight:700;color:{c}">{s:.1f}</span></div>'
|
| 603 |
-
done = sum(1 for t in tasks if t.task_id in results)
|
| 604 |
-
jf = sum(1 for t in tasks if t.task_id in results and results[t.task_id]["score"] < 0)
|
| 605 |
-
return f"""{CSS}<div class="summary-card">
|
| 606 |
-
<h2 style="margin:0;font-size:1.6em;text-align:center">𧬠FINAL Score: {aether:.1f} / 100</h2>
|
| 607 |
-
<h3 style="margin:4px 0;text-align:center;color:#aaa">Grade: {grade}</h3>
|
| 608 |
-
<p style="text-align:center;color:#888">Model: {model_name} | {done}κ° μλ£{f' Β· βJudgeμ€ν¨ {jf}건' if jf else ''}</p>
|
| 609 |
-
<hr style="border-color:#333;margin:12px 0"><h4 style="color:#aaa;margin:8px 0">κΈ°λ₯λ³ μ μ</h4>{ph}
|
| 610 |
-
<hr style="border-color:#333;margin:12px 0"><p style="font-size:0.85em;color:#aaa">{hf_status}</p></div>"""
|
| 611 |
-
|
| 612 |
-
|
| 613 |
-
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 614 |
-
# PART 10: λ³λ ¬ νκ° μμ§ + λ°±κ·ΈλΌμ΄λ μ€λ λ
|
| 615 |
-
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 616 |
|
| 617 |
-
|
| 618 |
|
| 619 |
-
def
|
| 620 |
try:
|
| 621 |
-
|
| 622 |
-
if
|
| 623 |
-
|
| 624 |
-
with
|
| 625 |
-
|
| 626 |
-
|
| 627 |
-
|
| 628 |
-
|
| 629 |
-
|
| 630 |
-
|
| 631 |
-
|
| 632 |
-
|
| 633 |
-
|
| 634 |
-
|
| 635 |
-
|
| 636 |
-
|
| 637 |
-
|
| 638 |
-
|
| 639 |
-
|
| 640 |
-
|
| 641 |
-
|
| 642 |
-
weighted = -1.0
|
| 643 |
-
else:
|
| 644 |
-
weighted = compute_weighted_score(judge_data["scores"], task.scoring_rubric)
|
| 645 |
-
with state["lock"]: state["parse_ok"] += 1
|
| 646 |
-
|
| 647 |
-
judge_json = json.dumps(judge_data, ensure_ascii=False)
|
| 648 |
-
_save_result(run_id, task.task_id, response, judge_json, weighted)
|
| 649 |
-
|
| 650 |
-
with state["lock"]:
|
| 651 |
-
state["done"] += 1
|
| 652 |
-
info = PILLAR_INFO.get(task.pillar, {})
|
| 653 |
-
state["active"].append(f'{info.get("icon","")} {task.task_id}')
|
| 654 |
-
if len(state["active"]) > 10: state["active"] = state["active"][-10:]
|
| 655 |
-
|
| 656 |
-
return task.task_id, {"response": response, "judge": judge_json, "score": weighted}
|
| 657 |
-
|
| 658 |
except Exception as e:
|
| 659 |
-
|
| 660 |
-
|
| 661 |
-
|
| 662 |
-
return task.task_id, {"response": f"[ERROR] {e}", "judge": "{}", "score": 0}
|
| 663 |
-
|
| 664 |
-
|
| 665 |
-
# ββ κΈλ‘λ² μν ββ
|
| 666 |
-
_STATE = {
|
| 667 |
-
"running": False, "stop_requested": False, "finished": False,
|
| 668 |
-
"run_id": "", "model": "", "done": 0, "total": 0, "cached": 0,
|
| 669 |
-
"errors": [], "active": [], "parse_ok": 0, "parse_fail": 0,
|
| 670 |
-
"start_time": 0, "results": {}, "tasks": [],
|
| 671 |
-
"pillar_done": {}, "pillar_total": {},
|
| 672 |
-
"n_workers": 5, "lock": threading.Lock(),
|
| 673 |
-
"message": "", "csv_path": None, "hf_status": "",
|
| 674 |
-
}
|
| 675 |
|
|
|
|
| 676 |
|
| 677 |
-
|
| 678 |
-
|
| 679 |
-
|
| 680 |
-
_STATE.update({
|
| 681 |
-
"running": False, "stop_requested": False, "finished": False,
|
| 682 |
-
"done": 0, "cached": 0, "errors": [], "active": [],
|
| 683 |
-
"parse_ok": 0, "parse_fail": 0, "start_time": 0,
|
| 684 |
-
"results": {}, "tasks": [], "pillar_done": {}, "pillar_total": {},
|
| 685 |
-
"message": "", "csv_path": None, "hf_status": "",
|
| 686 |
-
})
|
| 687 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 688 |
|
| 689 |
-
def
|
| 690 |
-
api_type, tasks, run_id, n_workers):
|
| 691 |
-
global _STATE
|
| 692 |
try:
|
| 693 |
-
|
| 694 |
-
|
| 695 |
-
|
| 696 |
-
|
| 697 |
-
pillar_tasks = {}
|
| 698 |
-
for t in pending:
|
| 699 |
-
pillar_tasks.setdefault(t.pillar, []).append(t)
|
| 700 |
-
|
| 701 |
-
with _STATE["lock"]:
|
| 702 |
-
_STATE["results"] = results; _STATE["cached"] = cached
|
| 703 |
-
_STATE["total"] = len(tasks)
|
| 704 |
-
_STATE["pillar_total"] = {p: len(ts) for p, ts in pillar_tasks.items()}
|
| 705 |
-
_STATE["pillar_done"] = {p: 0 for p in pillar_tasks}
|
| 706 |
-
_STATE["start_time"] = time.time()
|
| 707 |
-
|
| 708 |
if not pending:
|
| 709 |
-
with
|
| 710 |
-
|
| 711 |
-
|
| 712 |
-
|
| 713 |
-
|
| 714 |
-
|
| 715 |
-
|
| 716 |
-
|
| 717 |
-
|
| 718 |
-
futures = {}
|
| 719 |
-
for task in pending:
|
| 720 |
-
if _STATE["stop_requested"]: break
|
| 721 |
-
fut = executor.submit(_eval_single, task, run_id, api_key, judge_key,
|
| 722 |
-
model_id, judge_model, api_type, _STATE)
|
| 723 |
-
futures[fut] = task
|
| 724 |
-
|
| 725 |
-
completed = set()
|
| 726 |
-
while len(completed) < len(futures):
|
| 727 |
-
if _STATE["stop_requested"]:
|
| 728 |
-
with _STATE["lock"]:
|
| 729 |
-
_STATE["message"] = "βΉοΈ μ€λ¨λ¨"; _STATE["running"] = False; _STATE["finished"] = True
|
| 730 |
return
|
| 731 |
-
for
|
| 732 |
-
if
|
| 733 |
-
if
|
| 734 |
-
|
| 735 |
try:
|
| 736 |
-
tid,
|
| 737 |
-
with
|
| 738 |
-
_STATE["results"][tid] = data
|
| 739 |
-
_STATE["pillar_done"][futures[fut].pillar] = \
|
| 740 |
-
_STATE["pillar_done"].get(futures[fut].pillar, 0) + 1
|
| 741 |
except: pass
|
| 742 |
time.sleep(0.5)
|
| 743 |
-
|
| 744 |
-
|
| 745 |
-
results = dict(_STATE["results"])
|
| 746 |
-
_finalize(tasks, results, model_display)
|
| 747 |
-
|
| 748 |
except Exception as e:
|
| 749 |
-
with
|
| 750 |
-
_STATE["message"] = f"β μ€λ₯: {str(e)[:100]}"
|
| 751 |
-
_STATE["running"] = False; _STATE["finished"] = True
|
| 752 |
-
|
| 753 |
|
| 754 |
-
def
|
| 755 |
-
|
| 756 |
-
pillar_scores = {}
|
| 757 |
for p in PILLAR_INFO:
|
| 758 |
-
|
| 759 |
-
valid
|
| 760 |
-
|
| 761 |
-
|
| 762 |
-
|
| 763 |
-
|
| 764 |
-
|
| 765 |
-
|
| 766 |
-
|
| 767 |
-
|
| 768 |
-
|
| 769 |
-
|
| 770 |
-
|
| 771 |
-
|
| 772 |
-
|
| 773 |
-
|
| 774 |
-
|
| 775 |
-
|
| 776 |
-
|
| 777 |
-
|
| 778 |
-
|
| 779 |
-
|
| 780 |
-
with
|
| 781 |
-
|
| 782 |
-
|
| 783 |
-
|
| 784 |
-
|
| 785 |
-
|
| 786 |
-
def _start_eval(model_choice, api_type, eval_api_key, judge_api_key, judge_model,
|
| 787 |
-
pillar_filter, diff_filter, max_tasks, n_workers, fresh_start):
|
| 788 |
-
global _STATE
|
| 789 |
-
if _STATE["running"]:
|
| 790 |
-
return "β οΈ μ΄λ―Έ μ§ν μ€"
|
| 791 |
-
|
| 792 |
-
eval_api_key = (eval_api_key or "").strip() or os.getenv("HF_TOKEN", "")
|
| 793 |
-
judge_api_key = (judge_api_key or "").strip() or os.getenv("OPENAI_API_KEY", "")
|
| 794 |
-
if not eval_api_key: return "β API Keyλ₯Ό μ
λ ₯νμΈμ."
|
| 795 |
-
if not judge_api_key: return "β Judge API Key (OpenAI)λ₯Ό μ
λ ₯νμΈμ."
|
| 796 |
-
|
| 797 |
-
# Resolve model ID
|
| 798 |
-
if api_type == "HuggingFace Inference":
|
| 799 |
-
model_id = HF_MODELS.get(model_choice, model_choice)
|
| 800 |
-
at = "hf"
|
| 801 |
-
else:
|
| 802 |
-
model_id = OPENAI_MODELS.get(model_choice, model_choice)
|
| 803 |
-
at = "openai"
|
| 804 |
-
|
| 805 |
-
tasks = ALL_TASKS[:]
|
| 806 |
-
if pillar_filter != "μ 체":
|
| 807 |
-
tasks = [t for t in tasks if t.pillar == pillar_filter]
|
| 808 |
-
if diff_filter != "μ 체":
|
| 809 |
-
tasks = [t for t in tasks if t.difficulty == diff_filter]
|
| 810 |
-
tasks = tasks[:int(max_tasks)]
|
| 811 |
-
|
| 812 |
-
run_id = _make_run_id(model_id + "_pure")
|
| 813 |
-
if fresh_start:
|
| 814 |
-
_clear_run(run_id)
|
| 815 |
-
|
| 816 |
-
_reset_state()
|
| 817 |
-
with _STATE["lock"]:
|
| 818 |
-
_STATE["running"] = True; _STATE["run_id"] = run_id
|
| 819 |
-
_STATE["model"] = model_choice; _STATE["tasks"] = tasks
|
| 820 |
-
_STATE["total"] = len(tasks); _STATE["n_workers"] = int(n_workers)
|
| 821 |
-
_STATE["message"] = "π μ€λΉ μ€..."
|
| 822 |
-
|
| 823 |
-
thread = threading.Thread(
|
| 824 |
-
target=_bg_evaluate,
|
| 825 |
-
args=(eval_api_key, judge_api_key, model_id, model_choice, judge_model,
|
| 826 |
-
at, tasks, run_id, int(n_workers)),
|
| 827 |
-
daemon=True)
|
| 828 |
-
thread.start()
|
| 829 |
-
return f"β‘ {model_choice} νκ° μμ ({len(tasks)}κ³Όμ , {int(n_workers)}μ컀)"
|
| 830 |
-
|
| 831 |
|
| 832 |
def _stop():
|
| 833 |
-
|
| 834 |
-
if _STATE["running"]:
|
| 835 |
-
_STATE["stop_requested"] = True
|
| 836 |
-
return "βΉοΈ μ€λ¨ μμ²"
|
| 837 |
return "βΉοΈ μ€ν μ€ μλ"
|
| 838 |
|
|
|
|
| 839 |
|
| 840 |
-
|
| 841 |
-
|
| 842 |
-
|
| 843 |
-
|
| 844 |
-
|
| 845 |
-
|
| 846 |
-
|
| 847 |
-
|
| 848 |
-
|
|
|
|
|
|
|
| 849 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 850 |
# Progress
|
| 851 |
-
if
|
| 852 |
-
|
| 853 |
-
pct = min(int(
|
| 854 |
-
|
| 855 |
-
eta = int((
|
| 856 |
-
|
| 857 |
-
|
| 858 |
-
|
| 859 |
-
|
| 860 |
-
|
| 861 |
-
|
| 862 |
-
|
| 863 |
-
|
| 864 |
-
|
| 865 |
-
|
| 866 |
-
|
| 867 |
-
|
| 868 |
-
|
| 869 |
-
|
| 870 |
-
|
| 871 |
-
|
| 872 |
-
|
| 873 |
-
|
| 874 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 875 |
for p in PILLAR_INFO:
|
| 876 |
-
|
| 877 |
-
valid
|
| 878 |
-
|
| 879 |
-
|
| 880 |
-
|
| 881 |
-
|
| 882 |
-
|
| 883 |
-
|
| 884 |
-
|
| 885 |
-
|
| 886 |
-
|
| 887 |
-
|
| 888 |
-
# ββββ
|
| 889 |
-
|
| 890 |
-
|
| 891 |
-
|
| 892 |
-
|
| 893 |
-
|
| 894 |
-
|
| 895 |
-
|
| 896 |
-
|
| 897 |
-
HEADER_HTML = """
|
| 898 |
-
<div style="text-align:center;padding:16px 0;">
|
| 899 |
-
<h1 style="margin:0;font-size:1.8em;">𧬠FINAL Bench Auto-Evaluator v1.0</h1>
|
| 900 |
-
<h2 style="margin:4px 0;color:#555;font-size:1.05em;">ALL Bench μ°λ Β· FINAL Score μλ μΈ‘μ </h2>
|
| 901 |
-
<p style="color:#888;font-size:0.88em;max-width:700px;margin:8px auto;">
|
| 902 |
-
220 Tasks Β· 5 Pillars Β· 21 Sub-dimensions Β· HAR Metric<br>
|
| 903 |
-
π‘ <b>HF Inference API</b>: Qwen, DeepSeek, Llama, Phi, Mistral λ± μ€νμμ€<br>
|
| 904 |
-
π <b>OpenAI API</b>: GPT-5.x μ리μ¦<br>
|
| 905 |
-
βοΈ <b>Judge</b>: OpenAI GPT-5.2 Structured Output Β· π κ²°κ³Ό β <code>final_scores.json</code> β ALL Bench μλ λ°μ
|
| 906 |
-
</p>
|
| 907 |
-
</div>"""
|
| 908 |
-
|
| 909 |
-
PILLAR_CHOICES = ["μ 체"] + list(PILLAR_INFO.keys())
|
| 910 |
-
DIFF_CHOICES = ["μ 체", "expert", "frontier"]
|
| 911 |
-
|
| 912 |
|
| 913 |
def create_app():
|
| 914 |
with gr.Blocks(title="FINAL Bench Auto-Evaluator", theme=gr.themes.Soft(),
|
| 915 |
css=".gradio-container{max-width:1100px !important}") as app:
|
| 916 |
-
gr.HTML(
|
| 917 |
-
|
| 918 |
-
with gr.Row():
|
| 919 |
-
api_type = gr.Radio(
|
| 920 |
-
["HuggingFace Inference", "OpenAI Compatible"],
|
| 921 |
-
value="HuggingFace Inference", label="π‘ API μ ν", scale=2)
|
| 922 |
-
model_choice = gr.Dropdown(
|
| 923 |
-
choices=list(HF_MODELS.keys()),
|
| 924 |
-
value=list(HF_MODELS.keys())[0],
|
| 925 |
-
label="π€ νκ° λμ λͺ¨λΈ", scale=3, allow_custom_value=True)
|
| 926 |
-
|
| 927 |
-
api_type.change(_update_model_choices, [api_type], [model_choice])
|
| 928 |
-
|
| 929 |
with gr.Row():
|
| 930 |
-
|
| 931 |
-
|
| 932 |
-
|
| 933 |
-
|
| 934 |
-
|
| 935 |
-
label="βοΈ Judge API Key (OpenAI GPT-5.2)",
|
| 936 |
-
type="password", placeholder="sk-...",
|
| 937 |
-
value=os.getenv("OPENAI_API_KEY", ""), scale=3)
|
| 938 |
-
|
| 939 |
with gr.Row():
|
| 940 |
-
|
| 941 |
-
|
| 942 |
-
|
| 943 |
-
|
| 944 |
-
|
| 945 |
-
|
| 946 |
-
with gr.Row():
|
| 947 |
-
start_btn = gr.Button("βΆοΈ νκ° μμ (μ΄μ΄νκΈ°)", variant="primary", size="lg", scale=2)
|
| 948 |
-
fresh_btn = gr.Button("π μλ‘ μμ", variant="secondary", size="lg", scale=2)
|
| 949 |
-
stop_btn = gr.Button("βΉοΈ μ€λ¨", variant="stop", size="lg", scale=1)
|
| 950 |
-
|
| 951 |
-
status_msg = gr.Textbox(label="μν", interactive=False, max_lines=1)
|
| 952 |
-
|
| 953 |
-
# ββ Existing scores display ββ
|
| 954 |
-
with gr.Accordion("π κΈ°μ‘΄ FINAL Score κ²°κ³Ό", open=False):
|
| 955 |
-
scores_display = gr.JSON(label="final_scores.json", value=load_final_scores())
|
| 956 |
-
|
| 957 |
with gr.Tabs():
|
| 958 |
-
with gr.Tab("π μ§ν"):
|
| 959 |
-
|
| 960 |
-
with gr.Tab("
|
| 961 |
-
|
| 962 |
-
with gr.Tab("π μ΅μ’
"):
|
| 963 |
-
summary_html = gr.HTML()
|
| 964 |
-
with gr.Tab("πΎ CSV"):
|
| 965 |
-
csv_file = gr.File(label="νκ° κ²°κ³Ό CSV")
|
| 966 |
-
|
| 967 |
-
# Timer polling
|
| 968 |
timer = gr.Timer(value=2, active=True)
|
| 969 |
-
timer.tick(fn=_poll, outputs=[
|
| 970 |
-
|
| 971 |
-
|
| 972 |
-
|
| 973 |
-
|
| 974 |
-
start_btn.click(
|
| 975 |
-
fn=lambda *args: _start_eval(*args, fresh_start=False),
|
| 976 |
-
inputs=all_inputs, outputs=[status_msg])
|
| 977 |
-
fresh_btn.click(
|
| 978 |
-
fn=lambda *args: _start_eval(*args, fresh_start=True),
|
| 979 |
-
inputs=all_inputs, outputs=[status_msg])
|
| 980 |
-
stop_btn.click(fn=_stop, outputs=[status_msg])
|
| 981 |
-
|
| 982 |
-
gr.Markdown("""---
|
| 983 |
-
<center>FINAL Bench Auto-Evaluator v1.0 Β· Apache 2.0 Β· Ginigen AI (μ§λμ AI)<br>
|
| 984 |
-
π‘ HF Inference API + βοΈ OpenAI Structured Judge<br>
|
| 985 |
-
π κ²°κ³Ό β <code>final_scores.json</code> β ALL Bench Leaderboard μλ μ°λ</center>""")
|
| 986 |
-
|
| 987 |
return app
|
| 988 |
|
| 989 |
-
|
| 990 |
-
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 991 |
-
# MAIN
|
| 992 |
-
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 993 |
-
|
| 994 |
if __name__ == "__main__":
|
| 995 |
stats = {}
|
| 996 |
-
for t in ALL_TASKS:
|
| 997 |
-
|
| 998 |
-
|
| 999 |
-
|
| 1000 |
-
|
| 1001 |
-
|
| 1002 |
-
print(f" π‘ HF Models: {len(HF_MODELS)} | π OpenAI Models: {len(OPENAI_MODELS)}")
|
| 1003 |
-
|
| 1004 |
app = create_app()
|
| 1005 |
app.queue(default_concurrency_limit=2)
|
| 1006 |
app.launch(server_name="0.0.0.0", server_port=7860, ssr_mode=False)
|
|
|
|
| 1 |
"""
|
| 2 |
+
FINAL Bench Auto-Evaluator v1.0
|
| 3 |
+
================================
|
| 4 |
+
FINAL Bench 100λ¬Έμ x HF Inference API -> GPT-5.2 Judge -> final_scores.json
|
| 5 |
|
| 6 |
+
- μν λ¬Έμ : FINAL-Bench/Metacognitive (HuggingFace Dataset)
|
| 7 |
+
- μν μμμ: ALL Bench λ±μ¬ HF Inference API λͺ¨λΈ
|
| 8 |
+
- μ¬ν: GPT-5.2 (os.getenv("OPENAI_API_KEY"))
|
| 9 |
+
- μΆλ ₯: final_scores.json -> ALL Bench Metacog μ»¬λΌ μλ λ°μ
|
| 10 |
|
| 11 |
+
Author: Ginigen AI Β· FINAL-Bench Β· Apache 2.0
|
|
|
|
| 12 |
"""
|
| 13 |
|
| 14 |
+
import json, os, time, csv, io, re, hashlib, sqlite3, threading
|
| 15 |
from datetime import datetime
|
| 16 |
from dataclasses import dataclass, field, asdict
|
| 17 |
+
from typing import Dict, Optional
|
| 18 |
+
from concurrent.futures import ThreadPoolExecutor
|
| 19 |
import requests
|
| 20 |
import numpy as np
|
|
|
|
| 21 |
import gradio as gr
|
| 22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
PILLAR_INFO = {
|
| 24 |
+
"P1_Emergence": {"name": "μ°½λ°μ±", "icon": "β¦", "color": "#FF6B35", "weight": 0.20},
|
| 25 |
+
"P2_Metacognition": {"name": "λ©νμΈμ§", "icon": "β", "color": "#7B2FF7", "weight": 0.25},
|
| 26 |
+
"P3_SelfEvolution": {"name": "μκ°μ§ν", "icon": "β", "color": "#00B4D8", "weight": 0.15},
|
| 27 |
+
"P4_Orchestration": {"name": "λ€μ€μ§λ₯", "icon": "β¬", "color": "#2EC4B6", "weight": 0.15},
|
| 28 |
+
"P5_SynergyAntagonism": {"name": "μμμκ·Ή", "icon": "β―", "color": "#E63946", "weight": 0.25},
|
| 29 |
}
|
| 30 |
|
| 31 |
@dataclass
|
|
|
|
| 33 |
task_id: str; pillar: str; sub_dimension: str; difficulty: str
|
| 34 |
prompt: str; context: Optional[str] = None; expected_behavior: Optional[str] = None
|
| 35 |
scoring_rubric: Dict = field(default_factory=dict); metadata: Dict = field(default_factory=dict)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
+
# ββ FINAL Bench 100λ¬Έμ λ‘λ ββ
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
+
def load_tasks():
|
| 40 |
+
"""FINAL-Bench/Metacognitive HF Datasetμμ 100λ¬Έμ λ‘λ"""
|
| 41 |
+
try:
|
| 42 |
+
from datasets import load_dataset
|
| 43 |
+
ds = load_dataset("FINAL-Bench/Metacognitive", split="train")
|
| 44 |
+
tasks = []
|
| 45 |
+
for row in ds:
|
| 46 |
+
rubric = row.get("scoring_rubric", {})
|
| 47 |
+
if isinstance(rubric, str):
|
| 48 |
+
try: rubric = json.loads(rubric)
|
| 49 |
+
except: rubric = {}
|
| 50 |
+
meta = row.get("metadata") or {}
|
| 51 |
+
if isinstance(meta, str):
|
| 52 |
+
try: meta = json.loads(meta)
|
| 53 |
+
except: meta = {}
|
| 54 |
+
tasks.append(EvalTask(
|
| 55 |
+
task_id=row["task_id"], pillar=row["pillar"],
|
| 56 |
+
sub_dimension=row["sub_dimension"], difficulty=row["difficulty"],
|
| 57 |
+
prompt=row["prompt"], context=row.get("context"),
|
| 58 |
+
expected_behavior=row.get("expected_behavior"),
|
| 59 |
+
scoring_rubric=rubric, metadata=meta))
|
| 60 |
+
print(f"β
FINAL Bench: {len(tasks)}λ¬Έμ λ‘λ (HF Dataset)")
|
| 61 |
+
return tasks
|
| 62 |
+
except Exception as e:
|
| 63 |
+
print(f"β οΈ HF Dataset μ€ν¨: {e}, parquet ν΄λ°±...")
|
| 64 |
+
try:
|
| 65 |
+
import pandas as pd
|
| 66 |
+
df = pd.read_parquet("full_v2.parquet")
|
| 67 |
+
tasks = []
|
| 68 |
+
for _, row in df.iterrows():
|
| 69 |
+
rubric = row["scoring_rubric"]
|
| 70 |
+
if isinstance(rubric, str): rubric = json.loads(rubric)
|
| 71 |
+
tasks.append(EvalTask(
|
| 72 |
+
task_id=row["task_id"], pillar=row["pillar"],
|
| 73 |
+
sub_dimension=row["sub_dimension"], difficulty=row["difficulty"],
|
| 74 |
+
prompt=row["prompt"], context=row.get("context"),
|
| 75 |
+
expected_behavior=row.get("expected_behavior"),
|
| 76 |
+
scoring_rubric=rubric, metadata={}))
|
| 77 |
+
print(f"β
Parquet ν΄λ°±: {len(tasks)}λ¬Έμ ")
|
| 78 |
+
return tasks
|
| 79 |
+
except Exception as e2:
|
| 80 |
+
print(f"β λ‘λ μ€ν¨: {e2}")
|
| 81 |
+
return []
|
| 82 |
+
|
| 83 |
+
ALL_TASKS = load_tasks()
|
| 84 |
+
|
| 85 |
+
# ββ ALL Bench λ±μ¬ HF Inference API λͺ¨λΈ ββ
|
| 86 |
+
|
| 87 |
+
HF_MODELS = {
|
| 88 |
+
"Qwen3.5-397B": "Qwen/Qwen3.5-397B-A17B",
|
| 89 |
+
"Qwen3.5-122B": "Qwen/Qwen3.5-122B-A10B",
|
| 90 |
+
"Qwen3.5-27B": "Qwen/Qwen3.5-27B",
|
| 91 |
+
"Qwen3.5-35B": "Qwen/Qwen3.5-35B-A3B",
|
| 92 |
+
"Qwen3.5-9B": "Qwen/Qwen3.5-9B",
|
| 93 |
+
"Qwen3.5-4B": "Qwen/Qwen3.5-4B",
|
| 94 |
+
"Qwen3-Next-80B": "Qwen/Qwen3-Next-80B-A3B-Thinking",
|
| 95 |
+
"DeepSeek V3.2": "deepseek-ai/DeepSeek-V3-0324",
|
| 96 |
+
"DeepSeek R1": "deepseek-ai/DeepSeek-R1",
|
| 97 |
+
"Llama 4 Scout": "meta-llama/Llama-4-Scout-17B-16E-Instruct",
|
| 98 |
+
"Llama 4 Maverick": "meta-llama/Llama-4-Maverick-17B-128E-Instruct",
|
| 99 |
+
"Phi-4": "microsoft/phi-4",
|
| 100 |
+
"Mistral Large 3": "mistralai/Mistral-Large-Instruct-2501",
|
| 101 |
}
|
| 102 |
|
| 103 |
+
# ββ LLM νΈμΆ: HF Inference API ββ
|
|
|
|
|
|
|
| 104 |
|
| 105 |
+
def _strip(text):
|
| 106 |
if not text: return text
|
| 107 |
+
for t in ['think','thinking','reasoning','reflection']:
|
| 108 |
+
text = re.sub(rf'<{t}>.*?</{t}>', '', text, flags=re.DOTALL)
|
|
|
|
|
|
|
| 109 |
return text.strip()
|
| 110 |
|
| 111 |
+
def call_model(prompt, system="", model_id="Qwen/Qwen3.5-397B-A17B", max_tokens=4096, temperature=0.6):
|
| 112 |
+
hf_token = os.getenv("HF_TOKEN", "")
|
| 113 |
+
if not hf_token: return "[API_ERROR] HF_TOKEN λ―Έμ€μ "
|
| 114 |
+
msgs = []
|
| 115 |
+
if system: msgs.append({"role":"system","content":system})
|
| 116 |
+
msgs.append({"role":"user","content":prompt})
|
| 117 |
+
headers = {"Content-Type":"application/json","Authorization":f"Bearer {hf_token}"}
|
| 118 |
+
payload = {"model":model_id,"messages":msgs,"max_tokens":max_tokens,"temperature":temperature,"stream":False}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 119 |
for attempt in range(3):
|
| 120 |
try:
|
| 121 |
+
r = requests.post(f"https://router.huggingface.co/hf-inference/models/{model_id}/v1/chat/completions",
|
| 122 |
+
headers=headers, json=payload, timeout=180)
|
| 123 |
+
if r.status_code in (429, 503):
|
| 124 |
+
time.sleep(10*(attempt+1)); continue
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
r.raise_for_status()
|
| 126 |
+
return _strip(r.json()["choices"][0]["message"]["content"])
|
|
|
|
|
|
|
| 127 |
except Exception as e:
|
| 128 |
+
if attempt < 2: time.sleep(5*(attempt+1))
|
| 129 |
+
else: return f"[API_ERROR] {e}"
|
| 130 |
+
|
| 131 |
+
# ββ Judge: GPT-5.2 (OPENAI_API_KEY) ββ
|
| 132 |
+
|
| 133 |
+
JUDGE_SYS = """You are a FINAL Bench scoring judge. Score each rubric item using ONLY: 0.0, 0.25, 0.5, 0.75, 1.0.
|
| 134 |
+
1.0=Excellent 0.75=Good 0.5=Average 0.25=Below 0.0=Fails
|
| 135 |
+
Output JSON: {"scores":{...}, "comment":"νμ€νκ°"}. Every rubric key MUST appear."""
|
| 136 |
+
|
| 137 |
+
def call_judge(prompt, rubric_keys):
|
| 138 |
+
api_key = os.getenv("OPENAI_API_KEY", "")
|
| 139 |
+
if not api_key: return None
|
| 140 |
+
props = {k:{"type":"number","enum":[0.0,0.25,0.5,0.75,1.0]} for k in rubric_keys}
|
| 141 |
+
schema = {"type":"object","properties":{"scores":{"type":"object","properties":props,
|
| 142 |
+
"required":list(rubric_keys),"additionalProperties":False},
|
| 143 |
+
"comment":{"type":"string"}},"required":["scores","comment"],"additionalProperties":False}
|
| 144 |
+
payload = {"model":"gpt-5.2","max_completion_tokens":4096,"temperature":0.1,
|
| 145 |
+
"messages":[{"role":"system","content":JUDGE_SYS},{"role":"user","content":prompt}],
|
| 146 |
+
"response_format":{"type":"json_schema","json_schema":{"name":"JudgeResult","strict":True,"schema":schema}}}
|
| 147 |
+
headers = {"Content-Type":"application/json","Authorization":f"Bearer {api_key}"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 148 |
for attempt in range(3):
|
| 149 |
try:
|
| 150 |
+
r = requests.post("https://api.openai.com/v1/chat/completions", headers=headers, json=payload, timeout=180)
|
| 151 |
+
if r.status_code == 429: time.sleep(8*(attempt+1)); continue
|
|
|
|
|
|
|
| 152 |
r.raise_for_status()
|
| 153 |
+
content = _strip(r.json()["choices"][0]["message"]["content"])
|
| 154 |
if not content:
|
| 155 |
+
if attempt < 2: time.sleep(3); continue
|
| 156 |
return None
|
|
|
|
|
|
|
| 157 |
data = json.loads(content)
|
| 158 |
+
if "scores" in data:
|
| 159 |
for k in rubric_keys:
|
| 160 |
if k not in data["scores"]: data["scores"][k] = 0.5
|
| 161 |
+
return data
|
| 162 |
+
except:
|
| 163 |
+
if attempt < 2: time.sleep(5*(attempt+1)); continue
|
|
|
|
|
|
|
|
|
|
| 164 |
return None
|
| 165 |
return None
|
| 166 |
|
| 167 |
+
def judge_prompt(task, response):
|
| 168 |
+
keys = list(task.scoring_rubric.keys())
|
| 169 |
+
skel = ", ".join([f'\"{k}\": ___' for k in keys])
|
| 170 |
+
rubric = "\n".join([f' \"{k}\": {v["desc"]}' for k,v in task.scoring_rubric.items()])
|
| 171 |
+
return f"Task: {task.task_id} | {task.pillar} | {task.difficulty}\nPrompt: {task.prompt[:800]}\nExpected: {(task.expected_behavior or 'N/A')[:300]}\nResponse: {response[:8000]}\n\nRubric:\n{rubric}\n\nOutput JSON: {{\"scores\": {{{skel}}}, \"comment\": \"νμ€νκ°\"}}"
|
| 172 |
+
|
| 173 |
+
def score(scores, rubric):
|
| 174 |
+
return round(sum(scores.get(k,0.5)*v["weight"] for k,v in rubric.items())*100, 2)
|
| 175 |
+
|
| 176 |
+
# ββ λ€μ€ λΌμ΄λ κ³Όμ ββ
|
| 177 |
+
|
| 178 |
+
def _mutual(topic, mid):
|
| 179 |
+
r1 = call_model(f"[R1] \'{topic}\' 500λ¨μ΄ λΆμ.", model_id=mid)
|
| 180 |
+
r2 = call_model(f"[R2] λΉννλΌ.\n---\n{r1[:2000]}", model_id=mid)
|
| 181 |
+
r3 = call_model(f"[R3] μμ νλΌ.\n--- μλ¬Έ ---\n{r1[:1500]}\n--- λΉν ---\n{r2[:1500]}", model_id=mid)
|
| 182 |
+
r4 = call_model(f"[R4] λ©νλΆμ.\n--- R1 ---\n{r1[:800]}\n--- R2 ---\n{r2[:800]}\n--- R3 ---\n{r3[:800]}", model_id=mid)
|
| 183 |
+
return f"[R1]\n{r1}\n\n[R2]\n{r2}\n\n[R3]\n{r3}\n\n[R4]\n{r4}"
|
| 184 |
+
|
| 185 |
+
def _feedback(pj, mid):
|
| 186 |
+
try: data = json.loads(pj)
|
| 187 |
+
except: return call_model(pj, model_id=mid)
|
| 188 |
+
topic, specs = data.get("topic",""), data.get("rounds",[])
|
| 189 |
+
outs, prev = [], ""
|
| 190 |
+
for i, rd in enumerate(specs):
|
| 191 |
+
inst, fb = rd.get("instruction",""), rd.get("feedback")
|
| 192 |
+
if i==0: p = f"\'{topic}\' - {inst}."
|
| 193 |
+
elif fb: p = f"νΌλλ°± λ°μ: {inst}.\n--- μ΄μ ---\n{prev[:2000]}\n--- νΌλλ°± ---\n{fb}"
|
| 194 |
+
else: p = f"{inst}.\n--- μ΅μ’
---\n{prev[:2500]}"
|
| 195 |
+
resp = call_model(p, model_id=mid); outs.append(f"[R{i+1}]\n{resp}"); prev = resp
|
| 196 |
+
return "\n\n".join(outs)
|
| 197 |
+
|
| 198 |
+
def run_task(task, mid):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 199 |
if task.sub_dimension == "mutual_verification":
|
| 200 |
+
return _mutual(task.prompt.replace("[μμ-μκ·Ή μ¬μ΄ν΄] ","").split("\n")[0], mid)
|
|
|
|
| 201 |
elif task.sub_dimension == "feedback_incorporation":
|
| 202 |
+
return _feedback(task.prompt, mid)
|
| 203 |
+
return call_model(task.prompt, model_id=mid)
|
| 204 |
+
|
| 205 |
+
# ββ DB 체ν¬ν¬μΈνΈ ββ
|
| 206 |
+
|
| 207 |
+
DB = "final_bench.db"
|
| 208 |
+
def _initdb():
|
| 209 |
+
c = sqlite3.connect(DB)
|
| 210 |
+
c.execute("CREATE TABLE IF NOT EXISTS r (rid TEXT,tid TEXT,resp TEXT,judge TEXT,score REAL,ts REAL,PRIMARY KEY(rid,tid))")
|
| 211 |
+
c.commit(); c.close()
|
| 212 |
+
def _rid(m): return hashlib.md5(m.encode()).hexdigest()[:12]
|
| 213 |
+
def _sv(rid,tid,resp,jdg,sc):
|
| 214 |
+
c=sqlite3.connect(DB); c.execute("INSERT OR REPLACE INTO r VALUES(?,?,?,?,?,?)",(rid,tid,resp,jdg,sc,time.time())); c.commit(); c.close()
|
| 215 |
+
def _loadall(rid):
|
| 216 |
+
c=sqlite3.connect(DB); rows=c.execute("SELECT tid,resp,judge,score FROM r WHERE rid=?", (rid,)).fetchall(); c.close()
|
| 217 |
+
return {r[0]:{"response":r[1],"judge":r[2],"score":r[3]} for r in rows}
|
| 218 |
+
def _clr(rid):
|
| 219 |
+
c=sqlite3.connect(DB); c.execute("DELETE FROM r WHERE rid=?",(rid,)); c.commit(); c.close()
|
| 220 |
+
_initdb()
|
| 221 |
+
|
| 222 |
+
# ββ Scores μ μ₯ + HF μ
λ‘λ ββ
|
| 223 |
+
|
| 224 |
+
SF = "final_scores.json"
|
| 225 |
+
def load_sf():
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 226 |
try:
|
| 227 |
+
with open(SF) as f: return json.load(f)
|
| 228 |
+
except: return {"version":"1.0","updated":"","models":{}}
|
| 229 |
+
def save_sf(mn, ps, fs, total, done):
|
| 230 |
+
d = load_sf(); d["updated"]=datetime.now().isoformat()
|
| 231 |
+
d["models"][mn]={"final_score":fs,"pillar_scores":{p:round(s,2) for p,s in ps.items()},
|
| 232 |
+
"total_tasks":total,"completed":done,"evaluated_at":datetime.now().isoformat()}
|
| 233 |
+
with open(SF,"w") as f: json.dump(d,f,indent=2,ensure_ascii=False)
|
| 234 |
+
return d
|
| 235 |
+
def upload_sf(d):
|
| 236 |
+
tk = os.getenv("HF_TOKEN","")
|
| 237 |
+
if not tk: return "β οΈ HF_TOKEN λ―Έμ€μ "
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 238 |
try:
|
| 239 |
from huggingface_hub import HfApi
|
| 240 |
+
api = HfApi(token=tk)
|
| 241 |
+
api.upload_file(path_or_fileobj=json.dumps(d,indent=2,ensure_ascii=False).encode("utf-8"),
|
| 242 |
+
path_in_repo="final_scores.json", repo_id="FINAL-Bench/ALL-Bench-Leaderboard",
|
| 243 |
+
repo_type="dataset", commit_message=f"FINAL Score {datetime.now().strftime('%m-%d %H:%M')}")
|
| 244 |
+
return "β
HF Dataset μ
λ‘λ μλ£"
|
| 245 |
+
except Exception as e: return f"β {e}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 246 |
|
| 247 |
+
# ββ νκ° μ컀 ββ
|
| 248 |
|
| 249 |
+
def _eval1(task, rid, mid, st):
|
| 250 |
try:
|
| 251 |
+
resp = run_task(task, mid)
|
| 252 |
+
if resp.startswith("[API_ERROR"):
|
| 253 |
+
_sv(rid,task.task_id,resp,"{}",0)
|
| 254 |
+
with st["lock"]: st["done"]+=1; st["err"].append(task.task_id)
|
| 255 |
+
return task.task_id, {"response":resp,"judge":"{}","score":0}
|
| 256 |
+
rk = list(task.scoring_rubric.keys())
|
| 257 |
+
jp = judge_prompt(task, resp)
|
| 258 |
+
jd = call_judge(jp, rk)
|
| 259 |
+
if jd is None:
|
| 260 |
+
_sv(rid,task.task_id,resp,'{"failed":true}',-1)
|
| 261 |
+
with st["lock"]: st["done"]+=1; st["jf"]+=1
|
| 262 |
+
return task.task_id, {"response":resp,"judge":'{"failed":true}',"score":-1}
|
| 263 |
+
sc = score(jd["scores"], task.scoring_rubric)
|
| 264 |
+
jj = json.dumps(jd, ensure_ascii=False)
|
| 265 |
+
_sv(rid,task.task_id,resp,jj,sc)
|
| 266 |
+
with st["lock"]:
|
| 267 |
+
st["done"]+=1; st["jok"]+=1
|
| 268 |
+
info = PILLAR_INFO.get(task.pillar,{})
|
| 269 |
+
st["rec"].append(f'{info.get("icon","")} {task.task_id} β {sc:.0f}')
|
| 270 |
+
if len(st["rec"])>8: st["rec"]=st["rec"][-8:]
|
| 271 |
+
return task.task_id, {"response":resp,"judge":jj,"score":sc}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 272 |
except Exception as e:
|
| 273 |
+
_sv(rid,task.task_id,f"[ERR]{e}","{}",0)
|
| 274 |
+
with st["lock"]: st["done"]+=1; st["err"].append(f"{task.task_id}:{str(e)[:40]}")
|
| 275 |
+
return task.task_id, {"response":f"[ERR]{e}","judge":"{}","score":0}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 276 |
|
| 277 |
+
# ββ κΈλ‘λ² μν + λ°±κ·ΈλΌμ΄λ ββ
|
| 278 |
|
| 279 |
+
_S = {"running":False,"stop":False,"finished":False,"model":"","rid":"",
|
| 280 |
+
"done":0,"total":0,"cached":0,"err":[],"rec":[],"jok":0,"jf":0,
|
| 281 |
+
"t0":0,"results":{},"tasks":[],"lock":threading.Lock(),"msg":"","csv":None,"hf":""}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 282 |
|
| 283 |
+
def _rst():
|
| 284 |
+
with _S["lock"]:
|
| 285 |
+
_S.update({"running":False,"stop":False,"finished":False,"done":0,"cached":0,
|
| 286 |
+
"err":[],"rec":[],"jok":0,"jf":0,"t0":0,"results":{},"tasks":[],"msg":"","csv":None,"hf":""})
|
| 287 |
|
| 288 |
+
def _bg(mn, mid, tasks, rid, wk):
|
|
|
|
|
|
|
| 289 |
try:
|
| 290 |
+
cached = _loadall(rid)
|
| 291 |
+
pending = [t for t in tasks if t.task_id not in cached]
|
| 292 |
+
with _S["lock"]: _S["results"]=cached; _S["cached"]=len(cached); _S["total"]=len(tasks); _S["t0"]=time.time()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 293 |
if not pending:
|
| 294 |
+
with _S["lock"]: _S["msg"]=f"πΎ μΊμ μλ£ ({len(cached)}κ°)"
|
| 295 |
+
_fin(tasks,cached,mn); return
|
| 296 |
+
with _S["lock"]: _S["msg"]=f"β‘ {len(pending)}λ¬Έμ Β· {wk}μ컀"
|
| 297 |
+
with ThreadPoolExecutor(max_workers=wk) as ex:
|
| 298 |
+
futs = {ex.submit(_eval1,t,rid,mid,_S):t for t in pending if not _S["stop"]}
|
| 299 |
+
done_set = set()
|
| 300 |
+
while len(done_set)<len(futs):
|
| 301 |
+
if _S["stop"]:
|
| 302 |
+
with _S["lock"]: _S["msg"]="βΉοΈ μ€λ¨"; _S["running"]=False; _S["finished"]=True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 303 |
return
|
| 304 |
+
for f in list(futs):
|
| 305 |
+
if f in done_set: continue
|
| 306 |
+
if f.done():
|
| 307 |
+
done_set.add(f)
|
| 308 |
try:
|
| 309 |
+
tid,data = f.result()
|
| 310 |
+
with _S["lock"]: _S["results"][tid]=data
|
|
|
|
|
|
|
|
|
|
| 311 |
except: pass
|
| 312 |
time.sleep(0.5)
|
| 313 |
+
with _S["lock"]: results=dict(_S["results"])
|
| 314 |
+
_fin(tasks,results,mn)
|
|
|
|
|
|
|
|
|
|
| 315 |
except Exception as e:
|
| 316 |
+
with _S["lock"]: _S["msg"]=f"β {str(e)[:100]}"; _S["running"]=False; _S["finished"]=True
|
|
|
|
|
|
|
|
|
|
| 317 |
|
| 318 |
+
def _fin(tasks, results, mn):
|
| 319 |
+
ps = {}
|
|
|
|
| 320 |
for p in PILLAR_INFO:
|
| 321 |
+
valid = [results[t.task_id]["score"] for t in tasks if t.pillar==p and t.task_id in results and results[t.task_id]["score"]>=0]
|
| 322 |
+
if valid: ps[p] = np.mean(valid)
|
| 323 |
+
wts = {p:info["weight"] for p,info in PILLAR_INFO.items()}
|
| 324 |
+
fs = round(sum(ps.get(p,0)*w for p,w in wts.items()), 2)
|
| 325 |
+
done = sum(1 for t in tasks if t.task_id in results and results[t.task_id]["score"]>=0)
|
| 326 |
+
sd = save_sf(mn, ps, fs, len(tasks), done)
|
| 327 |
+
hf = upload_sf(sd)
|
| 328 |
+
el = int(time.time()-_S["t0"]) if _S["t0"] else 0
|
| 329 |
+
with _S["lock"]:
|
| 330 |
+
_S["hf"]=hf; _S["msg"]=f"π FINAL Score = {fs:.1f} ({el}μ΄)"
|
| 331 |
+
_S["running"]=False; _S["finished"]=True
|
| 332 |
+
|
| 333 |
+
def _start(mc, mt, wk, fresh):
|
| 334 |
+
if _S["running"]: return "β οΈ μ§ν μ€"
|
| 335 |
+
if not os.getenv("HF_TOKEN"): return "β HF_TOKEN (Secrets)"
|
| 336 |
+
if not os.getenv("OPENAI_API_KEY"): return "β OPENAI_API_KEY (Secrets)"
|
| 337 |
+
if not ALL_TASKS: return "β κ³Όμ λ‘λ μ€ν¨"
|
| 338 |
+
mid = HF_MODELS.get(mc, mc)
|
| 339 |
+
tasks = ALL_TASKS[:int(mt)]
|
| 340 |
+
rid = _rid(mid)
|
| 341 |
+
if fresh: _clr(rid)
|
| 342 |
+
_rst()
|
| 343 |
+
with _S["lock"]:
|
| 344 |
+
_S.update({"running":True,"rid":rid,"model":mc,"tasks":tasks,"total":len(tasks),"msg":"π μ€λΉ..."})
|
| 345 |
+
threading.Thread(target=_bg, args=(mc,mid,tasks,rid,int(wk)), daemon=True).start()
|
| 346 |
+
return f"β‘ {mc} νκ° μμ ({len(tasks)}λ¬Έμ , {int(wk)}μ컀)"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 347 |
|
| 348 |
def _stop():
|
| 349 |
+
if _S["running"]: _S["stop"]=True; return "βΉοΈ μ€λ¨ μμ²"
|
|
|
|
|
|
|
|
|
|
| 350 |
return "βΉοΈ μ€ν μ€ μλ"
|
| 351 |
|
| 352 |
+
# ββ UI λΉλ ββ
|
| 353 |
|
| 354 |
+
CSS = """<style>
|
| 355 |
+
.score-bar{background:#e0e0e0;border-radius:8px;height:18px;overflow:hidden;min-width:80px}
|
| 356 |
+
.score-fill{height:100%;border-radius:8px}
|
| 357 |
+
.summary-card{background:linear-gradient(135deg,#1a1a2e,#16213e);border-radius:14px;padding:24px;color:#fff}
|
| 358 |
+
.pillar-row{display:flex;align-items:center;gap:10px;margin:6px 0}
|
| 359 |
+
.pillar-bar{flex:1;background:#333;border-radius:6px;height:16px;overflow:hidden}
|
| 360 |
+
.pillar-fill{height:100%;border-radius:6px}
|
| 361 |
+
.pbar{background:#e0e0e0;border-radius:8px;height:22px;overflow:hidden}
|
| 362 |
+
.pfill{height:100%;border-radius:8px;background:linear-gradient(90deg,#6366f1,#10b981)}
|
| 363 |
+
</style>"""
|
| 364 |
+
def _c(s): return "#4caf50" if s>=80 else ("#ff9800" if s>=60 else "#f44336")
|
| 365 |
|
| 366 |
+
def _poll():
|
| 367 |
+
with _S["lock"]:
|
| 368 |
+
run,fin = _S["running"],_S["finished"]
|
| 369 |
+
tasks,res = _S.get("tasks",[]),dict(_S.get("results",{}))
|
| 370 |
+
msg = _S.get("msg","")
|
| 371 |
+
if not run and not fin and not res:
|
| 372 |
+
return ("βΉοΈ λͺ¨λΈ μ ν β βΆοΈ μμ", "", "", None)
|
| 373 |
# Progress
|
| 374 |
+
if run:
|
| 375 |
+
d,tot = _S["done"],max(_S.get("total",1),1)
|
| 376 |
+
pct = min(int(d/tot*100),100)
|
| 377 |
+
el = int(time.time()-_S.get("t0",time.time()))
|
| 378 |
+
eta = int((el/max(d,1))*(tot-d)) if d>0 else 0
|
| 379 |
+
tags = " ".join([f'<span style="background:#e8eaf6;padding:2px 8px;border-radius:4px;font-size:.8em">{r}</span>' for r in _S.get("rec",[])[-6:]])
|
| 380 |
+
prog = f'{CSS}<div><div style="display:flex;justify-content:space-between;margin-bottom:4px"><span>β‘ {d}/{tot} | {el}μ΄ | ~{eta}μ΄</span><span style="font-weight:700">{pct}%</span></div><div class="pbar"><div class="pfill" style="width:{pct}%"></div></div><div style="margin-top:6px">{tags}</div><div style="margin-top:4px;font-size:.85em">βοΈ β
{_S.get("jok",0)} β{_S.get("jf",0)}</div></div>'
|
| 381 |
+
elif fin:
|
| 382 |
+
prog = f'<div style="background:#e8f5e9;padding:14px;border-radius:8px;font-weight:700">{msg}</div>'
|
| 383 |
+
else: prog = msg
|
| 384 |
+
# Table
|
| 385 |
+
tbl = ""
|
| 386 |
+
if tasks:
|
| 387 |
+
rows = ""
|
| 388 |
+
for t in tasks:
|
| 389 |
+
info = PILLAR_INFO.get(t.pillar,{})
|
| 390 |
+
if t.task_id in res:
|
| 391 |
+
s = res[t.task_id]["score"]
|
| 392 |
+
if s<0: rows += f'<tr style="background:#fff3e0"><td>{t.task_id}</td><td>{info.get("icon","")} {info.get("name","")}</td><td>{t.difficulty}</td><td style="color:#ff9800">β</td><td>β</td></tr>'
|
| 393 |
+
else:
|
| 394 |
+
c = _c(s)
|
| 395 |
+
rows += f'<tr><td>{t.task_id}</td><td>{info.get("icon","")} {info.get("name","")}</td><td>{t.difficulty}</td><td><div class="score-bar"><div class="score-fill" style="width:{min(s,100)}%;background:{c}"></div></div></td><td style="color:{c};font-weight:700">{s:.1f}</td></tr>'
|
| 396 |
+
else: rows += f'<tr style="opacity:.35"><td>{t.task_id}</td><td>{info.get("icon","")}</td><td>{t.difficulty}</td><td>β³</td><td>β</td></tr>'
|
| 397 |
+
tbl = f'{CSS}<table style="width:100%;border-collapse:collapse;font-size:.85em"><thead><tr><th style="background:#f0f4f8;padding:8px;text-align:left;border-bottom:2px solid #ccc">ID</th><th style="background:#f0f4f8;padding:8px">κΈ°λ₯</th><th style="background:#f0f4f8;padding:8px">λμ΄λ</th><th style="background:#f0f4f8;padding:8px">μ μ</th><th style="background:#f0f4f8;padding:8px">κ°</th></tr></thead><tbody>{rows}</tbody></table>'
|
| 398 |
+
# Summary
|
| 399 |
+
summ = ""
|
| 400 |
+
if fin and tasks:
|
| 401 |
+
ps = {}
|
| 402 |
for p in PILLAR_INFO:
|
| 403 |
+
valid = [res[t.task_id]["score"] for t in tasks if t.pillar==p and t.task_id in res and res[t.task_id]["score"]>=0]
|
| 404 |
+
if valid: ps[p]=np.mean(valid)
|
| 405 |
+
wts = {p:info["weight"] for p,info in PILLAR_INFO.items()}
|
| 406 |
+
fs = round(sum(ps.get(p,0)*w for p,w in wts.items()),2)
|
| 407 |
+
g = "A" if fs>=80 else ("B+" if fs>=70 else ("B" if fs>=60 else "C"))
|
| 408 |
+
ph = ""
|
| 409 |
+
for p,info in PILLAR_INFO.items():
|
| 410 |
+
s=ps.get(p,0); c=_c(s); w=int(info["weight"]*100)
|
| 411 |
+
ph += f'<div class="pillar-row"><span style="width:140px">{info["icon"]} {info["name"]} ({w}%)</span><div class="pillar-bar"><div class="pillar-fill" style="width:{min(s,100)}%;background:{c}"></div></div><span style="width:55px;text-align:right;font-weight:700;color:{c}">{s:.1f}</span></div>'
|
| 412 |
+
summ = f'{CSS}<div class="summary-card"><h2 style="margin:0;font-size:1.8em;text-align:center">𧬠FINAL Score: {fs:.1f}/100</h2><h3 style="text-align:center;color:#aaa">{g} | {_S.get("model","")}</h3><hr style="border-color:#333;margin:16px 0">{ph}<hr style="border-color:#333;margin:16px 0"><p style="font-size:.85em;color:#888">{_S.get("hf","")}</p></div>'
|
| 413 |
+
return (prog, tbl, summ, None)
|
| 414 |
+
|
| 415 |
+
# ββ Gradio App ββ
|
| 416 |
+
|
| 417 |
+
HEADER = """<div style="text-align:center;padding:20px 0">
|
| 418 |
+
<h1 style="margin:0;font-size:2em">𧬠FINAL Bench Auto-Evaluator</h1>
|
| 419 |
+
<p style="color:#666;max-width:700px;margin:10px auto;line-height:1.7">
|
| 420 |
+
<b>FINAL Bench 100λ¬Έμ </b> Γ ALL Bench λ±μ¬ λͺ¨λΈ μλ νκ°<br>
|
| 421 |
+
π‘ HF Inference API Β· βοΈ GPT-5.2 Judge Β· π β ALL Bench Metacog μλ λ°μ
|
| 422 |
+
</p></div>"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 423 |
|
| 424 |
def create_app():
|
| 425 |
with gr.Blocks(title="FINAL Bench Auto-Evaluator", theme=gr.themes.Soft(),
|
| 426 |
css=".gradio-container{max-width:1100px !important}") as app:
|
| 427 |
+
gr.HTML(HEADER)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 428 |
with gr.Row():
|
| 429 |
+
mdd = gr.Dropdown(list(HF_MODELS.keys()), value=list(HF_MODELS.keys())[0],
|
| 430 |
+
label="π€ νκ° λμ λͺ¨λΈ", scale=4)
|
| 431 |
+
mt = gr.Slider(1, len(ALL_TASKS) if ALL_TASKS else 100,
|
| 432 |
+
value=len(ALL_TASKS) if ALL_TASKS else 100, step=1, label="κ³Όμ μ", scale=2)
|
| 433 |
+
wk = gr.Slider(1, 15, value=8, step=1, label="β‘ μ컀", scale=1)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 434 |
with gr.Row():
|
| 435 |
+
sb = gr.Button("βΆοΈ μ΄μ΄νκΈ°", variant="primary", size="lg", scale=2)
|
| 436 |
+
fb = gr.Button("π μλ‘ μμ", variant="secondary", size="lg", scale=2)
|
| 437 |
+
xb = gr.Button("βΉοΈ μ€λ¨", variant="stop", size="lg", scale=1)
|
| 438 |
+
st = gr.Textbox(label="μν", interactive=False, max_lines=1)
|
| 439 |
+
with gr.Accordion("π κΈ°μ‘΄ κ²°κ³Ό", open=False):
|
| 440 |
+
gr.JSON(label="final_scores.json", value=load_sf())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 441 |
with gr.Tabs():
|
| 442 |
+
with gr.Tab("π μ§ν"): p1=gr.HTML()
|
| 443 |
+
with gr.Tab("π κ²°κ³Όν"): p2=gr.HTML()
|
| 444 |
+
with gr.Tab("π μ΅μ’
"): p3=gr.HTML()
|
| 445 |
+
with gr.Tab("πΎ CSV"): p4=gr.File(label="CSV")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 446 |
timer = gr.Timer(value=2, active=True)
|
| 447 |
+
timer.tick(fn=_poll, outputs=[p1,p2,p3,p4])
|
| 448 |
+
sb.click(fn=lambda m,t,w: _start(m,t,w,False), inputs=[mdd,mt,wk], outputs=[st])
|
| 449 |
+
fb.click(fn=lambda m,t,w: _start(m,t,w,True), inputs=[mdd,mt,wk], outputs=[st])
|
| 450 |
+
xb.click(fn=_stop, outputs=[st])
|
| 451 |
+
gr.Markdown(f"---\n<center>FINAL Bench v1.0 Β· {len(ALL_TASKS)}λ¬Έμ Β· Ginigen AI Β· Apache 2.0</center>")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 452 |
return app
|
| 453 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 454 |
if __name__ == "__main__":
|
| 455 |
stats = {}
|
| 456 |
+
for t in ALL_TASKS: stats[t.pillar]=stats.get(t.pillar,0)+1
|
| 457 |
+
print(f"𧬠FINAL Bench Auto-Evaluator: {len(ALL_TASKS)} tasks")
|
| 458 |
+
for p,n in stats.items():
|
| 459 |
+
info=PILLAR_INFO[p]; print(f" {info['icon']} {info['name']}: {n}")
|
| 460 |
+
print(f" π‘ HF Models: {len(HF_MODELS)} | βοΈ Judge: GPT-5.2")
|
| 461 |
+
print(f" π HF_TOKEN: {'β
' if os.getenv('HF_TOKEN') else 'β'} | OPENAI_API_KEY: {'β
' if os.getenv('OPENAI_API_KEY') else 'β'}")
|
|
|
|
|
|
|
| 462 |
app = create_app()
|
| 463 |
app.queue(default_concurrency_limit=2)
|
| 464 |
app.launch(server_name="0.0.0.0", server_port=7860, ssr_mode=False)
|