cgeorgiaw HF Staff commited on
Commit
ed922f9
Β·
1 Parent(s): 3bfb60a

adding coloring

Browse files
Files changed (3) hide show
  1. __pycache__/about.cpython-310.pyc +0 -0
  2. about.py +23 -0
  3. app.py +70 -21
__pycache__/about.cpython-310.pyc CHANGED
Binary files a/__pycache__/about.cpython-310.pyc and b/__pycache__/about.cpython-310.pyc differ
 
about.py CHANGED
@@ -114,6 +114,29 @@ METRIC_GROUPS = {
114
  ],
115
  }
116
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
117
  # Compact view columns (most important metrics visible without scrolling)
118
  COMPACT_VIEW_COLUMNS = [
119
  'run_name',
 
114
  ],
115
  }
116
 
117
+ # Color coding for metric families (background colors for headers)
118
+ METRIC_GROUP_COLORS = {
119
+ 'Validity ↑': '#e3f2fd', # Light blue
120
+ 'Uniqueness & Novelty ↑': '#f3e5f5', # Light purple
121
+ 'Energy Metrics ↓': '#fff3e0', # Light orange
122
+ 'Stability ↑': '#e8f5e9', # Light green
123
+ 'Metastability ↑': '#f1f8e9', # Light lime
124
+ 'Distribution ↓': '#fce4ec', # Light pink
125
+ 'Diversity ↑': '#e0f7fa', # Light cyan
126
+ 'HHI ↓': '#fff8e1', # Light amber
127
+ }
128
+
129
+ # Map each column to its group for styling
130
+ def get_column_to_group_mapping():
131
+ """Returns a dict mapping column names to their metric group."""
132
+ col_to_group = {}
133
+ for group_name, cols in METRIC_GROUPS.items():
134
+ for col in cols:
135
+ col_to_group[col] = group_name
136
+ return col_to_group
137
+
138
+ COLUMN_TO_GROUP = get_column_to_group_mapping()
139
+
140
  # Compact view columns (most important metrics visible without scrolling)
141
  COMPACT_VIEW_COLUMNS = [
142
  'run_name',
app.py CHANGED
@@ -11,8 +11,8 @@ import os
11
 
12
  from about import (
13
  PROBLEM_TYPES, TOKEN, CACHE_PATH, API, submissions_repo, results_repo,
14
- COLUMN_DISPLAY_NAMES, COUNT_BASED_METRICS,
15
- COMPACT_VIEW_COLUMNS, FULL_VIEW_COLUMNS
16
  )
17
 
18
  def get_leaderboard():
@@ -24,16 +24,26 @@ def get_leaderboard():
24
 
25
  return full_df
26
 
27
- def format_dataframe(df, show_percentage=False, view_mode="Compact"):
28
  """Format the dataframe with proper column names and optional percentages."""
29
  if len(df) == 0:
30
  return df
31
 
32
- # Select columns based on view mode
33
- if view_mode == "Compact":
34
- selected_cols = [col for col in COMPACT_VIEW_COLUMNS if col in df.columns]
35
- else: # Full view
36
- selected_cols = [col for col in FULL_VIEW_COLUMNS if col in df.columns]
 
 
 
 
 
 
 
 
 
 
37
 
38
  # Create a copy with selected columns
39
  display_df = df[selected_cols].copy()
@@ -54,12 +64,40 @@ def format_dataframe(df, show_percentage=False, view_mode="Compact"):
54
  # Rename columns for display
55
  display_df = display_df.rename(columns=COLUMN_DISPLAY_NAMES)
56
 
57
- return display_df
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58
 
59
- def update_leaderboard(show_percentage, view_mode):
 
 
 
 
 
 
 
 
 
 
 
 
60
  """Update the leaderboard based on user selections."""
61
  df = get_leaderboard()
62
- return format_dataframe(df, show_percentage, view_mode)
 
63
 
64
  def show_output_box(message):
65
  return gr.update(value=message, visible=True)
@@ -67,6 +105,14 @@ def show_output_box(message):
67
  def submit_cif_files(problem_type, cif_files, profile: gr.OAuthProfile | None):
68
  return
69
 
 
 
 
 
 
 
 
 
70
  def gradio_interface() -> gr.Blocks:
71
  with gr.Blocks() as demo:
72
  gr.Markdown("## Welcome to the LeMaterial Generative Benchmark Leaderboard!")
@@ -76,12 +122,12 @@ def gradio_interface() -> gr.Blocks:
76
 
77
  # Display options
78
  with gr.Row():
79
- with gr.Column(scale=1):
80
- view_mode = gr.Radio(
81
- choices=["Compact", "Full"],
82
- value="Compact",
83
- label="View Mode",
84
- info="Compact: Key metrics | Full: All metrics grouped by category"
85
  )
86
  with gr.Column(scale=1):
87
  show_percentage = gr.Checkbox(
@@ -90,6 +136,9 @@ def gradio_interface() -> gr.Blocks:
90
  info="Display count-based metrics as percentages of total structures"
91
  )
92
 
 
 
 
93
  # Metric legend
94
  with gr.Accordion("Metric Groups Legend", open=False):
95
  legend_md = """
@@ -109,7 +158,7 @@ def gradio_interface() -> gr.Blocks:
109
  try:
110
  # Initial dataframe
111
  initial_df = get_leaderboard()
112
- formatted_df = format_dataframe(initial_df, show_percentage=False, view_mode="Compact")
113
 
114
  leaderboard_table = gr.Dataframe(
115
  label="GenBench Leaderboard",
@@ -123,12 +172,12 @@ def gradio_interface() -> gr.Blocks:
123
  # Update dataframe when options change
124
  show_percentage.change(
125
  fn=update_leaderboard,
126
- inputs=[show_percentage, view_mode],
127
  outputs=leaderboard_table
128
  )
129
- view_mode.change(
130
  fn=update_leaderboard,
131
- inputs=[show_percentage, view_mode],
132
  outputs=leaderboard_table
133
  )
134
 
 
11
 
12
  from about import (
13
  PROBLEM_TYPES, TOKEN, CACHE_PATH, API, submissions_repo, results_repo,
14
+ COLUMN_DISPLAY_NAMES, COUNT_BASED_METRICS, METRIC_GROUPS,
15
+ METRIC_GROUP_COLORS, COLUMN_TO_GROUP
16
  )
17
 
18
  def get_leaderboard():
 
24
 
25
  return full_df
26
 
27
+ def format_dataframe(df, show_percentage=False, selected_groups=None):
28
  """Format the dataframe with proper column names and optional percentages."""
29
  if len(df) == 0:
30
  return df
31
 
32
+ # Build column list based on selected metric groups
33
+ selected_cols = ['run_name']
34
+ if 'n_structures' in df.columns:
35
+ selected_cols.append('n_structures')
36
+
37
+ # If no groups selected, show all
38
+ if not selected_groups:
39
+ selected_groups = list(METRIC_GROUPS.keys())
40
+
41
+ # Add columns from selected groups
42
+ for group in selected_groups:
43
+ if group in METRIC_GROUPS:
44
+ for col in METRIC_GROUPS[group]:
45
+ if col in df.columns and col not in selected_cols:
46
+ selected_cols.append(col)
47
 
48
  # Create a copy with selected columns
49
  display_df = df[selected_cols].copy()
 
64
  # Rename columns for display
65
  display_df = display_df.rename(columns=COLUMN_DISPLAY_NAMES)
66
 
67
+ # Apply color coding based on metric groups
68
+ styled_df = apply_color_styling(display_df, selected_cols)
69
+
70
+ return styled_df
71
+
72
+ def apply_color_styling(display_df, original_cols):
73
+ """Apply background colors to dataframe based on metric groups using pandas Styler."""
74
+
75
+ def style_by_group(x):
76
+ # Create a DataFrame with the same shape filled with empty strings
77
+ styles = pd.DataFrame('', index=x.index, columns=x.columns)
78
+
79
+ # Map display column names back to original column names
80
+ for i, display_col in enumerate(x.columns):
81
+ if i < len(original_cols):
82
+ original_col = original_cols[i]
83
 
84
+ # Check if this column belongs to a metric group
85
+ if original_col in COLUMN_TO_GROUP:
86
+ group = COLUMN_TO_GROUP[original_col]
87
+ color = METRIC_GROUP_COLORS.get(group, '')
88
+ if color:
89
+ styles[display_col] = f'background-color: {color}'
90
+
91
+ return styles
92
+
93
+ # Apply the styling function
94
+ return display_df.style.apply(style_by_group, axis=None)
95
+
96
+ def update_leaderboard(show_percentage, selected_groups):
97
  """Update the leaderboard based on user selections."""
98
  df = get_leaderboard()
99
+ formatted_df = format_dataframe(df, show_percentage, selected_groups)
100
+ return formatted_df
101
 
102
  def show_output_box(message):
103
  return gr.update(value=message, visible=True)
 
105
  def submit_cif_files(problem_type, cif_files, profile: gr.OAuthProfile | None):
106
  return
107
 
108
+ def generate_color_legend_html():
109
+ """Generate HTML for color-coded metric group legend."""
110
+ html = '<div style="display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 10px;">'
111
+ for group, color in METRIC_GROUP_COLORS.items():
112
+ html += f'<span style="background-color: {color}; padding: 4px 8px; border-radius: 4px; font-size: 12px;">{group}</span>'
113
+ html += '</div>'
114
+ return html
115
+
116
  def gradio_interface() -> gr.Blocks:
117
  with gr.Blocks() as demo:
118
  gr.Markdown("## Welcome to the LeMaterial Generative Benchmark Leaderboard!")
 
122
 
123
  # Display options
124
  with gr.Row():
125
+ with gr.Column(scale=2):
126
+ selected_groups = gr.CheckboxGroup(
127
+ choices=list(METRIC_GROUPS.keys()),
128
+ value=list(METRIC_GROUPS.keys()),
129
+ label="Metric Families",
130
+ info="Select which metric groups to display"
131
  )
132
  with gr.Column(scale=1):
133
  show_percentage = gr.Checkbox(
 
136
  info="Display count-based metrics as percentages of total structures"
137
  )
138
 
139
+ # Color-coded legend
140
+ gr.HTML(generate_color_legend_html())
141
+
142
  # Metric legend
143
  with gr.Accordion("Metric Groups Legend", open=False):
144
  legend_md = """
 
158
  try:
159
  # Initial dataframe
160
  initial_df = get_leaderboard()
161
+ formatted_df = format_dataframe(initial_df, show_percentage=False, selected_groups=list(METRIC_GROUPS.keys()))
162
 
163
  leaderboard_table = gr.Dataframe(
164
  label="GenBench Leaderboard",
 
172
  # Update dataframe when options change
173
  show_percentage.change(
174
  fn=update_leaderboard,
175
+ inputs=[show_percentage, selected_groups],
176
  outputs=leaderboard_table
177
  )
178
+ selected_groups.change(
179
  fn=update_leaderboard,
180
+ inputs=[show_percentage, selected_groups],
181
  outputs=leaderboard_table
182
  )
183