Upload RPC-Bench Space
Browse files
app.py
CHANGED
|
@@ -7,7 +7,6 @@ import tempfile
|
|
| 7 |
import traceback
|
| 8 |
from datetime import datetime, timezone
|
| 9 |
from pathlib import Path
|
| 10 |
-
from typing import List
|
| 11 |
|
| 12 |
import gradio as gr
|
| 13 |
import pandas as pd
|
|
@@ -33,18 +32,18 @@ from constants import (
|
|
| 33 |
from eval import evaluate_submission
|
| 34 |
|
| 35 |
|
| 36 |
-
def _empty_leaderboard()
|
| 37 |
return pd.DataFrame(columns=ALL_COLUMNS)
|
| 38 |
|
| 39 |
|
| 40 |
-
def _normalize_leaderboard_df(df
|
| 41 |
for col in SCORE_COLUMNS:
|
| 42 |
if col in df.columns:
|
| 43 |
df[col] = pd.to_numeric(df[col], errors="coerce")
|
| 44 |
return df
|
| 45 |
|
| 46 |
|
| 47 |
-
def _seed_leaderboard()
|
| 48 |
if not SEED_LEADERBOARD_PATH.exists():
|
| 49 |
return _empty_leaderboard()
|
| 50 |
|
|
@@ -55,7 +54,7 @@ def _seed_leaderboard() -> pd.DataFrame:
|
|
| 55 |
return _normalize_leaderboard_df(df[ALL_COLUMNS])
|
| 56 |
|
| 57 |
|
| 58 |
-
def _clone_submission_repo()
|
| 59 |
if not SUBMISSION_REPO_ID:
|
| 60 |
return None, Path(".")
|
| 61 |
|
|
@@ -70,7 +69,7 @@ def _clone_submission_repo() -> tuple[Repository | None, Path]:
|
|
| 70 |
return repo, local_dir
|
| 71 |
|
| 72 |
|
| 73 |
-
def _load_leaderboard()
|
| 74 |
try:
|
| 75 |
seed_df = _seed_leaderboard()
|
| 76 |
repo, local_dir = _clone_submission_repo()
|
|
@@ -92,14 +91,14 @@ def _load_leaderboard() -> pd.DataFrame:
|
|
| 92 |
return _seed_leaderboard().sort_values(by=["Info"], ascending=False, na_position="last")
|
| 93 |
|
| 94 |
|
| 95 |
-
def _validate_submission_file(file_path
|
| 96 |
path = Path(file_path)
|
| 97 |
if not path.exists():
|
| 98 |
return False, "Uploaded file does not exist.", []
|
| 99 |
if path.suffix.lower() not in {".jsonl", ".json"}:
|
| 100 |
return False, "Submission file must be JSONL or JSON.", []
|
| 101 |
|
| 102 |
-
rows
|
| 103 |
try:
|
| 104 |
if path.suffix.lower() == ".json":
|
| 105 |
loaded = json.loads(path.read_text(encoding="utf-8"))
|
|
@@ -124,7 +123,7 @@ def _validate_submission_file(file_path: str) -> tuple[bool, str, List[dict]]:
|
|
| 124 |
return True, "Submission format is valid.", rows
|
| 125 |
|
| 126 |
|
| 127 |
-
def _append_submission_record(local_dir
|
| 128 |
csv_path = local_dir / SUBMISSION_CSV_PATH
|
| 129 |
merged = pd.concat([leaderboard, pd.DataFrame([row])], ignore_index=True)
|
| 130 |
merged = merged.reindex(columns=ALL_COLUMNS)
|
|
@@ -271,4 +270,4 @@ with gr.Blocks(title=SPACE_TITLE) as demo:
|
|
| 271 |
|
| 272 |
|
| 273 |
if __name__ == "__main__":
|
| 274 |
-
demo.launch()
|
|
|
|
| 7 |
import traceback
|
| 8 |
from datetime import datetime, timezone
|
| 9 |
from pathlib import Path
|
|
|
|
| 10 |
|
| 11 |
import gradio as gr
|
| 12 |
import pandas as pd
|
|
|
|
| 32 |
from eval import evaluate_submission
|
| 33 |
|
| 34 |
|
| 35 |
+
def _empty_leaderboard():
|
| 36 |
return pd.DataFrame(columns=ALL_COLUMNS)
|
| 37 |
|
| 38 |
|
| 39 |
+
def _normalize_leaderboard_df(df):
|
| 40 |
for col in SCORE_COLUMNS:
|
| 41 |
if col in df.columns:
|
| 42 |
df[col] = pd.to_numeric(df[col], errors="coerce")
|
| 43 |
return df
|
| 44 |
|
| 45 |
|
| 46 |
+
def _seed_leaderboard():
|
| 47 |
if not SEED_LEADERBOARD_PATH.exists():
|
| 48 |
return _empty_leaderboard()
|
| 49 |
|
|
|
|
| 54 |
return _normalize_leaderboard_df(df[ALL_COLUMNS])
|
| 55 |
|
| 56 |
|
| 57 |
+
def _clone_submission_repo():
|
| 58 |
if not SUBMISSION_REPO_ID:
|
| 59 |
return None, Path(".")
|
| 60 |
|
|
|
|
| 69 |
return repo, local_dir
|
| 70 |
|
| 71 |
|
| 72 |
+
def _load_leaderboard():
|
| 73 |
try:
|
| 74 |
seed_df = _seed_leaderboard()
|
| 75 |
repo, local_dir = _clone_submission_repo()
|
|
|
|
| 91 |
return _seed_leaderboard().sort_values(by=["Info"], ascending=False, na_position="last")
|
| 92 |
|
| 93 |
|
| 94 |
+
def _validate_submission_file(file_path):
|
| 95 |
path = Path(file_path)
|
| 96 |
if not path.exists():
|
| 97 |
return False, "Uploaded file does not exist.", []
|
| 98 |
if path.suffix.lower() not in {".jsonl", ".json"}:
|
| 99 |
return False, "Submission file must be JSONL or JSON.", []
|
| 100 |
|
| 101 |
+
rows = []
|
| 102 |
try:
|
| 103 |
if path.suffix.lower() == ".json":
|
| 104 |
loaded = json.loads(path.read_text(encoding="utf-8"))
|
|
|
|
| 123 |
return True, "Submission format is valid.", rows
|
| 124 |
|
| 125 |
|
| 126 |
+
def _append_submission_record(local_dir, leaderboard, row):
|
| 127 |
csv_path = local_dir / SUBMISSION_CSV_PATH
|
| 128 |
merged = pd.concat([leaderboard, pd.DataFrame([row])], ignore_index=True)
|
| 129 |
merged = merged.reindex(columns=ALL_COLUMNS)
|
|
|
|
| 270 |
|
| 271 |
|
| 272 |
if __name__ == "__main__":
|
| 273 |
+
demo.launch(server_name="0.0.0.0", show_api=False)
|