Spaces:
Running
Running
Commit
·
49c7961
1
Parent(s):
98371a5
refactor
Browse files
main.py
CHANGED
|
@@ -42,7 +42,6 @@ class LBContainer:
|
|
| 42 |
def _base_path(self):
|
| 43 |
return Path(__file__).parent / "data" / self.base_path_to_results
|
| 44 |
|
| 45 |
-
|
| 46 |
def load_df_leaderboard(self) -> pd.DataFrame:
|
| 47 |
df = pd.read_csv(self._base_path.resolve() / "website_leaderboard.csv")
|
| 48 |
df = df.rename(columns={"1#": "#"})
|
|
@@ -222,7 +221,6 @@ def make_leaderboard(lb: LBContainer) -> Leaderboard:
|
|
| 222 |
)
|
| 223 |
)
|
| 224 |
|
| 225 |
-
|
| 226 |
return Leaderboard(
|
| 227 |
elem_id=f"lb_for_{lb.name}",
|
| 228 |
value=df_leaderboard,
|
|
@@ -363,9 +361,11 @@ def render_details(imputation, splits, tasks, datasets, lb_matrix):
|
|
| 363 |
show_share_button=True,
|
| 364 |
)
|
| 365 |
|
|
|
|
| 366 |
def render_func(evt: gr.SelectData):
|
| 367 |
print(f"Tab Selected: {evt.value} (Type: {evt.index})")
|
| 368 |
|
|
|
|
| 369 |
def main():
|
| 370 |
css = """
|
| 371 |
.markdown-text-box {
|
|
@@ -428,110 +428,60 @@ def main():
|
|
| 428 |
datasets_state = gr.State(lb_matrix.datasets[0])
|
| 429 |
|
| 430 |
# Impute
|
| 431 |
-
with gr.Tabs(elem_classes="tab-buttons") as
|
| 432 |
-
for
|
| 433 |
with gr.TabItem(
|
| 434 |
lb_matrix.get_name_for_lb("imputation", impute_t),
|
| 435 |
-
id=
|
| 436 |
) as t_impute:
|
| 437 |
t_impute.select(lambda x=impute_t: x, outputs=impute_state)
|
| 438 |
-
|
| 439 |
-
|
| 440 |
-
|
| 441 |
-
|
| 442 |
-
|
| 443 |
-
|
| 444 |
-
|
| 445 |
-
|
| 446 |
-
|
| 447 |
-
|
| 448 |
-
|
| 449 |
-
|
| 450 |
-
|
| 451 |
-
|
| 452 |
-
|
| 453 |
-
|
| 454 |
-
|
| 455 |
-
|
| 456 |
-
|
| 457 |
-
|
| 458 |
-
|
| 459 |
-
|
| 460 |
-
|
| 461 |
-
|
| 462 |
-
|
| 463 |
-
|
| 464 |
-
|
| 465 |
-
|
| 466 |
-
|
| 467 |
-
|
| 468 |
-
|
| 469 |
-
|
| 470 |
-
|
| 471 |
-
|
| 472 |
-
|
| 473 |
-
|
| 474 |
-
|
| 475 |
-
|
| 476 |
-
|
| 477 |
-
|
| 478 |
-
|
| 479 |
-
|
| 480 |
-
|
| 481 |
-
# 2. DEFINE RENDER LOGIC
|
| 482 |
-
# We define a helper function to bind the current loop variables
|
| 483 |
-
# (context_i, context_s, etc.) so they don't get overwritten.
|
| 484 |
-
def define_render(
|
| 485 |
-
context_i,
|
| 486 |
-
context_s,
|
| 487 |
-
context_t,
|
| 488 |
-
context_d,
|
| 489 |
-
):
|
| 490 |
-
# This triggers whenever ANY of the 4 states change
|
| 491 |
-
@gr.render(
|
| 492 |
-
inputs=[
|
| 493 |
-
impute_state,
|
| 494 |
-
splits_state,
|
| 495 |
-
tasks_state,
|
| 496 |
-
datasets_state,
|
| 497 |
-
],
|
| 498 |
-
trigger_mode="once",
|
| 499 |
-
concurrency_limit=1,
|
| 500 |
-
concurrency_id=f"{context_i}_{context_s}_{context_t}_{context_d}"
|
| 501 |
-
)
|
| 502 |
-
def reactive_render(
|
| 503 |
-
sel_i,
|
| 504 |
-
sel_s,
|
| 505 |
-
sel_t,
|
| 506 |
-
sel_d,
|
| 507 |
-
):
|
| 508 |
-
|
| 509 |
-
if (
|
| 510 |
-
sel_i == context_i
|
| 511 |
-
and sel_s
|
| 512 |
-
== context_s
|
| 513 |
-
and sel_t
|
| 514 |
-
== context_t
|
| 515 |
-
and sel_d
|
| 516 |
-
== context_d
|
| 517 |
-
):
|
| 518 |
-
print(sel_i, sel_s, sel_t, sel_d)
|
| 519 |
-
render_details(
|
| 520 |
-
imputation=sel_i,
|
| 521 |
-
splits=sel_s,
|
| 522 |
-
tasks=sel_t,
|
| 523 |
-
datasets=sel_d,
|
| 524 |
-
lb_matrix=lb_matrix,
|
| 525 |
-
)
|
| 526 |
-
|
| 527 |
-
# Call the helper to attach the render logic to this specific tab
|
| 528 |
-
define_render(impute_t, splits_t, tasks_t, datasets_t)
|
| 529 |
|
| 530 |
with gr.Row(), gr.Accordion("📂 Version History", open=False):
|
| 531 |
gr.Markdown(VERSION_HISTORY_BUTTON_TEXT, elem_classes="markdown-text")
|
| 532 |
|
| 533 |
-
demo.
|
| 534 |
-
demo.launch()
|
| 535 |
|
| 536 |
|
| 537 |
if __name__ == "__main__":
|
|
|
|
| 42 |
def _base_path(self):
|
| 43 |
return Path(__file__).parent / "data" / self.base_path_to_results
|
| 44 |
|
|
|
|
| 45 |
def load_df_leaderboard(self) -> pd.DataFrame:
|
| 46 |
df = pd.read_csv(self._base_path.resolve() / "website_leaderboard.csv")
|
| 47 |
df = df.rename(columns={"1#": "#"})
|
|
|
|
| 221 |
)
|
| 222 |
)
|
| 223 |
|
|
|
|
| 224 |
return Leaderboard(
|
| 225 |
elem_id=f"lb_for_{lb.name}",
|
| 226 |
value=df_leaderboard,
|
|
|
|
| 361 |
show_share_button=True,
|
| 362 |
)
|
| 363 |
|
| 364 |
+
|
| 365 |
def render_func(evt: gr.SelectData):
|
| 366 |
print(f"Tab Selected: {evt.value} (Type: {evt.index})")
|
| 367 |
|
| 368 |
+
|
| 369 |
def main():
|
| 370 |
css = """
|
| 371 |
.markdown-text-box {
|
|
|
|
| 428 |
datasets_state = gr.State(lb_matrix.datasets[0])
|
| 429 |
|
| 430 |
# Impute
|
| 431 |
+
with gr.Tabs(elem_classes="tab-buttons") as impute_tabs:
|
| 432 |
+
for impute_t in lb_matrix.imputation:
|
| 433 |
with gr.TabItem(
|
| 434 |
lb_matrix.get_name_for_lb("imputation", impute_t),
|
| 435 |
+
id=impute_t,
|
| 436 |
) as t_impute:
|
| 437 |
t_impute.select(lambda x=impute_t: x, outputs=impute_state)
|
| 438 |
+
# Splits
|
| 439 |
+
with gr.Tabs(elem_classes="tab-buttons") as split_tabs:
|
| 440 |
+
for splits_t in lb_matrix.splits:
|
| 441 |
+
with gr.TabItem(
|
| 442 |
+
lb_matrix.get_name_for_lb("splits", splits_t),
|
| 443 |
+
id=f"{impute_t}_{splits_t}",
|
| 444 |
+
) as t_splits:
|
| 445 |
+
t_splits.select(lambda x=splits_t: x, outputs=splits_state)
|
| 446 |
+
# Tasks
|
| 447 |
+
with gr.Tabs(elem_classes="tab-buttons") as task_tabs:
|
| 448 |
+
for tasks_t in lb_matrix.tasks:
|
| 449 |
+
with gr.TabItem(
|
| 450 |
+
lb_matrix.get_name_for_lb("tasks", tasks_t),
|
| 451 |
+
id=f"{impute_t}_{splits_t}_{tasks_t}",
|
| 452 |
+
) as t_tasks:
|
| 453 |
+
t_tasks.select(lambda x=tasks_t: x, outputs=tasks_state)
|
| 454 |
+
# Datasets
|
| 455 |
+
with gr.Tabs(elem_classes="tab-buttons") as dataset_tabs:
|
| 456 |
+
for datasets_t in lb_matrix.datasets:
|
| 457 |
+
with gr.TabItem(
|
| 458 |
+
lb_matrix.get_name_for_lb("datasets", datasets_t),
|
| 459 |
+
id=f"{impute_t}_{splits_t}_{tasks_t}_{datasets_t}",
|
| 460 |
+
) as t_dataset:
|
| 461 |
+
t_dataset.select(
|
| 462 |
+
lambda x=datasets_t: x,
|
| 463 |
+
outputs=datasets_state,
|
| 464 |
+
)
|
| 465 |
+
|
| 466 |
+
@gr.render(inputs=[impute_state, splits_state, tasks_state, datasets_state])
|
| 467 |
+
def reactive_render(sel_i, sel_s, sel_t, sel_d):
|
| 468 |
+
# Since we are outside the loop, we don't need to check contexts.
|
| 469 |
+
# We simply render whatever the current state dictates.
|
| 470 |
+
print(f"Rendering: {sel_i}, {sel_s}, {sel_t}, {sel_d}")
|
| 471 |
+
|
| 472 |
+
with gr.Group():
|
| 473 |
+
render_details(
|
| 474 |
+
imputation=sel_i,
|
| 475 |
+
splits=sel_s,
|
| 476 |
+
tasks=sel_t,
|
| 477 |
+
datasets=sel_d,
|
| 478 |
+
lb_matrix=lb_matrix,
|
| 479 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 480 |
|
| 481 |
with gr.Row(), gr.Accordion("📂 Version History", open=False):
|
| 482 |
gr.Markdown(VERSION_HISTORY_BUTTON_TEXT, elem_classes="markdown-text")
|
| 483 |
|
| 484 |
+
demo.launch(show_error=True)
|
|
|
|
| 485 |
|
| 486 |
|
| 487 |
if __name__ == "__main__":
|