Roni Goldshmidt
commited on
Commit
·
e02c28e
1
Parent(s):
fbd8824
Initial leaderboard setup
Browse files- .ipynb_checkpoints/app-checkpoint.py +39 -85
- app.py +39 -85
.ipynb_checkpoints/app-checkpoint.py
CHANGED
@@ -74,28 +74,32 @@ tab1, tab2, tab3, tab4 = st.tabs([
|
|
74 |
|
75 |
def style_dataframe(df, highlight_first_column=True, show_progress_bars=True):
|
76 |
numeric_cols = df.select_dtypes(include=['float64']).columns
|
77 |
-
first_numeric_col = numeric_cols[0] if len(numeric_cols) > 0 else None
|
78 |
|
79 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
styled = df.style.format({col: '{:.2f}%' for col in numeric_cols})
|
81 |
|
82 |
-
if
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
)
|
89 |
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
'font-weight': 'bold',
|
95 |
-
'border-left': '3px solid #4a90e2',
|
96 |
-
'border-right': '3px solid #4a90e2'
|
97 |
-
}
|
98 |
-
)
|
99 |
|
100 |
styled = styled.set_properties(**{
|
101 |
'padding': '10px',
|
@@ -120,22 +124,25 @@ def style_dataframe(df, highlight_first_column=True, show_progress_bars=True):
|
|
120 |
|
121 |
def style_comparison_dataframe(df):
|
122 |
"""Style dataframe specifically for model comparison tables"""
|
123 |
-
|
|
|
124 |
|
125 |
-
styled = df.style.format({
|
126 |
-
**{col: '{:.2f}%' for col in numeric_cols},
|
127 |
-
'Difference': '{:+.2f}%' # Add plus sign for positive values
|
128 |
-
})
|
129 |
|
130 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
131 |
if 'Difference' in df.columns:
|
132 |
-
|
133 |
-
styled = styled.background_gradient(
|
134 |
-
cmap='RdYlGn',
|
135 |
-
subset=['Difference'],
|
136 |
-
vmin=-max_abs_diff,
|
137 |
-
vmax=max_abs_diff
|
138 |
-
)
|
139 |
|
140 |
styled = styled.set_properties(**{
|
141 |
'padding': '10px',
|
@@ -157,59 +164,6 @@ def style_comparison_dataframe(df):
|
|
157 |
])
|
158 |
|
159 |
return styled
|
160 |
-
|
161 |
-
def style_comparison_dataframe(df):
|
162 |
-
"""Style dataframe specifically for model comparison tables"""
|
163 |
-
numeric_cols = [col for col in df.columns if col not in ['Class', 'Difference']]
|
164 |
-
|
165 |
-
# Basic formatting for numeric columns
|
166 |
-
formatter = {
|
167 |
-
**{col: '{:.2f}%' for col in numeric_cols},
|
168 |
-
'Difference': '{:+.2f}%' # Add plus sign for positive values
|
169 |
-
}
|
170 |
-
|
171 |
-
def highlight_cells(x):
|
172 |
-
"""Style all cells in the row"""
|
173 |
-
if 'Difference' not in df.columns:
|
174 |
-
return [''] * len(df.columns)
|
175 |
-
|
176 |
-
styles = [''] * len(df.columns)
|
177 |
-
diff_idx = df.columns.get_loc('Difference')
|
178 |
-
val = x['Difference']
|
179 |
-
|
180 |
-
if not pd.isna(val):
|
181 |
-
# Normalize to ±10% scale
|
182 |
-
normalized = max(min(val / 10, 1), -1)
|
183 |
-
if normalized > 0:
|
184 |
-
styles[diff_idx] = f'background-color: rgba(0, 128, 0, {abs(normalized) * 0.4})'
|
185 |
-
else:
|
186 |
-
styles[diff_idx] = f'background-color: rgba(255, 0, 0, {abs(normalized) * 0.4})'
|
187 |
-
|
188 |
-
return styles
|
189 |
-
|
190 |
-
# Apply styling
|
191 |
-
styled = df.style\
|
192 |
-
.format(formatter)\
|
193 |
-
.apply(highlight_cells, axis=1)\
|
194 |
-
.set_properties(**{
|
195 |
-
'padding': '10px',
|
196 |
-
'border': '1px solid #dee2e6',
|
197 |
-
'text-align': 'center'
|
198 |
-
})\
|
199 |
-
.set_table_styles([
|
200 |
-
{'selector': 'th', 'props': [
|
201 |
-
('background-color', '#4a90e2'),
|
202 |
-
('color', 'white'),
|
203 |
-
('font-weight', 'bold'),
|
204 |
-
('padding', '10px'),
|
205 |
-
('text-align', 'center')
|
206 |
-
]},
|
207 |
-
{'selector': 'tr:hover', 'props': [
|
208 |
-
('background-color', '#edf2f7')
|
209 |
-
]}
|
210 |
-
])
|
211 |
-
|
212 |
-
return styled
|
213 |
|
214 |
# Tab 1: Leaderboard
|
215 |
with tab1:
|
@@ -614,7 +568,7 @@ with tab4:
|
|
614 |
# Display the styled table
|
615 |
|
616 |
st.dataframe(
|
617 |
-
|
618 |
use_container_width=True,
|
619 |
)
|
620 |
# Add visual separator
|
|
|
74 |
|
75 |
def style_dataframe(df, highlight_first_column=True, show_progress_bars=True):
|
76 |
numeric_cols = df.select_dtypes(include=['float64']).columns
|
|
|
77 |
|
78 |
+
def color_background(val):
|
79 |
+
"""Return background color style based on value"""
|
80 |
+
return f'background-color: rgba({int(255 * (1 - val))}, {int(255 * val)}, 0, 0.2)'
|
81 |
+
|
82 |
+
def apply_colors_to_series(s):
|
83 |
+
"""Apply color gradient to a series of values"""
|
84 |
+
if len(s) == 0:
|
85 |
+
return []
|
86 |
+
normalized = (s - s.min()) / (s.max() - s.min()) if s.max() != s.min() else [0.5] * len(s)
|
87 |
+
return [color_background(val) for val in normalized]
|
88 |
+
|
89 |
styled = df.style.format({col: '{:.2f}%' for col in numeric_cols})
|
90 |
|
91 |
+
# First apply highlighting to first column if needed
|
92 |
+
if highlight_first_column and len(numeric_cols) > 0:
|
93 |
+
first_numeric_col = numeric_cols[0]
|
94 |
+
styled = styled.apply(lambda x: [
|
95 |
+
'background-color: rgba(74, 144, 226, 0.2)' if col == first_numeric_col else ''
|
96 |
+
for col in df.columns
|
97 |
+
], axis=1)
|
98 |
|
99 |
+
# Then apply color gradients if needed
|
100 |
+
if show_progress_bars:
|
101 |
+
for col in numeric_cols:
|
102 |
+
styled = styled.apply(lambda s: apply_colors_to_series(s), subset=[col])
|
|
|
|
|
|
|
|
|
|
|
103 |
|
104 |
styled = styled.set_properties(**{
|
105 |
'padding': '10px',
|
|
|
124 |
|
125 |
def style_comparison_dataframe(df):
|
126 |
"""Style dataframe specifically for model comparison tables"""
|
127 |
+
# Format all numeric columns as percentages
|
128 |
+
numeric_cols = df.select_dtypes(include=['float64']).columns
|
129 |
|
130 |
+
styled = df.style.format({col: '{:.2f}%' for col in numeric_cols})
|
|
|
|
|
|
|
131 |
|
132 |
+
def color_difference(x):
|
133 |
+
"""Color the difference column from red to green"""
|
134 |
+
if pd.isna(x):
|
135 |
+
return ''
|
136 |
+
# Normalize the value to a -1 to 1 scale for coloring
|
137 |
+
normalized = max(min(x / 10, 1), -1) # Scale of ±10%
|
138 |
+
if normalized > 0:
|
139 |
+
return f'background-color: rgba(0, 128, 0, {abs(normalized) * 0.3})'
|
140 |
+
else:
|
141 |
+
return f'background-color: rgba(255, 0, 0, {abs(normalized) * 0.3})'
|
142 |
+
|
143 |
+
# Apply color gradient only to the 'Difference' column
|
144 |
if 'Difference' in df.columns:
|
145 |
+
styled = styled.applymap(color_difference, subset=['Difference'])
|
|
|
|
|
|
|
|
|
|
|
|
|
146 |
|
147 |
styled = styled.set_properties(**{
|
148 |
'padding': '10px',
|
|
|
164 |
])
|
165 |
|
166 |
return styled
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
167 |
|
168 |
# Tab 1: Leaderboard
|
169 |
with tab1:
|
|
|
568 |
# Display the styled table
|
569 |
|
570 |
st.dataframe(
|
571 |
+
metric_df,
|
572 |
use_container_width=True,
|
573 |
)
|
574 |
# Add visual separator
|
app.py
CHANGED
@@ -74,28 +74,32 @@ tab1, tab2, tab3, tab4 = st.tabs([
|
|
74 |
|
75 |
def style_dataframe(df, highlight_first_column=True, show_progress_bars=True):
|
76 |
numeric_cols = df.select_dtypes(include=['float64']).columns
|
77 |
-
first_numeric_col = numeric_cols[0] if len(numeric_cols) > 0 else None
|
78 |
|
79 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
styled = df.style.format({col: '{:.2f}%' for col in numeric_cols})
|
81 |
|
82 |
-
if
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
)
|
89 |
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
'font-weight': 'bold',
|
95 |
-
'border-left': '3px solid #4a90e2',
|
96 |
-
'border-right': '3px solid #4a90e2'
|
97 |
-
}
|
98 |
-
)
|
99 |
|
100 |
styled = styled.set_properties(**{
|
101 |
'padding': '10px',
|
@@ -120,22 +124,25 @@ def style_dataframe(df, highlight_first_column=True, show_progress_bars=True):
|
|
120 |
|
121 |
def style_comparison_dataframe(df):
|
122 |
"""Style dataframe specifically for model comparison tables"""
|
123 |
-
|
|
|
124 |
|
125 |
-
styled = df.style.format({
|
126 |
-
**{col: '{:.2f}%' for col in numeric_cols},
|
127 |
-
'Difference': '{:+.2f}%' # Add plus sign for positive values
|
128 |
-
})
|
129 |
|
130 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
131 |
if 'Difference' in df.columns:
|
132 |
-
|
133 |
-
styled = styled.background_gradient(
|
134 |
-
cmap='RdYlGn',
|
135 |
-
subset=['Difference'],
|
136 |
-
vmin=-max_abs_diff,
|
137 |
-
vmax=max_abs_diff
|
138 |
-
)
|
139 |
|
140 |
styled = styled.set_properties(**{
|
141 |
'padding': '10px',
|
@@ -157,59 +164,6 @@ def style_comparison_dataframe(df):
|
|
157 |
])
|
158 |
|
159 |
return styled
|
160 |
-
|
161 |
-
def style_comparison_dataframe(df):
|
162 |
-
"""Style dataframe specifically for model comparison tables"""
|
163 |
-
numeric_cols = [col for col in df.columns if col not in ['Class', 'Difference']]
|
164 |
-
|
165 |
-
# Basic formatting for numeric columns
|
166 |
-
formatter = {
|
167 |
-
**{col: '{:.2f}%' for col in numeric_cols},
|
168 |
-
'Difference': '{:+.2f}%' # Add plus sign for positive values
|
169 |
-
}
|
170 |
-
|
171 |
-
def highlight_cells(x):
|
172 |
-
"""Style all cells in the row"""
|
173 |
-
if 'Difference' not in df.columns:
|
174 |
-
return [''] * len(df.columns)
|
175 |
-
|
176 |
-
styles = [''] * len(df.columns)
|
177 |
-
diff_idx = df.columns.get_loc('Difference')
|
178 |
-
val = x['Difference']
|
179 |
-
|
180 |
-
if not pd.isna(val):
|
181 |
-
# Normalize to ±10% scale
|
182 |
-
normalized = max(min(val / 10, 1), -1)
|
183 |
-
if normalized > 0:
|
184 |
-
styles[diff_idx] = f'background-color: rgba(0, 128, 0, {abs(normalized) * 0.4})'
|
185 |
-
else:
|
186 |
-
styles[diff_idx] = f'background-color: rgba(255, 0, 0, {abs(normalized) * 0.4})'
|
187 |
-
|
188 |
-
return styles
|
189 |
-
|
190 |
-
# Apply styling
|
191 |
-
styled = df.style\
|
192 |
-
.format(formatter)\
|
193 |
-
.apply(highlight_cells, axis=1)\
|
194 |
-
.set_properties(**{
|
195 |
-
'padding': '10px',
|
196 |
-
'border': '1px solid #dee2e6',
|
197 |
-
'text-align': 'center'
|
198 |
-
})\
|
199 |
-
.set_table_styles([
|
200 |
-
{'selector': 'th', 'props': [
|
201 |
-
('background-color', '#4a90e2'),
|
202 |
-
('color', 'white'),
|
203 |
-
('font-weight', 'bold'),
|
204 |
-
('padding', '10px'),
|
205 |
-
('text-align', 'center')
|
206 |
-
]},
|
207 |
-
{'selector': 'tr:hover', 'props': [
|
208 |
-
('background-color', '#edf2f7')
|
209 |
-
]}
|
210 |
-
])
|
211 |
-
|
212 |
-
return styled
|
213 |
|
214 |
# Tab 1: Leaderboard
|
215 |
with tab1:
|
@@ -614,7 +568,7 @@ with tab4:
|
|
614 |
# Display the styled table
|
615 |
|
616 |
st.dataframe(
|
617 |
-
|
618 |
use_container_width=True,
|
619 |
)
|
620 |
# Add visual separator
|
|
|
74 |
|
75 |
def style_dataframe(df, highlight_first_column=True, show_progress_bars=True):
|
76 |
numeric_cols = df.select_dtypes(include=['float64']).columns
|
|
|
77 |
|
78 |
+
def color_background(val):
|
79 |
+
"""Return background color style based on value"""
|
80 |
+
return f'background-color: rgba({int(255 * (1 - val))}, {int(255 * val)}, 0, 0.2)'
|
81 |
+
|
82 |
+
def apply_colors_to_series(s):
|
83 |
+
"""Apply color gradient to a series of values"""
|
84 |
+
if len(s) == 0:
|
85 |
+
return []
|
86 |
+
normalized = (s - s.min()) / (s.max() - s.min()) if s.max() != s.min() else [0.5] * len(s)
|
87 |
+
return [color_background(val) for val in normalized]
|
88 |
+
|
89 |
styled = df.style.format({col: '{:.2f}%' for col in numeric_cols})
|
90 |
|
91 |
+
# First apply highlighting to first column if needed
|
92 |
+
if highlight_first_column and len(numeric_cols) > 0:
|
93 |
+
first_numeric_col = numeric_cols[0]
|
94 |
+
styled = styled.apply(lambda x: [
|
95 |
+
'background-color: rgba(74, 144, 226, 0.2)' if col == first_numeric_col else ''
|
96 |
+
for col in df.columns
|
97 |
+
], axis=1)
|
98 |
|
99 |
+
# Then apply color gradients if needed
|
100 |
+
if show_progress_bars:
|
101 |
+
for col in numeric_cols:
|
102 |
+
styled = styled.apply(lambda s: apply_colors_to_series(s), subset=[col])
|
|
|
|
|
|
|
|
|
|
|
103 |
|
104 |
styled = styled.set_properties(**{
|
105 |
'padding': '10px',
|
|
|
124 |
|
125 |
def style_comparison_dataframe(df):
|
126 |
"""Style dataframe specifically for model comparison tables"""
|
127 |
+
# Format all numeric columns as percentages
|
128 |
+
numeric_cols = df.select_dtypes(include=['float64']).columns
|
129 |
|
130 |
+
styled = df.style.format({col: '{:.2f}%' for col in numeric_cols})
|
|
|
|
|
|
|
131 |
|
132 |
+
def color_difference(x):
|
133 |
+
"""Color the difference column from red to green"""
|
134 |
+
if pd.isna(x):
|
135 |
+
return ''
|
136 |
+
# Normalize the value to a -1 to 1 scale for coloring
|
137 |
+
normalized = max(min(x / 10, 1), -1) # Scale of ±10%
|
138 |
+
if normalized > 0:
|
139 |
+
return f'background-color: rgba(0, 128, 0, {abs(normalized) * 0.3})'
|
140 |
+
else:
|
141 |
+
return f'background-color: rgba(255, 0, 0, {abs(normalized) * 0.3})'
|
142 |
+
|
143 |
+
# Apply color gradient only to the 'Difference' column
|
144 |
if 'Difference' in df.columns:
|
145 |
+
styled = styled.applymap(color_difference, subset=['Difference'])
|
|
|
|
|
|
|
|
|
|
|
|
|
146 |
|
147 |
styled = styled.set_properties(**{
|
148 |
'padding': '10px',
|
|
|
164 |
])
|
165 |
|
166 |
return styled
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
167 |
|
168 |
# Tab 1: Leaderboard
|
169 |
with tab1:
|
|
|
568 |
# Display the styled table
|
569 |
|
570 |
st.dataframe(
|
571 |
+
metric_df,
|
572 |
use_container_width=True,
|
573 |
)
|
574 |
# Add visual separator
|