Joschka Strueber commited on
Commit
afa5fdc
·
1 Parent(s): 8e6c6a4

[Fix] plot visibility

Browse files
Files changed (1) hide show
  1. app.py +21 -16
app.py CHANGED
@@ -5,21 +5,26 @@ from src.dataloading import get_leaderboard_models_cached, get_leaderboard_datas
5
 
6
  def create_heatmap(selected_models, selected_dataset):
7
  if not selected_models or not selected_dataset:
8
- return None, gr.update(visible=False) # Hide the plot if no models or dataset selected
9
 
10
  # Generate random similarity matrix
11
  size = len(selected_models)
12
  similarities = np.random.rand(size, size)
13
  similarities = (similarities + similarities.T) / 2 # Make symmetric
 
14
 
15
- # Create plot
16
- fig = go.Figure()
17
- fig.add_trace(go.Heatmap(
18
- z=similarities,
19
- x=selected_models,
20
- y=selected_models,
21
- colorscale='Viridis'
22
- ))
 
 
 
 
23
 
24
  # Improve axis readability
25
  fig.update_layout(
@@ -28,12 +33,12 @@ def create_heatmap(selected_models, selected_dataset):
28
  yaxis_title="Models",
29
  xaxis=dict(tickangle=45, automargin=True),
30
  yaxis=dict(automargin=True),
31
- width=800 + 20*len(selected_models),
32
- height=800 + 20*len(selected_models),
33
- margin=dict(b=100, l=100) # Add bottom/left margin for labels
34
  )
35
 
36
- return fig, gr.update(visible=True) # Show the plot
37
 
38
 
39
  def validate_inputs(selected_models, selected_dataset):
@@ -64,7 +69,7 @@ with gr.Blocks(title="LLM Similarity Analyzer") as demo:
64
  )
65
 
66
  generate_btn = gr.Button("Generate Heatmap", variant="primary")
67
- heatmap = gr.Plot(label="Similarity Heatmap", visible=False)
68
 
69
  # Event handling
70
  generate_btn.click(
@@ -74,7 +79,7 @@ with gr.Blocks(title="LLM Similarity Analyzer") as demo:
74
  ).then(
75
  fn=create_heatmap,
76
  inputs=[model_dropdown, dataset_dropdown],
77
- outputs=[heatmap, heatmap]
78
  )
79
 
80
  # Clear button
@@ -86,4 +91,4 @@ with gr.Blocks(title="LLM Similarity Analyzer") as demo:
86
 
87
 
88
  if __name__ == "__main__":
89
- demo.launch()
 
5
 
6
  def create_heatmap(selected_models, selected_dataset):
7
  if not selected_models or not selected_dataset:
8
+ return None # Just return None to hide the plot
9
 
10
  # Generate random similarity matrix
11
  size = len(selected_models)
12
  similarities = np.random.rand(size, size)
13
  similarities = (similarities + similarities.T) / 2 # Make symmetric
14
+ similarities = np.round(similarities, 2) # Round for clarity
15
 
16
+ # Create the heatmap figure
17
+ fig = go.Figure(
18
+ data=go.Heatmap(
19
+ z=similarities, # ✅ Ensure it's a NumPy array
20
+ x=selected_models,
21
+ y=selected_models,
22
+ colorscale='Viridis',
23
+ zmin=0, zmax=1, # Normalize scale
24
+ text=similarities, # ✅ Show values in heatmap
25
+ hoverinfo="text"
26
+ )
27
+ )
28
 
29
  # Improve axis readability
30
  fig.update_layout(
 
33
  yaxis_title="Models",
34
  xaxis=dict(tickangle=45, automargin=True),
35
  yaxis=dict(automargin=True),
36
+ width=800 + 20 * len(selected_models),
37
+ height=800 + 20 * len(selected_models),
38
+ margin=dict(b=100, l=100), # Add bottom/left margin for labels
39
  )
40
 
41
+ return fig # Return only the figure
42
 
43
 
44
  def validate_inputs(selected_models, selected_dataset):
 
69
  )
70
 
71
  generate_btn = gr.Button("Generate Heatmap", variant="primary")
72
+ heatmap = gr.Plot(label="Similarity Heatmap", visible=True) # ✅ Ensure visible=True
73
 
74
  # Event handling
75
  generate_btn.click(
 
79
  ).then(
80
  fn=create_heatmap,
81
  inputs=[model_dropdown, dataset_dropdown],
82
+ outputs=heatmap # ✅ Only one output (gr.Plot)
83
  )
84
 
85
  # Clear button
 
91
 
92
 
93
  if __name__ == "__main__":
94
+ demo.launch()