Spaces:
Running
Running
yangzhitao
commited on
Commit
·
b30e7f7
1
Parent(s):
5a3aec3
refactor: enhance type safety and input handling in create_submit_tab function by updating benchmark results form and restructuring submission logic
Browse files
app.py
CHANGED
|
@@ -2,6 +2,7 @@ import json
|
|
| 2 |
import re
|
| 3 |
import sys
|
| 4 |
import threading
|
|
|
|
| 5 |
from textwrap import dedent
|
| 6 |
|
| 7 |
import gradio as gr
|
|
@@ -46,6 +47,9 @@ from src.prepare import get_benchmarks, load_display_toml, prepare_space
|
|
| 46 |
from src.submission.submit import add_new_submit
|
| 47 |
from src.utils.hf import restart_space
|
| 48 |
|
|
|
|
|
|
|
|
|
|
| 49 |
prepare_space()
|
| 50 |
|
| 51 |
|
|
@@ -458,7 +462,7 @@ def create_submit_tab(tab_id: int, demo: gr.Blocks):
|
|
| 458 |
)
|
| 459 |
|
| 460 |
# Simple form for benchmark results
|
| 461 |
-
benchmark_results_form: list = []
|
| 462 |
for benchmark in benchmarks_list:
|
| 463 |
with gr.Row():
|
| 464 |
benchmark_checkbox = gr.Checkbox(
|
|
@@ -553,6 +557,9 @@ def create_submit_tab(tab_id: int, demo: gr.Blocks):
|
|
| 553 |
|
| 554 |
# Build results: {benchmark_key: {metric: value}}
|
| 555 |
results = {}
|
|
|
|
|
|
|
|
|
|
| 556 |
for benchmark, checkbox_checked, result_value in zip(
|
| 557 |
benchmarks_list,
|
| 558 |
benchmark_checkbox_values,
|
|
@@ -581,9 +588,8 @@ def create_submit_tab(tab_id: int, demo: gr.Blocks):
|
|
| 581 |
model_type: str,
|
| 582 |
json_str: str,
|
| 583 |
commit_message: str,
|
|
|
|
| 584 |
oauth_profile: gr.OAuthProfile | None = None,
|
| 585 |
-
*,
|
| 586 |
-
benchmark_values: list[tuple[bool, float]],
|
| 587 |
):
|
| 588 |
"""Submit with either form data or JSON"""
|
| 589 |
# Check if user is logged in
|
|
@@ -677,38 +683,13 @@ def create_submit_tab(tab_id: int, demo: gr.Blocks):
|
|
| 677 |
)
|
| 678 |
submission_result = gr.Markdown()
|
| 679 |
|
| 680 |
-
|
| 681 |
-
|
| 682 |
-
|
| 683 |
-
|
| 684 |
-
precision: str,
|
| 685 |
-
weight_type: str,
|
| 686 |
-
model_type: str,
|
| 687 |
-
json_str: str,
|
| 688 |
-
commit_message: str,
|
| 689 |
-
oauth_profile: gr.OAuthProfile | None = None,
|
| 690 |
-
):
|
| 691 |
-
# Collect all inputs for submission
|
| 692 |
-
# Add benchmark form inputs (these will be captured by *benchmark_values)
|
| 693 |
-
benchmark_values: list[tuple[bool, float]] = []
|
| 694 |
-
for _, checkbox, result_input in benchmark_results_form:
|
| 695 |
-
benchmark_values.append((checkbox.value, result_input.value))
|
| 696 |
-
|
| 697 |
-
return submit_with_form_or_json(
|
| 698 |
-
model=model,
|
| 699 |
-
base_model=base_model,
|
| 700 |
-
revision=revision,
|
| 701 |
-
precision=precision,
|
| 702 |
-
weight_type=weight_type,
|
| 703 |
-
model_type=model_type,
|
| 704 |
-
json_str=json_str,
|
| 705 |
-
commit_message=commit_message,
|
| 706 |
-
oauth_profile=oauth_profile,
|
| 707 |
-
benchmark_values=benchmark_values,
|
| 708 |
-
)
|
| 709 |
|
| 710 |
submit_button.click(
|
| 711 |
-
fn=
|
| 712 |
inputs=[
|
| 713 |
model_name_textbox,
|
| 714 |
base_model_name_textbox,
|
|
@@ -718,6 +699,7 @@ def create_submit_tab(tab_id: int, demo: gr.Blocks):
|
|
| 718 |
model_type,
|
| 719 |
json_str,
|
| 720 |
commit_textbox,
|
|
|
|
| 721 |
],
|
| 722 |
outputs=submission_result,
|
| 723 |
)
|
|
|
|
| 2 |
import re
|
| 3 |
import sys
|
| 4 |
import threading
|
| 5 |
+
import typing
|
| 6 |
from textwrap import dedent
|
| 7 |
|
| 8 |
import gradio as gr
|
|
|
|
| 47 |
from src.submission.submit import add_new_submit
|
| 48 |
from src.utils.hf import restart_space
|
| 49 |
|
| 50 |
+
if typing.TYPE_CHECKING:
|
| 51 |
+
from src.schemas.meta_toml import MetaToml_Benchmark
|
| 52 |
+
|
| 53 |
prepare_space()
|
| 54 |
|
| 55 |
|
|
|
|
| 462 |
)
|
| 463 |
|
| 464 |
# Simple form for benchmark results
|
| 465 |
+
benchmark_results_form: list[tuple[MetaToml_Benchmark, gr.Checkbox, gr.Number]] = []
|
| 466 |
for benchmark in benchmarks_list:
|
| 467 |
with gr.Row():
|
| 468 |
benchmark_checkbox = gr.Checkbox(
|
|
|
|
| 557 |
|
| 558 |
# Build results: {benchmark_key: {metric: value}}
|
| 559 |
results = {}
|
| 560 |
+
assert (
|
| 561 |
+
len(benchmarks_list) > 0 and len(benchmark_checkbox_values) > 0 and len(benchmark_result_values) > 0
|
| 562 |
+
), "Empty benchmarks list, checkbox values, or result values."
|
| 563 |
for benchmark, checkbox_checked, result_value in zip(
|
| 564 |
benchmarks_list,
|
| 565 |
benchmark_checkbox_values,
|
|
|
|
| 588 |
model_type: str,
|
| 589 |
json_str: str,
|
| 590 |
commit_message: str,
|
| 591 |
+
*benchmark_values: list[bool | float],
|
| 592 |
oauth_profile: gr.OAuthProfile | None = None,
|
|
|
|
|
|
|
| 593 |
):
|
| 594 |
"""Submit with either form data or JSON"""
|
| 595 |
# Check if user is logged in
|
|
|
|
| 683 |
)
|
| 684 |
submission_result = gr.Markdown()
|
| 685 |
|
| 686 |
+
# Add benchmark form inputs (these will be captured by *benchmark_values)
|
| 687 |
+
benchmark_values: list[gr.Checkbox | gr.Number] = []
|
| 688 |
+
for _, checkbox, result_input in benchmark_results_form:
|
| 689 |
+
benchmark_values.extend((checkbox, result_input))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 690 |
|
| 691 |
submit_button.click(
|
| 692 |
+
fn=submit_with_form_or_json,
|
| 693 |
inputs=[
|
| 694 |
model_name_textbox,
|
| 695 |
base_model_name_textbox,
|
|
|
|
| 699 |
model_type,
|
| 700 |
json_str,
|
| 701 |
commit_textbox,
|
| 702 |
+
*benchmark_values,
|
| 703 |
],
|
| 704 |
outputs=submission_result,
|
| 705 |
)
|