Spaces:
Running
Running
Display fix
Browse files
app.py
CHANGED
|
@@ -423,6 +423,56 @@ def initialize_main_dashboard(graph_year_selector_value):
|
|
| 423 |
)
|
| 424 |
|
| 425 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 426 |
### HELPER FUNCTIONS
|
| 427 |
|
| 428 |
def generate_distinct_colors(n):
|
|
@@ -616,13 +666,6 @@ with gr.Blocks(theme=theme, css=custom_css, js=js_func) as demo:
|
|
| 616 |
outputs=[leaderboard, line_plot],
|
| 617 |
)
|
| 618 |
|
| 619 |
-
# Initialize main dashboard on load with random model selections
|
| 620 |
-
demo.load(
|
| 621 |
-
fn=initialize_main_dashboard,
|
| 622 |
-
inputs=[graph_year_selector],
|
| 623 |
-
outputs=[graph_model_filter, leaderboard, line_plot]
|
| 624 |
-
)
|
| 625 |
-
|
| 626 |
gr.Markdown('<hr>')
|
| 627 |
gr.Markdown('<br>')
|
| 628 |
gr.Markdown("## Model Comparison: Faithfulness to Ideal Answer with PELT Changepoints")
|
|
@@ -679,11 +722,11 @@ with gr.Blocks(theme=theme, css=custom_css, js=js_func) as demo:
|
|
| 679 |
outputs=[comparison_plot_1, comparison_plot_2, col_plot_1, col_model_2, col_plot_2]
|
| 680 |
)
|
| 681 |
|
| 682 |
-
# Initialize
|
| 683 |
demo.load(
|
| 684 |
-
fn=
|
| 685 |
-
inputs=
|
| 686 |
-
outputs=[model_dropdown_1, model_dropdown_2, comparison_plot_1, comparison_plot_2, col_plot_1, col_model_2, col_plot_2]
|
| 687 |
)
|
| 688 |
|
| 689 |
gr.Markdown('<hr>')
|
|
|
|
| 423 |
)
|
| 424 |
|
| 425 |
|
| 426 |
+
def initialize_all_components(graph_year_selector_value):
|
| 427 |
+
"""
|
| 428 |
+
Initialize all components on page load: main dashboard and model comparison.
|
| 429 |
+
Combining into a single load function to prevent double-rendering issues in HF Spaces.
|
| 430 |
+
|
| 431 |
+
Args:
|
| 432 |
+
graph_year_selector_value: Selected years from the graph year selector
|
| 433 |
+
|
| 434 |
+
Returns:
|
| 435 |
+
Tuple of all outputs for both dashboard and comparison sections
|
| 436 |
+
"""
|
| 437 |
+
import random
|
| 438 |
+
|
| 439 |
+
# Initialize main dashboard
|
| 440 |
+
num_models = min(5, len(all_models))
|
| 441 |
+
if num_models > 0:
|
| 442 |
+
random_graph_models = random.sample(all_models, num_models)
|
| 443 |
+
else:
|
| 444 |
+
random_graph_models = []
|
| 445 |
+
|
| 446 |
+
leaderboard, line_plot = update_dashboard(graph_year_selector_value, random_graph_models)
|
| 447 |
+
|
| 448 |
+
# Initialize model comparison
|
| 449 |
+
if len(all_models) >= 2:
|
| 450 |
+
random_models = random.sample(all_models, 2)
|
| 451 |
+
model1 = random_models[0]
|
| 452 |
+
model2 = random_models[1]
|
| 453 |
+
elif len(all_models) == 1:
|
| 454 |
+
model1 = all_models[0]
|
| 455 |
+
model2 = None
|
| 456 |
+
else:
|
| 457 |
+
model1 = None
|
| 458 |
+
model2 = None
|
| 459 |
+
|
| 460 |
+
plot1 = create_faithfulness_plot(model1) if model1 else go.Figure()
|
| 461 |
+
|
| 462 |
+
return (
|
| 463 |
+
gr.update(value=random_graph_models), # graph_model_filter
|
| 464 |
+
leaderboard,
|
| 465 |
+
line_plot,
|
| 466 |
+
gr.update(value=model1), # model_dropdown_1
|
| 467 |
+
gr.update(value=model2), # model_dropdown_2
|
| 468 |
+
plot1, # comparison_plot_1
|
| 469 |
+
go.Figure(), # comparison_plot_2
|
| 470 |
+
gr.update(visible=True), # col_plot_1
|
| 471 |
+
gr.update(visible=False), # col_model_2
|
| 472 |
+
gr.update(visible=False) # col_plot_2
|
| 473 |
+
)
|
| 474 |
+
|
| 475 |
+
|
| 476 |
### HELPER FUNCTIONS
|
| 477 |
|
| 478 |
def generate_distinct_colors(n):
|
|
|
|
| 666 |
outputs=[leaderboard, line_plot],
|
| 667 |
)
|
| 668 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 669 |
gr.Markdown('<hr>')
|
| 670 |
gr.Markdown('<br>')
|
| 671 |
gr.Markdown("## Model Comparison: Faithfulness to Ideal Answer with PELT Changepoints")
|
|
|
|
| 722 |
outputs=[comparison_plot_1, comparison_plot_2, col_plot_1, col_model_2, col_plot_2]
|
| 723 |
)
|
| 724 |
|
| 725 |
+
# Initialize all components on load with a single load call (prevents double-rendering in HF Spaces)
|
| 726 |
demo.load(
|
| 727 |
+
fn=initialize_all_components,
|
| 728 |
+
inputs=[graph_year_selector],
|
| 729 |
+
outputs=[graph_model_filter, leaderboard, line_plot, model_dropdown_1, model_dropdown_2, comparison_plot_1, comparison_plot_2, col_plot_1, col_model_2, col_plot_2]
|
| 730 |
)
|
| 731 |
|
| 732 |
gr.Markdown('<hr>')
|