Jellyfish042 commited on
Commit
234a449
·
1 Parent(s): 9ccd5a0

update Ui and data

Browse files
Files changed (2) hide show
  1. app.py +91 -14
  2. data/2025-01/1b5.xlsx +0 -0
app.py CHANGED
@@ -155,6 +155,7 @@ def update_table(
155
  visible_columns: list,
156
  color_columns: list,
157
  size_range: list,
 
158
  sort_by: str = "Average (lower=better)",
159
  ascending: bool = True,
160
  ):
@@ -201,16 +202,33 @@ def update_table(
201
 
202
  # color gradient
203
  colors = ["#63be7b", "#ffffff", "#f8696b"]
204
- cmap = LinearSegmentedColormap.from_list("custom_cmap", colors)
205
  vmin = {}
206
  vmax = {}
 
207
  for column in filtered_data.columns:
208
  if column in ["Name", "Params (B)"]:
209
  continue
210
  col_values = filtered_data[column]
211
  if len(col_values) > 1:
212
- vmin[column] = col_values.min()
213
- vmax[column] = col_values.max()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
214
 
215
  target_color_columns = []
216
  if "Average" in color_columns:
@@ -221,10 +239,16 @@ def update_table(
221
  styler = filtered_data.style.format(formatter).map(color_cell, subset=["Params (B)"])
222
 
223
  for column in target_color_columns:
224
- styler = styler.background_gradient(cmap=cmap, subset=[column], vmin=vmin[column], vmax=vmax[column])
 
 
 
 
 
 
 
225
 
226
  # return styler
227
-
228
  styler = styler.hide(axis="index")
229
 
230
  widths = [300, 150, 150, 100, 100, 100, 100, 100, 100, 100, 100]
@@ -232,11 +256,47 @@ def update_table(
232
 
233
  for i, w in enumerate(widths):
234
  table_styles.append(
235
- {"selector": f"th.col{i}", "props": [("min-width", f"{w}px"), ("max-width", f"{w}px"), ("text-align", "center")]} # 添加表头文字居中
 
 
 
 
 
 
 
236
  )
237
  table_styles.append(
238
- {"selector": f"td.col{i}", "props": [("min-width", f"{w}px"), ("max-width", f"{w}px"), ("text-align", "center")]} # 添加单元格文字居中
 
 
 
 
 
 
 
 
239
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
240
 
241
  styler = styler.set_table_styles(table_styles)
242
 
@@ -566,6 +626,7 @@ with gr.Blocks(css=css) as demo:
566
  size_range_slider = RangeSlider(minimum=0, maximum=15, value=[0, 15], step=0.1, label="Model Size Range")
567
  metric_selector = gr.Dropdown(label="Metric", choices=metric_list, value=initial_metric)
568
  with gr.Column():
 
569
  color_selector = gr.CheckboxGroup(label="Colored Columns", choices=["Average", "Individual Tests"], value=initial_colors)
570
  colfilter = gr.CheckboxGroup(label="Data Source", choices=get_unique_column_names(all_data), value=initial_columns)
571
 
@@ -578,22 +639,39 @@ with gr.Blocks(css=css) as demo:
578
  table = gr.HTML(initial_data)
579
 
580
  period_selector.change(
581
- update_table, inputs=[period_selector, model_selector, metric_selector, colfilter, color_selector, size_range_slider], outputs=table
 
 
582
  )
583
  model_selector.change(
584
- update_table, inputs=[period_selector, model_selector, metric_selector, colfilter, color_selector, size_range_slider], outputs=table
 
 
585
  )
586
  metric_selector.change(
587
- update_table, inputs=[period_selector, model_selector, metric_selector, colfilter, color_selector, size_range_slider], outputs=table
 
 
588
  )
589
  colfilter.change(
590
- update_table, inputs=[period_selector, model_selector, metric_selector, colfilter, color_selector, size_range_slider], outputs=table
 
 
591
  )
592
  color_selector.change(
593
- update_table, inputs=[period_selector, model_selector, metric_selector, colfilter, color_selector, size_range_slider], outputs=table
 
 
594
  )
595
  size_range_slider.change(
596
- update_table, inputs=[period_selector, model_selector, metric_selector, colfilter, color_selector, size_range_slider], outputs=table
 
 
 
 
 
 
 
597
  )
598
 
599
  with gr.Tab("🌍 MultiLang"):
@@ -601,7 +679,6 @@ with gr.Blocks(css=css) as demo:
601
  world_languages_plot = gr.Plot(create_world_languages_gdp_chart())
602
 
603
  with gr.Tab("📈 Scaling Law"):
604
- print(time_list)
605
  period_selector_2 = gr.Dropdown(label="Period", choices=time_list, value=last_period)
606
 
607
  def update_plot(period):
 
155
  visible_columns: list,
156
  color_columns: list,
157
  size_range: list,
158
+ midpoint: float = 0.5,
159
  sort_by: str = "Average (lower=better)",
160
  ascending: bool = True,
161
  ):
 
202
 
203
  # color gradient
204
  colors = ["#63be7b", "#ffffff", "#f8696b"]
 
205
  vmin = {}
206
  vmax = {}
207
+ vmid = {}
208
  for column in filtered_data.columns:
209
  if column in ["Name", "Params (B)"]:
210
  continue
211
  col_values = filtered_data[column]
212
  if len(col_values) > 1:
213
+ sorted_values = np.sort(col_values)
214
+ vmin[column] = sorted_values.min()
215
+ vmax[column] = sorted_values.max()
216
+ idx = int(len(sorted_values) * midpoint)
217
+ vmid[column] = sorted_values[idx]
218
+
219
+ def custom_background_gradient(series, cmap, vmin, vmax, vmid):
220
+ if len(series) == 0:
221
+ return series
222
+
223
+ def normalize(x):
224
+ if x <= vmid:
225
+ return 0.5 * (x - vmin) / (vmid - vmin)
226
+ else:
227
+ return 0.5 + 0.5 * (x - vmid) / (vmax - vmid)
228
+
229
+ normed = series.apply(normalize)
230
+ colors = [cmap(x) for x in normed]
231
+ return ["background-color: rgba({}, {}, {}, {})".format(*[int(255 * x) for x in c[:3]], c[3]) for c in colors]
232
 
233
  target_color_columns = []
234
  if "Average" in color_columns:
 
239
  styler = filtered_data.style.format(formatter).map(color_cell, subset=["Params (B)"])
240
 
241
  for column in target_color_columns:
242
+ styler = styler.apply(
243
+ custom_background_gradient,
244
+ cmap=LinearSegmentedColormap.from_list("custom_cmap", colors),
245
+ vmin=vmin[column],
246
+ vmax=vmax[column],
247
+ vmid=vmid[column],
248
+ subset=[column],
249
+ )
250
 
251
  # return styler
 
252
  styler = styler.hide(axis="index")
253
 
254
  widths = [300, 150, 150, 100, 100, 100, 100, 100, 100, 100, 100]
 
256
 
257
  for i, w in enumerate(widths):
258
  table_styles.append(
259
+ {
260
+ "selector": "th",
261
+ "props": [
262
+ ("background-color", "#f5f5f5"),
263
+ ("padding", "8px"),
264
+ ("font-weight", "bold"),
265
+ ],
266
+ }
267
  )
268
  table_styles.append(
269
+ {
270
+ "selector": f"th.col{i}",
271
+ "props": [
272
+ ("min-width", f"{w}px"),
273
+ ("max-width", f"{w}px"),
274
+ ("text-align", "center"),
275
+ ("border", "1px solid #dddddd"),
276
+ ],
277
+ }
278
  )
279
+ table_styles.append(
280
+ {
281
+ "selector": f"td.col{i}",
282
+ "props": [
283
+ ("min-width", f"{w}px"),
284
+ ("max-width", f"{w}px"),
285
+ ("text-align", "center"),
286
+ ("border", "1px solid #dddddd"),
287
+ ],
288
+ }
289
+ )
290
+
291
+ table_styles.append(
292
+ {
293
+ "selector": "table",
294
+ "props": [
295
+ ("border-collapse", "collapse"),
296
+ ("border", "1px solid #dddddd"),
297
+ ],
298
+ }
299
+ )
300
 
301
  styler = styler.set_table_styles(table_styles)
302
 
 
626
  size_range_slider = RangeSlider(minimum=0, maximum=15, value=[0, 15], step=0.1, label="Model Size Range")
627
  metric_selector = gr.Dropdown(label="Metric", choices=metric_list, value=initial_metric)
628
  with gr.Column():
629
+ midpoint_slider = gr.Slider(minimum=0.1, maximum=0.9, value=0.5, step=0.01, label="Color Gradient Midpoint")
630
  color_selector = gr.CheckboxGroup(label="Colored Columns", choices=["Average", "Individual Tests"], value=initial_colors)
631
  colfilter = gr.CheckboxGroup(label="Data Source", choices=get_unique_column_names(all_data), value=initial_columns)
632
 
 
639
  table = gr.HTML(initial_data)
640
 
641
  period_selector.change(
642
+ update_table,
643
+ inputs=[period_selector, model_selector, metric_selector, colfilter, color_selector, size_range_slider, midpoint_slider],
644
+ outputs=table,
645
  )
646
  model_selector.change(
647
+ update_table,
648
+ inputs=[period_selector, model_selector, metric_selector, colfilter, color_selector, size_range_slider, midpoint_slider],
649
+ outputs=table,
650
  )
651
  metric_selector.change(
652
+ update_table,
653
+ inputs=[period_selector, model_selector, metric_selector, colfilter, color_selector, size_range_slider, midpoint_slider],
654
+ outputs=table,
655
  )
656
  colfilter.change(
657
+ update_table,
658
+ inputs=[period_selector, model_selector, metric_selector, colfilter, color_selector, size_range_slider, midpoint_slider],
659
+ outputs=table,
660
  )
661
  color_selector.change(
662
+ update_table,
663
+ inputs=[period_selector, model_selector, metric_selector, colfilter, color_selector, size_range_slider, midpoint_slider],
664
+ outputs=table,
665
  )
666
  size_range_slider.change(
667
+ update_table,
668
+ inputs=[period_selector, model_selector, metric_selector, colfilter, color_selector, size_range_slider, midpoint_slider],
669
+ outputs=table,
670
+ )
671
+ midpoint_slider.change(
672
+ update_table,
673
+ inputs=[period_selector, model_selector, metric_selector, colfilter, color_selector, size_range_slider, midpoint_slider],
674
+ outputs=table,
675
  )
676
 
677
  with gr.Tab("🌍 MultiLang"):
 
679
  world_languages_plot = gr.Plot(create_world_languages_gdp_chart())
680
 
681
  with gr.Tab("📈 Scaling Law"):
 
682
  period_selector_2 = gr.Dropdown(label="Period", choices=time_list, value=last_period)
683
 
684
  def update_plot(period):
data/2025-01/1b5.xlsx CHANGED
Binary files a/data/2025-01/1b5.xlsx and b/data/2025-01/1b5.xlsx differ