Spaces:
Running
Running
yangzhitao
commited on
Commit
·
ecc1bf2
1
Parent(s):
1e0ed83
refactor: update benchmark values handling in create_submit_tab function to improve type safety and streamline input collection
Browse files- .env.example +1 -1
- app.py +41 -39
.env.example
CHANGED
|
@@ -6,4 +6,4 @@ HF_RESULTS_REPO_NAME=EASI-Leaderboard-Results
|
|
| 6 |
HF_REQUESTS_REPO_NAME=EASI-Leaderboard-Requests
|
| 7 |
|
| 8 |
# Enable Submission
|
| 9 |
-
ENABLE_SUBMISSION=
|
|
|
|
| 6 |
HF_REQUESTS_REPO_NAME=EASI-Leaderboard-Requests
|
| 7 |
|
| 8 |
# Enable Submission
|
| 9 |
+
ENABLE_SUBMISSION=0
|
app.py
CHANGED
|
@@ -460,7 +460,7 @@ def create_submit_tab(tab_id: int, demo: gr.Blocks):
|
|
| 460 |
|
| 461 |
# Simple form for benchmark results
|
| 462 |
benchmarks = get_benchmarks()
|
| 463 |
-
benchmark_results_form = []
|
| 464 |
for benchmark in benchmarks:
|
| 465 |
with gr.Row():
|
| 466 |
benchmark_checkbox = gr.Checkbox(
|
|
@@ -568,21 +568,6 @@ def create_submit_tab(tab_id: int, demo: gr.Blocks):
|
|
| 568 |
|
| 569 |
return json.dumps({"config": config, "results": results}, indent=2, ensure_ascii=False)
|
| 570 |
|
| 571 |
-
SubmitWithFormOrJsonInputs = namedtuple(
|
| 572 |
-
"SubmitWithFormOrJsonInputs",
|
| 573 |
-
[
|
| 574 |
-
"model",
|
| 575 |
-
"base_model",
|
| 576 |
-
"revision",
|
| 577 |
-
"precision",
|
| 578 |
-
"weight_type",
|
| 579 |
-
"model_type",
|
| 580 |
-
"json_str",
|
| 581 |
-
"commit_message",
|
| 582 |
-
# "oauth_profile",
|
| 583 |
-
],
|
| 584 |
-
)
|
| 585 |
-
|
| 586 |
def submit_with_form_or_json(
|
| 587 |
model: str,
|
| 588 |
base_model: str,
|
|
@@ -592,9 +577,9 @@ def create_submit_tab(tab_id: int, demo: gr.Blocks):
|
|
| 592 |
model_type: str,
|
| 593 |
json_str: str,
|
| 594 |
commit_message: str,
|
| 595 |
-
oauth_profile: gr.OAuthProfile,
|
| 596 |
*,
|
| 597 |
-
benchmark_values: list[bool
|
| 598 |
):
|
| 599 |
"""Submit with either form data or JSON"""
|
| 600 |
# Check if user is logged in
|
|
@@ -632,11 +617,9 @@ def create_submit_tab(tab_id: int, demo: gr.Blocks):
|
|
| 632 |
# Split into checkbox values and result values
|
| 633 |
benchmark_checkbox_values: list[bool] = []
|
| 634 |
benchmark_result_values: list[float] = []
|
| 635 |
-
for
|
| 636 |
-
|
| 637 |
-
|
| 638 |
-
else:
|
| 639 |
-
benchmark_result_values.append(float(val)) # pyright: ignore[reportArgumentType]
|
| 640 |
|
| 641 |
try:
|
| 642 |
final_json = build_json_from_form(
|
|
@@ -690,29 +673,48 @@ def create_submit_tab(tab_id: int, demo: gr.Blocks):
|
|
| 690 |
)
|
| 691 |
submission_result = gr.Markdown()
|
| 692 |
|
| 693 |
-
|
| 694 |
-
|
| 695 |
-
|
| 696 |
-
|
| 697 |
-
|
| 698 |
-
|
| 699 |
-
|
| 700 |
-
|
| 701 |
-
|
| 702 |
-
|
| 703 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 704 |
precision=precision,
|
| 705 |
weight_type=weight_type,
|
| 706 |
model_type=model_type,
|
| 707 |
json_str=json_str,
|
| 708 |
-
commit_message=
|
| 709 |
-
|
|
|
|
| 710 |
)
|
| 711 |
-
)
|
| 712 |
|
| 713 |
submit_button.click(
|
| 714 |
-
fn=
|
| 715 |
-
inputs=
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 716 |
outputs=submission_result,
|
| 717 |
)
|
| 718 |
|
|
|
|
| 460 |
|
| 461 |
# Simple form for benchmark results
|
| 462 |
benchmarks = get_benchmarks()
|
| 463 |
+
benchmark_results_form: list = []
|
| 464 |
for benchmark in benchmarks:
|
| 465 |
with gr.Row():
|
| 466 |
benchmark_checkbox = gr.Checkbox(
|
|
|
|
| 568 |
|
| 569 |
return json.dumps({"config": config, "results": results}, indent=2, ensure_ascii=False)
|
| 570 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 571 |
def submit_with_form_or_json(
|
| 572 |
model: str,
|
| 573 |
base_model: str,
|
|
|
|
| 577 |
model_type: str,
|
| 578 |
json_str: str,
|
| 579 |
commit_message: str,
|
| 580 |
+
oauth_profile: gr.OAuthProfile | None = None,
|
| 581 |
*,
|
| 582 |
+
benchmark_values: list[tuple[bool, float]],
|
| 583 |
):
|
| 584 |
"""Submit with either form data or JSON"""
|
| 585 |
# Check if user is logged in
|
|
|
|
| 617 |
# Split into checkbox values and result values
|
| 618 |
benchmark_checkbox_values: list[bool] = []
|
| 619 |
benchmark_result_values: list[float] = []
|
| 620 |
+
for checkbox_value, result_value in benchmark_values:
|
| 621 |
+
benchmark_checkbox_values.append(checkbox_value)
|
| 622 |
+
benchmark_result_values.append(result_value) # pyright: ignore[reportArgumentType]
|
|
|
|
|
|
|
| 623 |
|
| 624 |
try:
|
| 625 |
final_json = build_json_from_form(
|
|
|
|
| 673 |
)
|
| 674 |
submission_result = gr.Markdown()
|
| 675 |
|
| 676 |
+
def submit_with_form_or_json_wrapper(
|
| 677 |
+
model: str,
|
| 678 |
+
base_model: str,
|
| 679 |
+
revision: str,
|
| 680 |
+
precision: str,
|
| 681 |
+
weight_type: str,
|
| 682 |
+
model_type: str,
|
| 683 |
+
json_str: str,
|
| 684 |
+
commit_message: str,
|
| 685 |
+
oauth_profile: gr.OAuthProfile | None = None,
|
| 686 |
+
):
|
| 687 |
+
# Collect all inputs for submission
|
| 688 |
+
# Add benchmark form inputs (these will be captured by *benchmark_values)
|
| 689 |
+
benchmark_values: list[tuple[bool, float]] = []
|
| 690 |
+
for _, checkbox, result_input in benchmark_results_form:
|
| 691 |
+
benchmark_values.append((checkbox.value, result_input.value))
|
| 692 |
+
|
| 693 |
+
return submit_with_form_or_json(
|
| 694 |
+
model=model,
|
| 695 |
+
base_model=base_model,
|
| 696 |
+
revision=revision,
|
| 697 |
precision=precision,
|
| 698 |
weight_type=weight_type,
|
| 699 |
model_type=model_type,
|
| 700 |
json_str=json_str,
|
| 701 |
+
commit_message=commit_message,
|
| 702 |
+
oauth_profile=oauth_profile,
|
| 703 |
+
benchmark_values=benchmark_values,
|
| 704 |
)
|
|
|
|
| 705 |
|
| 706 |
submit_button.click(
|
| 707 |
+
fn=submit_with_form_or_json_wrapper,
|
| 708 |
+
inputs=[
|
| 709 |
+
model_name_textbox,
|
| 710 |
+
base_model_name_textbox,
|
| 711 |
+
revision_name_textbox,
|
| 712 |
+
precision,
|
| 713 |
+
weight_type,
|
| 714 |
+
model_type,
|
| 715 |
+
json_str,
|
| 716 |
+
commit_textbox,
|
| 717 |
+
],
|
| 718 |
outputs=submission_result,
|
| 719 |
)
|
| 720 |
|