Upload folder using huggingface_hub
Browse files- README.md +1 -1
- __pycache__/app.cpython-311.pyc +0 -0
- app.py +111 -2
README.md
CHANGED
|
@@ -4,7 +4,7 @@ emoji: 🔎
|
|
| 4 |
colorFrom: red
|
| 5 |
colorTo: blue
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version:
|
| 8 |
python_version: 3.11
|
| 9 |
app_file: app.py
|
| 10 |
pinned: false
|
|
|
|
| 4 |
colorFrom: red
|
| 5 |
colorTo: blue
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 5.49.1
|
| 8 |
python_version: 3.11
|
| 9 |
app_file: app.py
|
| 10 |
pinned: false
|
__pycache__/app.cpython-311.pyc
CHANGED
|
Binary files a/__pycache__/app.cpython-311.pyc and b/__pycache__/app.cpython-311.pyc differ
|
|
|
app.py
CHANGED
|
@@ -8,6 +8,8 @@ from pathlib import Path
|
|
| 8 |
from typing import Any
|
| 9 |
|
| 10 |
os.environ.setdefault("GRADIO_SSR_MODE", "false")
|
|
|
|
|
|
|
| 11 |
|
| 12 |
import gradio as gr
|
| 13 |
import pandas as pd
|
|
@@ -558,6 +560,106 @@ def load_results() -> list[dict[str, Any]]:
|
|
| 558 |
return read_jsonl(RESULTS_PATH)
|
| 559 |
|
| 560 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 561 |
def logo_data_uri() -> str:
|
| 562 |
if not LOGO_PATH.exists():
|
| 563 |
return ""
|
|
@@ -734,7 +836,7 @@ def task_choices() -> list[str]:
|
|
| 734 |
|
| 735 |
|
| 736 |
with gr.Blocks(title="RusBEIR Leaderboard") as demo:
|
| 737 |
-
gr.HTML(summary_html())
|
| 738 |
|
| 739 |
with gr.Tabs():
|
| 740 |
with gr.Tab("Leaderboard"):
|
|
@@ -807,12 +909,19 @@ with gr.Blocks(title="RusBEIR Leaderboard") as demo:
|
|
| 807 |
source_url = gr.Textbox(label="Source URL", placeholder="Evaluation logs, paper, PR, or model card")
|
| 808 |
notes = gr.Textbox(label="Notes", lines=3)
|
| 809 |
template_button = gr.Button("Create submission template", variant="primary")
|
| 810 |
-
template = gr.Code(label="JSONL record", language="json")
|
|
|
|
|
|
|
| 811 |
template_button.click(
|
| 812 |
submission_template,
|
| 813 |
inputs=[model_id, model_type, source_url, notes],
|
| 814 |
outputs=template,
|
| 815 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 816 |
|
| 817 |
with gr.Tab("About"):
|
| 818 |
with gr.Column(elem_classes=["rusbeir-panel"]):
|
|
|
|
| 8 |
from typing import Any
|
| 9 |
|
| 10 |
os.environ.setdefault("GRADIO_SSR_MODE", "false")
|
| 11 |
+
os.environ.setdefault("GRADIO_ANALYTICS_ENABLED", "False")
|
| 12 |
+
os.environ.setdefault("HF_HUB_DISABLE_TELEMETRY", "1")
|
| 13 |
|
| 14 |
import gradio as gr
|
| 15 |
import pandas as pd
|
|
|
|
| 560 |
return read_jsonl(RESULTS_PATH)
|
| 561 |
|
| 562 |
|
| 563 |
+
def normalize_submission_record(record: dict[str, Any]) -> dict[str, Any]:
|
| 564 |
+
model_id = str(record.get("model_id", "")).strip()
|
| 565 |
+
if not model_id:
|
| 566 |
+
raise ValueError("`model_id` is required.")
|
| 567 |
+
|
| 568 |
+
scores = record.get("scores")
|
| 569 |
+
if not isinstance(scores, dict):
|
| 570 |
+
raise ValueError("`scores` must be an object.")
|
| 571 |
+
|
| 572 |
+
average_scores = scores.get("average", {})
|
| 573 |
+
dataset_scores = scores.get("datasets", {})
|
| 574 |
+
if average_scores is None:
|
| 575 |
+
average_scores = {}
|
| 576 |
+
if dataset_scores is None:
|
| 577 |
+
dataset_scores = {}
|
| 578 |
+
if not isinstance(average_scores, dict):
|
| 579 |
+
raise ValueError("`scores.average` must be an object.")
|
| 580 |
+
if not isinstance(dataset_scores, dict):
|
| 581 |
+
raise ValueError("`scores.datasets` must be an object.")
|
| 582 |
+
|
| 583 |
+
has_metric = any(metric_value(average_scores, metric) is not None for metric in METRICS)
|
| 584 |
+
if not has_metric:
|
| 585 |
+
for metrics in dataset_scores.values():
|
| 586 |
+
if isinstance(metrics, dict) and any(metric_value(metrics, metric) is not None for metric in METRICS):
|
| 587 |
+
has_metric = True
|
| 588 |
+
break
|
| 589 |
+
if not has_metric:
|
| 590 |
+
raise ValueError(f"At least one numeric metric is required: {', '.join(METRICS)}.")
|
| 591 |
+
|
| 592 |
+
normalized = dict(record)
|
| 593 |
+
normalized["model_id"] = model_id
|
| 594 |
+
normalized["model_name"] = str(record.get("model_name") or model_id.split("/")[-1]).strip()
|
| 595 |
+
normalized["organization"] = str(record.get("organization") or (model_id.split("/", 1)[0] if "/" in model_id else "")).strip()
|
| 596 |
+
normalized["type"] = str(record.get("type") or "dense").strip()
|
| 597 |
+
normalized["date"] = str(record.get("date") or date.today().isoformat()).strip()
|
| 598 |
+
normalized["verified"] = bool(record.get("verified", False))
|
| 599 |
+
normalized["source_url"] = str(record.get("source_url", "")).strip()
|
| 600 |
+
normalized["scores"] = {"average": average_scores, "datasets": dataset_scores}
|
| 601 |
+
return normalized
|
| 602 |
+
|
| 603 |
+
|
| 604 |
+
def add_submission_record(
|
| 605 |
+
record_text: str,
|
| 606 |
+
metric: str,
|
| 607 |
+
task_filter: str,
|
| 608 |
+
verified_only: bool,
|
| 609 |
+
model_filter: str,
|
| 610 |
+
) -> tuple[str, str, str]:
|
| 611 |
+
record_text = record_text.strip()
|
| 612 |
+
if not record_text:
|
| 613 |
+
return (
|
| 614 |
+
"Paste or generate a JSONL record first.",
|
| 615 |
+
summary_html(),
|
| 616 |
+
leaderboard_table_html(metric, task_filter, verified_only, model_filter),
|
| 617 |
+
)
|
| 618 |
+
|
| 619 |
+
try:
|
| 620 |
+
parsed = json.loads(record_text)
|
| 621 |
+
if not isinstance(parsed, dict):
|
| 622 |
+
raise ValueError("Submission must be a single JSON object.")
|
| 623 |
+
record = normalize_submission_record(parsed)
|
| 624 |
+
except (json.JSONDecodeError, ValueError) as exc:
|
| 625 |
+
return (
|
| 626 |
+
f"Submission was not added: {exc}",
|
| 627 |
+
summary_html(),
|
| 628 |
+
leaderboard_table_html(metric, task_filter, verified_only, model_filter),
|
| 629 |
+
)
|
| 630 |
+
|
| 631 |
+
serialized = json.dumps(record, ensure_ascii=False, sort_keys=True, separators=(",", ":"))
|
| 632 |
+
existing = set()
|
| 633 |
+
for item in load_results():
|
| 634 |
+
try:
|
| 635 |
+
existing.add(json.dumps(normalize_submission_record(item), ensure_ascii=False, sort_keys=True, separators=(",", ":")))
|
| 636 |
+
except ValueError:
|
| 637 |
+
continue
|
| 638 |
+
if serialized in existing:
|
| 639 |
+
return (
|
| 640 |
+
f"`{record['model_id']}` is already present with the same scores.",
|
| 641 |
+
summary_html(),
|
| 642 |
+
leaderboard_table_html(metric, task_filter, verified_only, model_filter),
|
| 643 |
+
)
|
| 644 |
+
|
| 645 |
+
RESULTS_PATH.parent.mkdir(parents=True, exist_ok=True)
|
| 646 |
+
with RESULTS_PATH.open("a", encoding="utf-8") as file:
|
| 647 |
+
needs_newline = RESULTS_PATH.exists() and RESULTS_PATH.stat().st_size > 0
|
| 648 |
+
if needs_newline:
|
| 649 |
+
with RESULTS_PATH.open("rb") as check_file:
|
| 650 |
+
check_file.seek(-1, os.SEEK_END)
|
| 651 |
+
needs_newline = check_file.read(1) != b"\n"
|
| 652 |
+
if needs_newline:
|
| 653 |
+
file.write("\n")
|
| 654 |
+
file.write(serialized)
|
| 655 |
+
|
| 656 |
+
return (
|
| 657 |
+
f"Added `{record['model_id']}` to `{RESULTS_PATH.name}`.",
|
| 658 |
+
summary_html(),
|
| 659 |
+
leaderboard_table_html(metric, task_filter, verified_only, model_filter),
|
| 660 |
+
)
|
| 661 |
+
|
| 662 |
+
|
| 663 |
def logo_data_uri() -> str:
|
| 664 |
if not LOGO_PATH.exists():
|
| 665 |
return ""
|
|
|
|
| 836 |
|
| 837 |
|
| 838 |
with gr.Blocks(title="RusBEIR Leaderboard") as demo:
|
| 839 |
+
summary = gr.HTML(summary_html())
|
| 840 |
|
| 841 |
with gr.Tabs():
|
| 842 |
with gr.Tab("Leaderboard"):
|
|
|
|
| 909 |
source_url = gr.Textbox(label="Source URL", placeholder="Evaluation logs, paper, PR, or model card")
|
| 910 |
notes = gr.Textbox(label="Notes", lines=3)
|
| 911 |
template_button = gr.Button("Create submission template", variant="primary")
|
| 912 |
+
template = gr.Code(label="JSONL record", language="json", interactive=True)
|
| 913 |
+
submit_status = gr.Markdown()
|
| 914 |
+
add_button = gr.Button("Add to leaderboard", variant="primary")
|
| 915 |
template_button.click(
|
| 916 |
submission_template,
|
| 917 |
inputs=[model_id, model_type, source_url, notes],
|
| 918 |
outputs=template,
|
| 919 |
)
|
| 920 |
+
add_button.click(
|
| 921 |
+
add_submission_record,
|
| 922 |
+
inputs=[template, metric, task_filter, verified_only, model_filter],
|
| 923 |
+
outputs=[submit_status, summary, table],
|
| 924 |
+
)
|
| 925 |
|
| 926 |
with gr.Tab("About"):
|
| 927 |
with gr.Column(elem_classes=["rusbeir-panel"]):
|