Minette Kaunismäki commited on
Commit
335823a
·
1 Parent(s): 3f9b0a5

fixing samples

Browse files
Files changed (2) hide show
  1. app.py +21 -15
  2. ui.py +62 -53
app.py CHANGED
@@ -359,6 +359,12 @@ button.theme-toggle[data-mode="light"] .theme-icon-moon { display: block !import
359
  color: var(--pruna-tab-selected) !important;
360
  background: transparent !important;
361
  }
 
 
 
 
 
 
362
  .main-tabs .tab-container > button.selected::after,
363
  .main-tabs .tab-container > button[aria-selected="true"]::after {
364
  background: var(--pruna-accent-bright) !important;
@@ -1478,6 +1484,11 @@ button.theme-toggle[data-mode="light"] .theme-icon-moon { display: block !import
1478
  max-width: 100% !important;
1479
  min-width: 0 !important;
1480
  overflow-x: hidden !important;
 
 
 
 
 
1481
  }
1482
  .compare-row { display: grid; gap: 12px; min-width: 0; width: 100%; }
1483
  .compare-prompt-text { overflow-wrap: anywhere; }
@@ -1514,12 +1525,17 @@ button.theme-toggle[data-mode="light"] .theme-icon-moon { display: block !import
1514
  border: 1px solid var(--pruna-border);
1515
  background: var(--pruna-bg-elevated);
1516
  }
1517
- .compare-empty {
1518
- padding: 18px;
1519
- border: 1px dashed color-mix(in oklab, var(--pruna-border) 60%, transparent);
1520
- border-radius: 12px;
 
 
 
1521
  color: var(--pruna-text-muted);
1522
- text-align: center;
 
 
1523
  }
1524
 
1525
  /*
@@ -1694,16 +1710,6 @@ footer, .footer { display: none !important; }
1694
  padding: 0 !important;
1695
  margin: 0 0 12px !important;
1696
  }
1697
- .pareto-note-copy {
1698
- margin: 0;
1699
- padding: 14px 16px;
1700
- background: var(--pruna-callout-bg, var(--pruna-bg-card));
1701
- border: 1px dashed color-mix(in oklab, var(--pruna-border) 70%, transparent);
1702
- border-radius: 10px;
1703
- color: var(--pruna-text-muted);
1704
- font-size: 0.95rem;
1705
- line-height: 1.5;
1706
- }
1707
  .pareto-metric-block {
1708
  padding-bottom: 0.5rem;
1709
  border-bottom: 1px solid var(--pruna-hairline);
 
359
  color: var(--pruna-tab-selected) !important;
360
  background: transparent !important;
361
  }
362
+ .main-tabs .tab-container > button:disabled,
363
+ .main-tabs .tab-container > button[disabled] {
364
+ opacity: 0.4 !important;
365
+ color: var(--pruna-text-muted) !important;
366
+ cursor: not-allowed !important;
367
+ }
368
  .main-tabs .tab-container > button.selected::after,
369
  .main-tabs .tab-container > button[aria-selected="true"]::after {
370
  background: var(--pruna-accent-bright) !important;
 
1484
  max-width: 100% !important;
1485
  min-width: 0 !important;
1486
  overflow-x: hidden !important;
1487
+ border: none !important;
1488
+ background: transparent !important;
1489
+ box-shadow: none !important;
1490
+ padding: 0 !important;
1491
+ margin: 0 !important;
1492
  }
1493
  .compare-row { display: grid; gap: 12px; min-width: 0; width: 100%; }
1494
  .compare-prompt-text { overflow-wrap: anywhere; }
 
1525
  border: 1px solid var(--pruna-border);
1526
  background: var(--pruna-bg-elevated);
1527
  }
1528
+ .compare-empty,
1529
+ .pareto-note-copy {
1530
+ margin: 0;
1531
+ padding: 14px 16px;
1532
+ background: var(--pruna-callout-bg, var(--pruna-bg-card));
1533
+ border: 1px dashed color-mix(in oklab, var(--pruna-border) 70%, transparent);
1534
+ border-radius: 10px;
1535
  color: var(--pruna-text-muted);
1536
+ font-size: 0.95rem;
1537
+ line-height: 1.5;
1538
+ text-align: left;
1539
  }
1540
 
1541
  /*
 
1710
  padding: 0 !important;
1711
  margin: 0 0 12px !important;
1712
  }
 
 
 
 
 
 
 
 
 
 
1713
  .pareto-metric-block {
1714
  padding-bottom: 0.5rem;
1715
  border-bottom: 1px solid var(--pruna-hairline);
ui.py CHANGED
@@ -208,15 +208,15 @@ def _dataset_choices(datasets, *, require_samples=False):
208
  ]
209
 
210
 
211
- def _coerce_sample_dataset(datasets, dataset_id):
212
- """Prefer datasets that have compare-sample artifacts."""
213
  dataset = _item(datasets, dataset_id)
214
- if dataset and dataset.get("samples"):
215
- return dataset["id"]
216
- for candidate in datasets:
217
- if candidate.get("samples"):
218
- return candidate["id"]
219
- return dataset_id
 
220
 
221
 
222
  ALL_METRICS_ID = "__all__"
@@ -857,21 +857,11 @@ def _pareto_pair(data, score_column):
857
  def _pareto_dataset_message(data):
858
  has_price = data is not None and _PARETO_PRICE_COLUMN in data.columns
859
  has_time = data is not None and _PARETO_TIME_COLUMN in data.columns
860
- if has_price and has_time:
861
  return None
862
- if not has_price and not has_time:
863
- return (
864
- "Price per image and min generation time aren't available for "
865
- "this dataset, so these plots can't be drawn."
866
- )
867
- if not has_price:
868
- return (
869
- "Price per image isn't available for this dataset, so only min "
870
- "generation time vs score is shown."
871
- )
872
  return (
873
- "Min generation time isn't available for this dataset, so only "
874
- "price vs score is shown."
875
  )
876
 
877
 
@@ -879,6 +869,16 @@ def _pareto_slot_note(price_fig, price_message, time_fig, time_message, data):
879
  has_price = data is not None and _PARETO_PRICE_COLUMN in data.columns
880
  has_time = data is not None and _PARETO_TIME_COLUMN in data.columns
881
  notes = []
 
 
 
 
 
 
 
 
 
 
882
  if price_fig is None and has_price:
883
  notes.append(price_message)
884
  if time_fig is None and has_time:
@@ -941,7 +941,9 @@ def _pareto_slot_updates(data, score_columns):
941
 
942
  def _samples_html(samples, selected_models, num_prompts, seed=0):
943
  if not samples:
944
- return ""
 
 
945
  models = list(selected_models or [])
946
  available = samples.get("models") or []
947
  models = [model for model in models if model in samples.get("images", {})]
@@ -1100,13 +1102,7 @@ def render_image_workspace(datasets, metrics, default_dataset_id, default_metric
1100
  initial_data = initial["data"]
1101
  initial_columns = initial["columns"]
1102
  initial_score_columns = initial["score_columns"]
1103
- sample_dataset_id = _coerce_sample_dataset(datasets, default_dataset_id)
1104
- if sample_dataset_id == default_dataset_id:
1105
- initial_samples = initial.get("samples")
1106
- else:
1107
- initial_samples = resolve_view(
1108
- datasets, metrics, sample_dataset_id, None
1109
- ).get("samples")
1110
  with gr.Column(elem_classes="workspace-shell"):
1111
  with gr.Column(elem_classes="workspace-filters") as filters_host:
1112
  gr.Markdown(
@@ -1119,7 +1115,7 @@ def render_image_workspace(datasets, metrics, default_dataset_id, default_metric
1119
  dataset_dd, metric_dd, models_dd = _filter_row(
1120
  datasets, metrics, default_dataset_id, None
1121
  )
1122
- with gr.Tabs(elem_classes="main-tabs"):
1123
  with gr.TabItem("Leaderboards", id=TAB_LEADERBOARDS) as lb_tab:
1124
  lb_note = gr.Markdown(
1125
  _leaderboard_intro_markdown(initial.get("note")),
@@ -1178,7 +1174,11 @@ def render_image_workspace(datasets, metrics, default_dataset_id, default_metric
1178
  elem_classes="ranking-table-host",
1179
  )
1180
 
1181
- with gr.TabItem("Pareto Plots", id=TAB_PARETO) as pp_tab:
 
 
 
 
1182
  gr.Markdown(
1183
  "<p class='view-help'>"
1184
  "Score against price and generation time. Green points are on the "
@@ -1203,12 +1203,6 @@ def render_image_workspace(datasets, metrics, default_dataset_id, default_metric
1203
  "",
1204
  elem_classes="pareto-metric-title",
1205
  )
1206
- slot_note = gr.HTML(
1207
- "",
1208
- padding=False,
1209
- visible=False,
1210
- elem_classes="pareto-note",
1211
- )
1212
  with gr.Row(
1213
  equal_height=True,
1214
  elem_classes="pareto-layout",
@@ -1241,6 +1235,12 @@ def render_image_workspace(datasets, metrics, default_dataset_id, default_metric
1241
  show_label=False,
1242
  elem_classes="pareto-plot",
1243
  )
 
 
 
 
 
 
1244
  pareto_slots.append(
1245
  (
1246
  slot_group,
@@ -1254,7 +1254,11 @@ def render_image_workspace(datasets, metrics, default_dataset_id, default_metric
1254
  )
1255
  )
1256
 
1257
- with gr.TabItem("Samples", id=TAB_SAMPLES) as sm_tab:
 
 
 
 
1258
  with gr.Column(visible=bool(initial_samples)) as samples_panel:
1259
  gr.Markdown(
1260
  f"<p class='view-help'>"
@@ -1472,18 +1476,10 @@ def render_image_workspace(datasets, metrics, default_dataset_id, default_metric
1472
  else:
1473
  pareto_updates = _pareto_skip_updates()
1474
  if include_samples:
1475
- sample_dataset_id = _coerce_sample_dataset(datasets, dataset_id)
1476
- sample_view = resolve_view(datasets, metrics, sample_dataset_id, None)
1477
- samples = sample_view.get("samples") if sample_view else None
1478
- sample_models = [
1479
- model
1480
- for model in (models or [])
1481
- if model
1482
- in _model_choice_values(_model_choices(datasets, sample_dataset_id))
1483
- ]
1484
  samples_html = _samples_html(
1485
  samples,
1486
- sample_models,
1487
  int(num_prompts or DEFAULT_COMPARE_PROMPTS),
1488
  int(seed or 0),
1489
  )
@@ -1526,7 +1522,14 @@ def render_image_workspace(datasets, metrics, default_dataset_id, default_metric
1526
  == _selection_key(dataset_id, metric_id, models)
1527
  ):
1528
  return _skip_all(len(dataset_outputs))
1529
- flags = _content_flags(tab)
 
 
 
 
 
 
 
1530
  view = resolve_view(datasets, metrics, dataset_id, metric_id)
1531
  extras = _leaderboard_extras(
1532
  view["data"], platform_value, owner_value, optimized_value
@@ -1548,7 +1551,7 @@ def render_image_workspace(datasets, metrics, default_dataset_id, default_metric
1548
  "owner": extras[4],
1549
  "optimized": extras[5],
1550
  }
1551
- if tab == TAB_LEADERBOARDS
1552
  else {}
1553
  )
1554
  new_state = _commit_state(
@@ -1556,7 +1559,7 @@ def render_image_workspace(datasets, metrics, default_dataset_id, default_metric
1556
  dataset_id,
1557
  metric_id,
1558
  models,
1559
- tab,
1560
  flags,
1561
  extras=extras_payload,
1562
  )
@@ -1568,6 +1571,11 @@ def render_image_workspace(datasets, metrics, default_dataset_id, default_metric
1568
  extras[1],
1569
  extras[2],
1570
  *views,
 
 
 
 
 
1571
  new_state,
1572
  )
1573
 
@@ -1808,7 +1816,6 @@ def render_image_workspace(datasets, metrics, default_dataset_id, default_metric
1808
  )
1809
 
1810
  def on_samples_controls(dataset_id, models, num_prompts, seed):
1811
- dataset_id = _coerce_sample_dataset(datasets, dataset_id)
1812
  view = resolve_view(datasets, metrics, dataset_id, None)
1813
  return _samples_html(
1814
  view.get("samples") if view else None,
@@ -1818,7 +1825,6 @@ def render_image_workspace(datasets, metrics, default_dataset_id, default_metric
1818
  )
1819
 
1820
  def on_shuffle(dataset_id, models, num_prompts, seed):
1821
- dataset_id = _coerce_sample_dataset(datasets, dataset_id)
1822
  next_seed = int(seed or 0) + 1
1823
  view = resolve_view(datasets, metrics, dataset_id, None)
1824
  return next_seed, _samples_html(
@@ -1914,6 +1920,9 @@ def render_image_workspace(datasets, metrics, default_dataset_id, default_metric
1914
  owner,
1915
  optimized,
1916
  *view_outputs,
 
 
 
1917
  view_state,
1918
  ]
1919
  dataset_dd.change(
 
208
  ]
209
 
210
 
211
+ def _dataset_has_samples(datasets, dataset_id):
 
212
  dataset = _item(datasets, dataset_id)
213
+ return bool(dataset and dataset.get("samples"))
214
+
215
+
216
+ def _dataset_has_pareto(datasets, dataset_id):
217
+ dataset = _item(datasets, dataset_id)
218
+ columns = getattr(dataset.get("data") if dataset else None, "columns", [])
219
+ return _PARETO_PRICE_COLUMN in columns or _PARETO_TIME_COLUMN in columns
220
 
221
 
222
  ALL_METRICS_ID = "__all__"
 
857
  def _pareto_dataset_message(data):
858
  has_price = data is not None and _PARETO_PRICE_COLUMN in data.columns
859
  has_time = data is not None and _PARETO_TIME_COLUMN in data.columns
860
+ if has_price or has_time:
861
  return None
 
 
 
 
 
 
 
 
 
 
862
  return (
863
+ "Price per image and min generation time aren't available for "
864
+ "this dataset, so these plots can't be drawn."
865
  )
866
 
867
 
 
869
  has_price = data is not None and _PARETO_PRICE_COLUMN in data.columns
870
  has_time = data is not None and _PARETO_TIME_COLUMN in data.columns
871
  notes = []
872
+ if has_price and not has_time:
873
+ notes.append(
874
+ "Min generation time isn't available for this dataset, so only "
875
+ "price vs score is shown."
876
+ )
877
+ elif has_time and not has_price:
878
+ notes.append(
879
+ "Price per image isn't available for this dataset, so only min "
880
+ "generation time vs score is shown."
881
+ )
882
  if price_fig is None and has_price:
883
  notes.append(price_message)
884
  if time_fig is None and has_time:
 
941
 
942
  def _samples_html(samples, selected_models, num_prompts, seed=0):
943
  if not samples:
944
+ return _pareto_unavailable_html(
945
+ "Samples aren't available for this dataset."
946
+ )
947
  models = list(selected_models or [])
948
  available = samples.get("models") or []
949
  models = [model for model in models if model in samples.get("images", {})]
 
1102
  initial_data = initial["data"]
1103
  initial_columns = initial["columns"]
1104
  initial_score_columns = initial["score_columns"]
1105
+ initial_samples = initial.get("samples")
 
 
 
 
 
 
1106
  with gr.Column(elem_classes="workspace-shell"):
1107
  with gr.Column(elem_classes="workspace-filters") as filters_host:
1108
  gr.Markdown(
 
1115
  dataset_dd, metric_dd, models_dd = _filter_row(
1116
  datasets, metrics, default_dataset_id, None
1117
  )
1118
+ with gr.Tabs(elem_classes="main-tabs") as main_tabs:
1119
  with gr.TabItem("Leaderboards", id=TAB_LEADERBOARDS) as lb_tab:
1120
  lb_note = gr.Markdown(
1121
  _leaderboard_intro_markdown(initial.get("note")),
 
1174
  elem_classes="ranking-table-host",
1175
  )
1176
 
1177
+ with gr.TabItem(
1178
+ "Pareto Plots",
1179
+ id=TAB_PARETO,
1180
+ interactive=_dataset_has_pareto(datasets, default_dataset_id),
1181
+ ) as pp_tab:
1182
  gr.Markdown(
1183
  "<p class='view-help'>"
1184
  "Score against price and generation time. Green points are on the "
 
1203
  "",
1204
  elem_classes="pareto-metric-title",
1205
  )
 
 
 
 
 
 
1206
  with gr.Row(
1207
  equal_height=True,
1208
  elem_classes="pareto-layout",
 
1235
  show_label=False,
1236
  elem_classes="pareto-plot",
1237
  )
1238
+ slot_note = gr.HTML(
1239
+ "",
1240
+ padding=False,
1241
+ visible=False,
1242
+ elem_classes="pareto-note",
1243
+ )
1244
  pareto_slots.append(
1245
  (
1246
  slot_group,
 
1254
  )
1255
  )
1256
 
1257
+ with gr.TabItem(
1258
+ "Samples",
1259
+ id=TAB_SAMPLES,
1260
+ interactive=_dataset_has_samples(datasets, default_dataset_id),
1261
+ ) as sm_tab:
1262
  with gr.Column(visible=bool(initial_samples)) as samples_panel:
1263
  gr.Markdown(
1264
  f"<p class='view-help'>"
 
1476
  else:
1477
  pareto_updates = _pareto_skip_updates()
1478
  if include_samples:
1479
+ samples = view.get("samples")
 
 
 
 
 
 
 
 
1480
  samples_html = _samples_html(
1481
  samples,
1482
+ models,
1483
  int(num_prompts or DEFAULT_COMPARE_PROMPTS),
1484
  int(seed or 0),
1485
  )
 
1522
  == _selection_key(dataset_id, metric_id, models)
1523
  ):
1524
  return _skip_all(len(dataset_outputs))
1525
+ can_pareto = _dataset_has_pareto(datasets, dataset_id)
1526
+ can_samples = _dataset_has_samples(datasets, dataset_id)
1527
+ selected_tab = tab
1528
+ if tab == TAB_SAMPLES and not can_samples:
1529
+ selected_tab = TAB_LEADERBOARDS
1530
+ elif tab == TAB_PARETO and not can_pareto:
1531
+ selected_tab = TAB_LEADERBOARDS
1532
+ flags = _content_flags(selected_tab)
1533
  view = resolve_view(datasets, metrics, dataset_id, metric_id)
1534
  extras = _leaderboard_extras(
1535
  view["data"], platform_value, owner_value, optimized_value
 
1551
  "owner": extras[4],
1552
  "optimized": extras[5],
1553
  }
1554
+ if selected_tab == TAB_LEADERBOARDS
1555
  else {}
1556
  )
1557
  new_state = _commit_state(
 
1559
  dataset_id,
1560
  metric_id,
1561
  models,
1562
+ selected_tab,
1563
  flags,
1564
  extras=extras_payload,
1565
  )
 
1571
  extras[1],
1572
  extras[2],
1573
  *views,
1574
+ gr.update(interactive=can_pareto),
1575
+ gr.update(interactive=can_samples),
1576
+ gr.update(selected=selected_tab)
1577
+ if selected_tab != tab
1578
+ else gr.skip(),
1579
  new_state,
1580
  )
1581
 
 
1816
  )
1817
 
1818
  def on_samples_controls(dataset_id, models, num_prompts, seed):
 
1819
  view = resolve_view(datasets, metrics, dataset_id, None)
1820
  return _samples_html(
1821
  view.get("samples") if view else None,
 
1825
  )
1826
 
1827
  def on_shuffle(dataset_id, models, num_prompts, seed):
 
1828
  next_seed = int(seed or 0) + 1
1829
  view = resolve_view(datasets, metrics, dataset_id, None)
1830
  return next_seed, _samples_html(
 
1920
  owner,
1921
  optimized,
1922
  *view_outputs,
1923
+ pp_tab,
1924
+ sm_tab,
1925
+ main_tabs,
1926
  view_state,
1927
  ]
1928
  dataset_dd.change(