Roni Goldshmidt
commited on
Commit
·
326cd70
1
Parent(s):
a8755b7
Initial leaderboard setup
Browse files- .ipynb_checkpoints/app-checkpoint.py +41 -51
- app.py +41 -51
.ipynb_checkpoints/app-checkpoint.py
CHANGED
@@ -74,41 +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 |
|
78 |
-
|
79 |
-
|
80 |
-
return f'background-color: rgba({int(255 * (1 - val))}, {int(255 * val)}, 0, 0.2)'
|
81 |
|
82 |
-
|
83 |
-
|
84 |
-
if
|
85 |
return []
|
86 |
normalized = (s - s.min()) / (s.max() - s.min()) if s.max() != s.min() else [0.5] * len(s)
|
87 |
-
return [
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
normalized = (val - df[col].min()) / (df[col].max() - df[col].min()) if df[col].max() != df[col].min() else 0.5
|
104 |
-
result[col_idx] = f'background-color: rgba({int(255 * (1 - normalized))}, {int(255 * normalized)}, 0, 0.2)'
|
105 |
-
if col == numeric_cols[0] and highlight_first_column:
|
106 |
-
result[col_idx] = result[col_idx] + '; font-weight: bold;'
|
107 |
-
|
108 |
-
return result
|
109 |
-
|
110 |
-
styled = styled.apply(highlight_and_color, axis=1)
|
111 |
-
|
112 |
styled = styled.set_properties(**{
|
113 |
'padding': '10px',
|
114 |
'border': '1px solid #dee2e6',
|
@@ -132,29 +123,28 @@ def style_dataframe(df, highlight_first_column=True, show_progress_bars=True):
|
|
132 |
|
133 |
def style_comparison_dataframe(df):
|
134 |
"""Style dataframe specifically for model comparison tables"""
|
135 |
-
numeric_cols = df.
|
|
|
|
|
|
|
|
|
|
|
|
|
136 |
|
137 |
-
|
|
|
138 |
"""Color the difference column from red to green"""
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
result[diff_idx] = f'background-color: rgba(0, 128, 0, {abs(normalized) * 0.3})'
|
148 |
-
else:
|
149 |
-
result[diff_idx] = f'background-color: rgba(255, 0, 0, {abs(normalized) * 0.3})'
|
150 |
-
return result
|
151 |
-
|
152 |
styled = df.style\
|
153 |
-
.format(
|
154 |
-
|
155 |
-
**{col: '{:.2f}%' for col in numeric_cols if col != 'Difference'}
|
156 |
-
})\
|
157 |
-
.apply(highlight_difference, axis=1)\
|
158 |
.set_properties(**{
|
159 |
'padding': '10px',
|
160 |
'border': '1px solid #dee2e6',
|
|
|
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 |
+
# Start with basic formatting
|
80 |
+
styled = df.style.format({col: '{:.2f}%' for col in numeric_cols})
|
|
|
81 |
|
82 |
+
# Function for color gradient
|
83 |
+
def color_gradient(s):
|
84 |
+
if s.empty:
|
85 |
return []
|
86 |
normalized = (s - s.min()) / (s.max() - s.min()) if s.max() != s.min() else [0.5] * len(s)
|
87 |
+
return ['background-color: rgba({}, {}, 0, 0.2)'.format(
|
88 |
+
int(255 * (1 - val)), int(255 * val)
|
89 |
+
) for val in normalized]
|
90 |
+
|
91 |
+
# Apply color gradient to all numeric columns if needed
|
92 |
+
if show_progress_bars:
|
93 |
+
for col in numeric_cols:
|
94 |
+
styled = styled.apply(color_gradient, subset=[col])
|
95 |
+
|
96 |
+
# Highlight first column if needed
|
97 |
+
if highlight_first_column and first_numeric_col:
|
98 |
+
styled = styled.apply(lambda x: ['background-color: rgba(74, 144, 226, 0.2); font-weight: bold;'
|
99 |
+
if col == first_numeric_col else ''
|
100 |
+
for col in df.columns], axis=0)
|
101 |
+
|
102 |
+
# Apply basic styling
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
103 |
styled = styled.set_properties(**{
|
104 |
'padding': '10px',
|
105 |
'border': '1px solid #dee2e6',
|
|
|
123 |
|
124 |
def style_comparison_dataframe(df):
|
125 |
"""Style dataframe specifically for model comparison tables"""
|
126 |
+
numeric_cols = [col for col in df.columns if col not in ['Class', 'Difference']]
|
127 |
+
|
128 |
+
# Basic formatting for numeric columns
|
129 |
+
formatter = {
|
130 |
+
**{col: '{:.2f}%' for col in numeric_cols},
|
131 |
+
'Difference': '{:+.2f}%' # Add plus sign for positive values
|
132 |
+
}
|
133 |
|
134 |
+
# Define gradient function for difference column
|
135 |
+
def color_difference(val):
|
136 |
"""Color the difference column from red to green"""
|
137 |
+
if pd.isna(val):
|
138 |
+
return ''
|
139 |
+
normalized = max(min(val / 10, 1), -1) # Scale of ±10%
|
140 |
+
if normalized > 0:
|
141 |
+
return f'background-color: rgba(0, 128, 0, {abs(normalized) * 0.4})'
|
142 |
+
return f'background-color: rgba(255, 0, 0, {abs(normalized) * 0.4})'
|
143 |
+
|
144 |
+
# Apply styling
|
|
|
|
|
|
|
|
|
|
|
145 |
styled = df.style\
|
146 |
+
.format(formatter)\
|
147 |
+
.applymap(color_difference, subset=['Difference'])\
|
|
|
|
|
|
|
148 |
.set_properties(**{
|
149 |
'padding': '10px',
|
150 |
'border': '1px solid #dee2e6',
|
app.py
CHANGED
@@ -74,41 +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 |
|
78 |
-
|
79 |
-
|
80 |
-
return f'background-color: rgba({int(255 * (1 - val))}, {int(255 * val)}, 0, 0.2)'
|
81 |
|
82 |
-
|
83 |
-
|
84 |
-
if
|
85 |
return []
|
86 |
normalized = (s - s.min()) / (s.max() - s.min()) if s.max() != s.min() else [0.5] * len(s)
|
87 |
-
return [
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
normalized = (val - df[col].min()) / (df[col].max() - df[col].min()) if df[col].max() != df[col].min() else 0.5
|
104 |
-
result[col_idx] = f'background-color: rgba({int(255 * (1 - normalized))}, {int(255 * normalized)}, 0, 0.2)'
|
105 |
-
if col == numeric_cols[0] and highlight_first_column:
|
106 |
-
result[col_idx] = result[col_idx] + '; font-weight: bold;'
|
107 |
-
|
108 |
-
return result
|
109 |
-
|
110 |
-
styled = styled.apply(highlight_and_color, axis=1)
|
111 |
-
|
112 |
styled = styled.set_properties(**{
|
113 |
'padding': '10px',
|
114 |
'border': '1px solid #dee2e6',
|
@@ -132,29 +123,28 @@ def style_dataframe(df, highlight_first_column=True, show_progress_bars=True):
|
|
132 |
|
133 |
def style_comparison_dataframe(df):
|
134 |
"""Style dataframe specifically for model comparison tables"""
|
135 |
-
numeric_cols = df.
|
|
|
|
|
|
|
|
|
|
|
|
|
136 |
|
137 |
-
|
|
|
138 |
"""Color the difference column from red to green"""
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
result[diff_idx] = f'background-color: rgba(0, 128, 0, {abs(normalized) * 0.3})'
|
148 |
-
else:
|
149 |
-
result[diff_idx] = f'background-color: rgba(255, 0, 0, {abs(normalized) * 0.3})'
|
150 |
-
return result
|
151 |
-
|
152 |
styled = df.style\
|
153 |
-
.format(
|
154 |
-
|
155 |
-
**{col: '{:.2f}%' for col in numeric_cols if col != 'Difference'}
|
156 |
-
})\
|
157 |
-
.apply(highlight_difference, axis=1)\
|
158 |
.set_properties(**{
|
159 |
'padding': '10px',
|
160 |
'border': '1px solid #dee2e6',
|
|
|
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 |
+
# Start with basic formatting
|
80 |
+
styled = df.style.format({col: '{:.2f}%' for col in numeric_cols})
|
|
|
81 |
|
82 |
+
# Function for color gradient
|
83 |
+
def color_gradient(s):
|
84 |
+
if s.empty:
|
85 |
return []
|
86 |
normalized = (s - s.min()) / (s.max() - s.min()) if s.max() != s.min() else [0.5] * len(s)
|
87 |
+
return ['background-color: rgba({}, {}, 0, 0.2)'.format(
|
88 |
+
int(255 * (1 - val)), int(255 * val)
|
89 |
+
) for val in normalized]
|
90 |
+
|
91 |
+
# Apply color gradient to all numeric columns if needed
|
92 |
+
if show_progress_bars:
|
93 |
+
for col in numeric_cols:
|
94 |
+
styled = styled.apply(color_gradient, subset=[col])
|
95 |
+
|
96 |
+
# Highlight first column if needed
|
97 |
+
if highlight_first_column and first_numeric_col:
|
98 |
+
styled = styled.apply(lambda x: ['background-color: rgba(74, 144, 226, 0.2); font-weight: bold;'
|
99 |
+
if col == first_numeric_col else ''
|
100 |
+
for col in df.columns], axis=0)
|
101 |
+
|
102 |
+
# Apply basic styling
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
103 |
styled = styled.set_properties(**{
|
104 |
'padding': '10px',
|
105 |
'border': '1px solid #dee2e6',
|
|
|
123 |
|
124 |
def style_comparison_dataframe(df):
|
125 |
"""Style dataframe specifically for model comparison tables"""
|
126 |
+
numeric_cols = [col for col in df.columns if col not in ['Class', 'Difference']]
|
127 |
+
|
128 |
+
# Basic formatting for numeric columns
|
129 |
+
formatter = {
|
130 |
+
**{col: '{:.2f}%' for col in numeric_cols},
|
131 |
+
'Difference': '{:+.2f}%' # Add plus sign for positive values
|
132 |
+
}
|
133 |
|
134 |
+
# Define gradient function for difference column
|
135 |
+
def color_difference(val):
|
136 |
"""Color the difference column from red to green"""
|
137 |
+
if pd.isna(val):
|
138 |
+
return ''
|
139 |
+
normalized = max(min(val / 10, 1), -1) # Scale of ±10%
|
140 |
+
if normalized > 0:
|
141 |
+
return f'background-color: rgba(0, 128, 0, {abs(normalized) * 0.4})'
|
142 |
+
return f'background-color: rgba(255, 0, 0, {abs(normalized) * 0.4})'
|
143 |
+
|
144 |
+
# Apply styling
|
|
|
|
|
|
|
|
|
|
|
145 |
styled = df.style\
|
146 |
+
.format(formatter)\
|
147 |
+
.applymap(color_difference, subset=['Difference'])\
|
|
|
|
|
|
|
148 |
.set_properties(**{
|
149 |
'padding': '10px',
|
150 |
'border': '1px solid #dee2e6',
|