Spaces:
Sleeping
Redesign app.py: dark monospace terminal aesthetic
Browse filesFull CSS overhaul targeting Gradio 6:
- #0a0a0a background, #111111 card surfaces, #00ff88 accent
- JetBrains Mono (code/numbers) + Inter (body) via Google Fonts
- Sharp corners (border-radius: 0) throughout; no Gradio blue anywhere
- Tab nav, buttons, inputs, sliders, tables, scrollbars all restyled
- Lowercase labels, no emoji, inline [error]/[warn]/[critical] prefixes
- Custom header: "haptal-curate" in mono green + muted subtitle, one line
- Custom footer: arxiv IDs + github link, muted mono, no framework mention
Charts: matplotlib rcParams set globally for dark bg, accent bars,
muted axis labels; kept=green/removed=red in tab 1,
clean=green/defective=red in tab 2; side-by-side confound comparison.
Tab 1 adds: phase-gated toggle, JSON download output
Tab 2 adds: "// no robot data needed" note, compare-without-truncation chart
|
@@ -1,6 +1,8 @@
|
|
| 1 |
-
"""
|
|
|
|
| 2 |
import os
|
| 3 |
import tempfile
|
|
|
|
| 4 |
|
| 5 |
import matplotlib
|
| 6 |
matplotlib.use("Agg")
|
|
@@ -11,244 +13,282 @@ import h5py
|
|
| 11 |
|
| 12 |
import haptal_curate as hc
|
| 13 |
from haptal_curate.metrics import (
|
| 14 |
-
EnsembleMetric,
|
| 15 |
-
|
| 16 |
-
GripperTimingMetric,
|
| 17 |
-
EntropyMetric,
|
| 18 |
-
IsolationForestMetric,
|
| 19 |
-
KNNMetric,
|
| 20 |
-
TrajectoryAlignmentMetric,
|
| 21 |
)
|
|
|
|
| 22 |
from haptal_curate.confounds import detect_length_confound
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
#
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
METRIC_CHOICES = [
|
| 29 |
-
"
|
| 30 |
-
"
|
| 31 |
-
"
|
| 32 |
-
"
|
| 33 |
-
"
|
| 34 |
-
"
|
| 35 |
-
"
|
| 36 |
]
|
| 37 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
|
| 39 |
def _build_metric(name: str):
|
| 40 |
-
return
|
| 41 |
-
"Ensemble (smoothness + gripper timing)": EnsembleMetric,
|
| 42 |
-
"Smoothness (SPARC)": SmoothnessMetric,
|
| 43 |
-
"Gripper Timing": GripperTimingMetric,
|
| 44 |
-
"Entropy (neg. action std)": EntropyMetric,
|
| 45 |
-
"Isolation Forest": IsolationForestMetric,
|
| 46 |
-
"k-NN Distance": KNNMetric,
|
| 47 |
-
"Trajectory Alignment": TrajectoryAlignmentMetric,
|
| 48 |
-
}[name]()
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
def _score_bar(scores, sorted_idx, color_fn, title):
|
| 52 |
-
fig, ax = plt.subplots(figsize=(7, 3))
|
| 53 |
-
colors = [color_fn(i) for i in sorted_idx]
|
| 54 |
-
ax.bar(range(len(scores)), scores[sorted_idx], color=colors, width=1.0, linewidth=0)
|
| 55 |
-
ax.set_xlabel("Demo rank (best β worst)")
|
| 56 |
-
ax.set_ylabel("Quality score")
|
| 57 |
-
ax.set_title(title)
|
| 58 |
-
ax.spines[["top", "right"]].set_visible(False)
|
| 59 |
-
fig.tight_layout()
|
| 60 |
-
return fig
|
| 61 |
|
| 62 |
|
| 63 |
-
|
| 64 |
-
|
| 65 |
rng = np.random.default_rng(seed)
|
| 66 |
with h5py.File(path, "w") as f:
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
for _ in range(n_clean):
|
| 70 |
T = int(rng.integers(300, 330))
|
| 71 |
-
dg =
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
actions
|
| 76 |
-
dg.
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
data=rng.standard_normal((T, 3)).astype(np.float32))
|
| 80 |
-
idx += 1
|
| 81 |
-
for _ in range(n_defective):
|
| 82 |
T = 500
|
| 83 |
-
dg =
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
actions
|
| 88 |
-
dg.
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
if hdf5_file is None:
|
| 101 |
-
return "
|
| 102 |
|
| 103 |
try:
|
| 104 |
path = hdf5_file if isinstance(hdf5_file, str) else hdf5_file.name
|
| 105 |
metric = _build_metric(metric_name)
|
| 106 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 107 |
curation = hc.curate(result, fraction=float(fraction))
|
| 108 |
-
summary
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
|
|
|
|
|
|
|
|
|
|
| 110 |
kept_set = set(curation.kept_indices.tolist())
|
| 111 |
sorted_idx = np.argsort(result.scores)[::-1]
|
| 112 |
table = [
|
| 113 |
-
[
|
| 114 |
-
|
| 115 |
-
result.demo_ids[i],
|
| 116 |
-
f"{result.scores[i]:.4f}",
|
| 117 |
-
"β kept" if i in kept_set else "β removed",
|
| 118 |
-
]
|
| 119 |
for rank, i in enumerate(sorted_idx)
|
| 120 |
]
|
| 121 |
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
)
|
| 140 |
-
|
| 141 |
-
fig = _score_bar(
|
| 142 |
-
result.scores,
|
| 143 |
-
sorted_idx,
|
| 144 |
-
color_fn=lambda i: "#2196F3" if i in kept_set else "#EF5350",
|
| 145 |
-
title=f"{metric_name} | blue = kept, red = removed",
|
| 146 |
-
)
|
| 147 |
-
return text, table, fig
|
| 148 |
|
| 149 |
except Exception as exc:
|
| 150 |
-
|
| 151 |
-
return
|
| 152 |
|
| 153 |
|
| 154 |
-
#
|
| 155 |
-
|
| 156 |
-
# ---------------------------------------------------------------------------
|
| 157 |
-
|
| 158 |
-
def run_synthetic(n_clean, n_defective, metric_name, fraction, show_confound):
|
| 159 |
n_clean, n_defective = int(n_clean), int(n_defective)
|
| 160 |
tmp = tempfile.NamedTemporaryFile(suffix=".hdf5", delete=False)
|
| 161 |
path = tmp.name
|
| 162 |
tmp.close()
|
| 163 |
|
| 164 |
try:
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
lines = [f"Dataset: {n_clean} clean + {n_defective} defective demos"]
|
| 168 |
|
| 169 |
-
# Optionally show untruncated (confounded) run
|
| 170 |
result_raw = None
|
| 171 |
-
|
|
|
|
| 172 |
result_raw = hc.score(
|
| 173 |
-
path, metrics=[_build_metric(metric_name)], truncate_t=None
|
| 174 |
-
)
|
| 175 |
cr = detect_length_confound(result_raw.scores, result_raw.episode_lengths)
|
| 176 |
-
|
| 177 |
"",
|
| 178 |
-
"
|
| 179 |
-
f"
|
| 180 |
f" {cr.message}",
|
| 181 |
]
|
| 182 |
|
| 183 |
-
|
| 184 |
-
result = hc.score(path, metrics=[_build_metric(metric_name)], truncate_t=324)
|
| 185 |
curation = hc.curate(result, fraction=float(fraction))
|
| 186 |
-
summary
|
| 187 |
-
|
| 188 |
-
lines
|
| 189 |
-
"",
|
| 190 |
-
"
|
| 191 |
-
f"
|
| 192 |
-
f"
|
| 193 |
-
f"({summary['curation']['fraction_kept']:.0%})",
|
| 194 |
-
f"
|
| 195 |
-
f"
|
| 196 |
-
]
|
| 197 |
|
| 198 |
text = "\n".join(lines)
|
| 199 |
|
| 200 |
-
#
|
| 201 |
kept_set = set(curation.kept_indices.tolist())
|
| 202 |
sorted_idx = np.argsort(result.scores)[::-1]
|
| 203 |
table = [
|
| 204 |
-
[
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
f"{result.scores[i]:.4f}",
|
| 208 |
-
"β kept" if i in kept_set else "β removed",
|
| 209 |
-
"defective" if i >= n_clean else "clean",
|
| 210 |
-
]
|
| 211 |
for rank, i in enumerate(sorted_idx)
|
| 212 |
]
|
| 213 |
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
axes = [axes]
|
| 219 |
-
|
| 220 |
-
# Truncated subplot (always last)
|
| 221 |
-
s_idx = np.argsort(result.scores)[::-1]
|
| 222 |
-
axes[-1].bar(
|
| 223 |
-
range(len(result.scores)),
|
| 224 |
-
result.scores[s_idx],
|
| 225 |
-
color=["#EF5350" if i >= n_clean else "#2196F3" for i in s_idx],
|
| 226 |
-
width=1.0, linewidth=0,
|
| 227 |
-
)
|
| 228 |
-
axes[-1].set_title("t = 324 | blue = clean, red = defective")
|
| 229 |
-
axes[-1].set_xlabel("Demo rank")
|
| 230 |
-
axes[-1].set_ylabel("Quality score")
|
| 231 |
-
axes[-1].spines[["top", "right"]].set_visible(False)
|
| 232 |
-
|
| 233 |
-
if ncols == 2:
|
| 234 |
-
r_idx = np.argsort(result_raw.scores)[::-1]
|
| 235 |
-
axes[0].bar(
|
| 236 |
-
range(len(result_raw.scores)),
|
| 237 |
-
result_raw.scores[r_idx],
|
| 238 |
-
color=["#EF5350" if i >= n_clean else "#2196F3" for i in r_idx],
|
| 239 |
-
width=1.0, linewidth=0,
|
| 240 |
-
)
|
| 241 |
-
axes[0].set_title("No truncation (length confound)")
|
| 242 |
-
axes[0].set_xlabel("Demo rank")
|
| 243 |
-
axes[0].set_ylabel("Quality score")
|
| 244 |
-
axes[0].spines[["top", "right"]].set_visible(False)
|
| 245 |
|
| 246 |
-
fig.tight_layout()
|
| 247 |
return text, table, fig
|
| 248 |
|
| 249 |
except Exception as exc:
|
| 250 |
-
|
| 251 |
-
return f"Error: {exc}\n\n{traceback.format_exc()}", [], None
|
| 252 |
|
| 253 |
finally:
|
| 254 |
try:
|
|
@@ -257,114 +297,462 @@ def run_synthetic(n_clean, n_defective, metric_name, fraction, show_confound):
|
|
| 257 |
pass
|
| 258 |
|
| 259 |
|
| 260 |
-
#
|
| 261 |
-
|
| 262 |
-
|
| 263 |
-
|
| 264 |
-
|
| 265 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 266 |
|
| 267 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 268 |
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 272 |
|
| 273 |
-
|
| 274 |
-
|
|
|
|
|
|
|
| 275 |
"""
|
| 276 |
|
|
|
|
| 277 |
with gr.Blocks(title="haptal-curate") as demo:
|
| 278 |
-
|
|
|
|
| 279 |
|
| 280 |
with gr.Tabs():
|
| 281 |
|
| 282 |
-
# ββ
|
| 283 |
-
with gr.Tab("
|
| 284 |
-
gr.Markdown(
|
| 285 |
-
"Upload a LIBERO-format HDF5 file, choose a quality metric, "
|
| 286 |
-
"and curate the dataset."
|
| 287 |
-
)
|
| 288 |
with gr.Row():
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 313 |
)
|
|
|
|
| 314 |
|
| 315 |
t1_btn.click(
|
| 316 |
fn=run_score_curate,
|
| 317 |
-
inputs=[t1_file, t1_metric, t1_trunc, t1_frac],
|
| 318 |
-
outputs=[t1_summary, t1_table, t1_plot],
|
| 319 |
)
|
| 320 |
|
| 321 |
-
# ββ
|
| 322 |
-
with gr.Tab("
|
| 323 |
-
gr.Markdown(
|
| 324 |
-
"Generate synthetic demonstrations (no LIBERO needed) and run "
|
| 325 |
-
"the full scoring pipeline. Toggle **Show length confound** to "
|
| 326 |
-
"see what happens *without* truncation."
|
| 327 |
-
)
|
| 328 |
with gr.Row():
|
| 329 |
-
|
| 330 |
-
|
| 331 |
-
|
| 332 |
-
|
| 333 |
-
|
| 334 |
-
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
| 352 |
-
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 360 |
)
|
| 361 |
|
| 362 |
t2_btn.click(
|
| 363 |
fn=run_synthetic,
|
| 364 |
-
inputs=[
|
| 365 |
outputs=[t2_summary, t2_table, t2_plot],
|
| 366 |
)
|
| 367 |
|
|
|
|
| 368 |
|
| 369 |
if __name__ == "__main__":
|
| 370 |
-
demo.launch(theme=gr.themes.
|
|
|
|
| 1 |
+
"""haptal-curate β dark, monospace, minimal Gradio UI."""
|
| 2 |
+
import json
|
| 3 |
import os
|
| 4 |
import tempfile
|
| 5 |
+
import traceback
|
| 6 |
|
| 7 |
import matplotlib
|
| 8 |
matplotlib.use("Agg")
|
|
|
|
| 13 |
|
| 14 |
import haptal_curate as hc
|
| 15 |
from haptal_curate.metrics import (
|
| 16 |
+
EnsembleMetric, SmoothnessMetric, GripperTimingMetric,
|
| 17 |
+
EntropyMetric, IsolationForestMetric, KNNMetric, TrajectoryAlignmentMetric,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
)
|
| 19 |
+
from haptal_curate.phase import PhaseGatedScorer
|
| 20 |
from haptal_curate.confounds import detect_length_confound
|
| 21 |
+
from haptal_curate.types import ScoreResult
|
| 22 |
+
|
| 23 |
+
# ββ chart theme ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 24 |
+
ACCENT = "#00ff88"
|
| 25 |
+
RED = "#ff4444"
|
| 26 |
+
SURFACE = "#111111"
|
| 27 |
+
MUTED = "#555555"
|
| 28 |
+
BORDER = "#222222"
|
| 29 |
+
|
| 30 |
+
plt.rcParams.update({
|
| 31 |
+
"figure.facecolor": SURFACE,
|
| 32 |
+
"axes.facecolor": "#0d0d0d",
|
| 33 |
+
"axes.edgecolor": BORDER,
|
| 34 |
+
"axes.labelcolor": MUTED,
|
| 35 |
+
"axes.titlecolor": "#888888",
|
| 36 |
+
"axes.titlesize": 10,
|
| 37 |
+
"axes.labelsize": 9,
|
| 38 |
+
"xtick.color": MUTED,
|
| 39 |
+
"ytick.color": MUTED,
|
| 40 |
+
"xtick.labelsize": 9,
|
| 41 |
+
"ytick.labelsize": 9,
|
| 42 |
+
"text.color": "#cccccc",
|
| 43 |
+
"grid.color": "#1a1a1a",
|
| 44 |
+
"grid.linewidth": 0.5,
|
| 45 |
+
"font.family": "monospace",
|
| 46 |
+
"font.size": 9,
|
| 47 |
+
"figure.dpi": 130,
|
| 48 |
+
"axes.spines.top": False,
|
| 49 |
+
"axes.spines.right": False,
|
| 50 |
+
})
|
| 51 |
+
|
| 52 |
+
# ββ metric registry βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 53 |
METRIC_CHOICES = [
|
| 54 |
+
"ensemble",
|
| 55 |
+
"smoothness",
|
| 56 |
+
"gripper_timing",
|
| 57 |
+
"entropy",
|
| 58 |
+
"isolation_forest",
|
| 59 |
+
"knn",
|
| 60 |
+
"trajectory_alignment",
|
| 61 |
]
|
| 62 |
|
| 63 |
+
_METRIC_MAP = {
|
| 64 |
+
"ensemble": EnsembleMetric,
|
| 65 |
+
"smoothness": SmoothnessMetric,
|
| 66 |
+
"gripper_timing": GripperTimingMetric,
|
| 67 |
+
"entropy": EntropyMetric,
|
| 68 |
+
"isolation_forest": IsolationForestMetric,
|
| 69 |
+
"knn": KNNMetric,
|
| 70 |
+
"trajectory_alignment": TrajectoryAlignmentMetric,
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
|
| 74 |
def _build_metric(name: str):
|
| 75 |
+
return _METRIC_MAP[name]()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
|
| 77 |
|
| 78 |
+
# ββ synthetic data ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 79 |
+
def _make_synthetic_hdf5(path: str, n_clean: int, n_defective: int, seed: int = 42):
|
| 80 |
rng = np.random.default_rng(seed)
|
| 81 |
with h5py.File(path, "w") as f:
|
| 82 |
+
g = f.create_group("data")
|
| 83 |
+
for k in range(n_clean):
|
|
|
|
| 84 |
T = int(rng.integers(300, 330))
|
| 85 |
+
dg = g.create_group(f"demo_{k}")
|
| 86 |
+
a = (rng.standard_normal((T, 7)) * 0.05).astype(np.float32)
|
| 87 |
+
a[:, -1] = -1.0
|
| 88 |
+
a[int(rng.integers(int(T * 0.8), T)):, -1] = 1.0
|
| 89 |
+
dg.create_dataset("actions", data=a)
|
| 90 |
+
dg.create_group("obs").create_dataset(
|
| 91 |
+
"robot0_eef_pos", data=rng.standard_normal((T, 3)).astype(np.float32))
|
| 92 |
+
for k in range(n_defective):
|
|
|
|
|
|
|
|
|
|
| 93 |
T = 500
|
| 94 |
+
dg = g.create_group(f"demo_{n_clean + k}")
|
| 95 |
+
a = (rng.standard_normal((T, 7)) * 0.3).astype(np.float32)
|
| 96 |
+
a[:, -1] = -1.0
|
| 97 |
+
a[int(rng.integers(50, 150)):, -1] = 1.0
|
| 98 |
+
dg.create_dataset("actions", data=a)
|
| 99 |
+
dg.create_group("obs").create_dataset(
|
| 100 |
+
"robot0_eef_pos", data=rng.standard_normal((T, 3)).astype(np.float32))
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
# ββ charts ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 104 |
+
def _bar_chart(scores, sorted_idx, colors, xlabel, title, figsize=(7, 2.8)):
|
| 105 |
+
fig, ax = plt.subplots(figsize=figsize)
|
| 106 |
+
ax.bar(range(len(scores)), scores[sorted_idx],
|
| 107 |
+
color=colors, width=1.0, linewidth=0)
|
| 108 |
+
ax.set_xlabel(xlabel, labelpad=6)
|
| 109 |
+
ax.set_ylabel("score", labelpad=6)
|
| 110 |
+
ax.set_title(title, pad=8)
|
| 111 |
+
ax.set_xlim(-0.5, len(scores) - 0.5)
|
| 112 |
+
fig.tight_layout(pad=1.2)
|
| 113 |
+
return fig
|
| 114 |
+
|
| 115 |
+
|
| 116 |
+
def _score_chart(result, curation):
|
| 117 |
+
kept_set = set(curation.kept_indices.tolist())
|
| 118 |
+
idx = np.argsort(result.scores)[::-1]
|
| 119 |
+
colors = [ACCENT if i in kept_set else RED for i in idx]
|
| 120 |
+
return _bar_chart(result.scores, idx, colors,
|
| 121 |
+
"demo rank (best β worst)",
|
| 122 |
+
f"{result.metric_name} | green = kept red = removed")
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
def _confound_chart(result_raw, result_trunc, n_clean):
|
| 126 |
+
fig, axes = plt.subplots(1, 2, figsize=(11, 2.8))
|
| 127 |
+
for ax, res, title in [
|
| 128 |
+
(axes[0], result_raw, "no truncation (length confound)"),
|
| 129 |
+
(axes[1], result_trunc, "truncated at t=324"),
|
| 130 |
+
]:
|
| 131 |
+
idx = np.argsort(res.scores)[::-1]
|
| 132 |
+
colors = [RED if i >= n_clean else ACCENT for i in idx]
|
| 133 |
+
ax.bar(range(len(res.scores)), res.scores[idx],
|
| 134 |
+
color=colors, width=1.0, linewidth=0)
|
| 135 |
+
ax.set_title(title, pad=8)
|
| 136 |
+
ax.set_xlabel("demo rank", labelpad=6)
|
| 137 |
+
ax.set_ylabel("score", labelpad=6)
|
| 138 |
+
ax.set_xlim(-0.5, len(res.scores) - 0.5)
|
| 139 |
+
fig.tight_layout(pad=1.4)
|
| 140 |
+
return fig
|
| 141 |
+
|
| 142 |
+
|
| 143 |
+
def _single_chart(result, n_clean):
|
| 144 |
+
idx = np.argsort(result.scores)[::-1]
|
| 145 |
+
colors = [RED if i >= n_clean else ACCENT for i in idx]
|
| 146 |
+
return _bar_chart(result.scores, idx, colors,
|
| 147 |
+
"demo rank (best β worst)",
|
| 148 |
+
"truncated at t=324 | green = clean red = defective")
|
| 149 |
+
|
| 150 |
+
|
| 151 |
+
# ββ tab 1 handler βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 152 |
+
def run_score_curate(hdf5_file, metric_name, phase_gated, truncate_t, fraction):
|
| 153 |
if hdf5_file is None:
|
| 154 |
+
return "[error] no file uploaded", [], None, None
|
| 155 |
|
| 156 |
try:
|
| 157 |
path = hdf5_file if isinstance(hdf5_file, str) else hdf5_file.name
|
| 158 |
metric = _build_metric(metric_name)
|
| 159 |
+
dataset = hc.load_demos(path, truncate_t=int(truncate_t))
|
| 160 |
+
|
| 161 |
+
if phase_gated:
|
| 162 |
+
scorer = PhaseGatedScorer(metric, strategy="uniform")
|
| 163 |
+
scorer.fit(dataset)
|
| 164 |
+
scores_arr = scorer.score_dataset(dataset)
|
| 165 |
+
result = ScoreResult(
|
| 166 |
+
scores=scores_arr,
|
| 167 |
+
demo_ids=[d.demo_id for d in dataset.demos],
|
| 168 |
+
metric_name=f"phase-gated:{metric_name}",
|
| 169 |
+
episode_lengths=np.array([d.episode_length for d in dataset.demos]),
|
| 170 |
+
)
|
| 171 |
+
else:
|
| 172 |
+
result = hc.score(dataset, metrics=[metric])
|
| 173 |
+
|
| 174 |
curation = hc.curate(result, fraction=float(fraction))
|
| 175 |
+
summary = hc.report(result, curation)
|
| 176 |
+
|
| 177 |
+
# confound line
|
| 178 |
+
confound_lines = []
|
| 179 |
+
if "confound" in summary:
|
| 180 |
+
c = summary["confound"]
|
| 181 |
+
sev = c["severity"]
|
| 182 |
+
prefix = "[warn]" if sev in ("mild", "moderate") else "[critical]" if sev == "severe" else "[ok]"
|
| 183 |
+
confound_lines = [
|
| 184 |
+
"",
|
| 185 |
+
f"{prefix} length confound: {sev} (spearman r={c['spearman_r']:.3f})",
|
| 186 |
+
f" {c['message']}",
|
| 187 |
+
]
|
| 188 |
+
|
| 189 |
+
lines = [
|
| 190 |
+
f"metric {result.metric_name}",
|
| 191 |
+
f"demos {summary['n_demos']}",
|
| 192 |
+
f"score meanΒ±std {summary['score_mean']:.4f} Β± {summary['score_std']:.4f}",
|
| 193 |
+
f"score range [{summary['score_min']:.4f}, {summary['score_max']:.4f}]",
|
| 194 |
+
f"kept {summary['curation']['n_kept']} / {summary['n_demos']}"
|
| 195 |
+
f" ({summary['curation']['fraction_kept']:.0%})",
|
| 196 |
+
f"top-5 {', '.join(summary['top5_demo_ids'])}",
|
| 197 |
+
f"bottom-5 {', '.join(summary['bottom5_demo_ids'])}",
|
| 198 |
+
] + confound_lines
|
| 199 |
|
| 200 |
+
text = "\n".join(lines)
|
| 201 |
+
|
| 202 |
+
# table
|
| 203 |
kept_set = set(curation.kept_indices.tolist())
|
| 204 |
sorted_idx = np.argsort(result.scores)[::-1]
|
| 205 |
table = [
|
| 206 |
+
[rank + 1, result.demo_ids[i], f"{result.scores[i]:.4f}",
|
| 207 |
+
"kept" if i in kept_set else "removed"]
|
|
|
|
|
|
|
|
|
|
|
|
|
| 208 |
for rank, i in enumerate(sorted_idx)
|
| 209 |
]
|
| 210 |
|
| 211 |
+
# download json
|
| 212 |
+
download_data = {
|
| 213 |
+
"metric": result.metric_name,
|
| 214 |
+
"truncate_t": int(truncate_t),
|
| 215 |
+
"kept_fraction": float(fraction),
|
| 216 |
+
"n_kept": int(len(curation.kept_indices)),
|
| 217 |
+
"kept_demo_ids": [result.demo_ids[i] for i in curation.kept_indices],
|
| 218 |
+
"scores": {result.demo_ids[i]: float(result.scores[i])
|
| 219 |
+
for i in range(len(result.scores))},
|
| 220 |
+
}
|
| 221 |
+
tmp_json = tempfile.NamedTemporaryFile(
|
| 222 |
+
mode="w", suffix=".json", delete=False, prefix="haptal_curate_")
|
| 223 |
+
json.dump(download_data, tmp_json, indent=2)
|
| 224 |
+
tmp_json.close()
|
| 225 |
+
|
| 226 |
+
fig = _score_chart(result, curation)
|
| 227 |
+
return text, table, fig, tmp_json.name
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 228 |
|
| 229 |
except Exception as exc:
|
| 230 |
+
msg = f"[error] {exc}\n\n{traceback.format_exc()}"
|
| 231 |
+
return msg, [], None, None
|
| 232 |
|
| 233 |
|
| 234 |
+
# ββ tab 2 handler βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 235 |
+
def run_synthetic(n_clean, n_defective, metric_name, fraction, compare_confound):
|
|
|
|
|
|
|
|
|
|
| 236 |
n_clean, n_defective = int(n_clean), int(n_defective)
|
| 237 |
tmp = tempfile.NamedTemporaryFile(suffix=".hdf5", delete=False)
|
| 238 |
path = tmp.name
|
| 239 |
tmp.close()
|
| 240 |
|
| 241 |
try:
|
| 242 |
+
_make_synthetic_hdf5(path, n_clean=n_clean, n_defective=n_defective)
|
|
|
|
|
|
|
| 243 |
|
|
|
|
| 244 |
result_raw = None
|
| 245 |
+
confound_lines = []
|
| 246 |
+
if compare_confound:
|
| 247 |
result_raw = hc.score(
|
| 248 |
+
path, metrics=[_build_metric(metric_name)], truncate_t=None)
|
|
|
|
| 249 |
cr = detect_length_confound(result_raw.scores, result_raw.episode_lengths)
|
| 250 |
+
confound_lines = [
|
| 251 |
"",
|
| 252 |
+
f"without truncation:",
|
| 253 |
+
f" length confound {cr.severity} (r={cr.spearman_r:.3f})",
|
| 254 |
f" {cr.message}",
|
| 255 |
]
|
| 256 |
|
| 257 |
+
result = hc.score(path, metrics=[_build_metric(metric_name)], truncate_t=324)
|
|
|
|
| 258 |
curation = hc.curate(result, fraction=float(fraction))
|
| 259 |
+
summary = hc.report(result, curation)
|
| 260 |
+
|
| 261 |
+
lines = [
|
| 262 |
+
f"dataset {n_clean} clean + {n_defective} defective",
|
| 263 |
+
f"metric {metric_name}",
|
| 264 |
+
f"score meanΒ±std {summary['score_mean']:.4f} Β± {summary['score_std']:.4f}",
|
| 265 |
+
f"kept {summary['curation']['n_kept']} / {summary['n_demos']}"
|
| 266 |
+
f" ({summary['curation']['fraction_kept']:.0%})",
|
| 267 |
+
f"top-5 {', '.join(summary['top5_demo_ids'])}",
|
| 268 |
+
f"bottom-5 {', '.join(summary['bottom5_demo_ids'])}",
|
| 269 |
+
] + confound_lines
|
| 270 |
|
| 271 |
text = "\n".join(lines)
|
| 272 |
|
| 273 |
+
# table
|
| 274 |
kept_set = set(curation.kept_indices.tolist())
|
| 275 |
sorted_idx = np.argsort(result.scores)[::-1]
|
| 276 |
table = [
|
| 277 |
+
[rank + 1, result.demo_ids[i], f"{result.scores[i]:.4f}",
|
| 278 |
+
"kept" if i in kept_set else "removed",
|
| 279 |
+
"defective" if i >= n_clean else "clean"]
|
|
|
|
|
|
|
|
|
|
|
|
|
| 280 |
for rank, i in enumerate(sorted_idx)
|
| 281 |
]
|
| 282 |
|
| 283 |
+
if compare_confound and result_raw is not None:
|
| 284 |
+
fig = _confound_chart(result_raw, result, n_clean)
|
| 285 |
+
else:
|
| 286 |
+
fig = _single_chart(result, n_clean)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 287 |
|
|
|
|
| 288 |
return text, table, fig
|
| 289 |
|
| 290 |
except Exception as exc:
|
| 291 |
+
return f"[error] {exc}\n\n{traceback.format_exc()}", [], None
|
|
|
|
| 292 |
|
| 293 |
finally:
|
| 294 |
try:
|
|
|
|
| 297 |
pass
|
| 298 |
|
| 299 |
|
| 300 |
+
# ββ CSS βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 301 |
+
CSS = """
|
| 302 |
+
@import url('https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;700&family=Inter:wght@400;500&display=swap');
|
| 303 |
+
|
| 304 |
+
/* ββ variables ββ */
|
| 305 |
+
:root {
|
| 306 |
+
--bg: #0a0a0a;
|
| 307 |
+
--s1: #111111;
|
| 308 |
+
--s2: #161616;
|
| 309 |
+
--border: #1e1e1e;
|
| 310 |
+
--border2: #2a2a2a;
|
| 311 |
+
--accent: #00ff88;
|
| 312 |
+
--red: #ff4444;
|
| 313 |
+
--text: #cccccc;
|
| 314 |
+
--muted: #555555;
|
| 315 |
+
--mono: 'JetBrains Mono', 'Fira Code', monospace;
|
| 316 |
+
--sans: 'Inter', system-ui, sans-serif;
|
| 317 |
+
}
|
| 318 |
+
|
| 319 |
+
/* ββ reset ββ */
|
| 320 |
+
*, *::before, *::after { box-sizing: border-box; }
|
| 321 |
+
|
| 322 |
+
html, body {
|
| 323 |
+
background: var(--bg) !important;
|
| 324 |
+
color: var(--text) !important;
|
| 325 |
+
margin: 0 !important;
|
| 326 |
+
}
|
| 327 |
+
|
| 328 |
+
.gradio-container {
|
| 329 |
+
background: var(--bg) !important;
|
| 330 |
+
font-family: var(--sans) !important;
|
| 331 |
+
max-width: 1280px !important;
|
| 332 |
+
margin: 0 auto !important;
|
| 333 |
+
padding: 0 !important;
|
| 334 |
+
min-height: 100vh !important;
|
| 335 |
+
}
|
| 336 |
+
|
| 337 |
+
/* hide gradio branding */
|
| 338 |
+
footer, .built-with { display: none !important; }
|
| 339 |
+
.share-btn-container { display: none !important; }
|
| 340 |
+
|
| 341 |
+
/* ββ header ββ */
|
| 342 |
+
.hc-header {
|
| 343 |
+
padding: 18px 28px;
|
| 344 |
+
border-bottom: 1px solid var(--border);
|
| 345 |
+
display: flex;
|
| 346 |
+
align-items: baseline;
|
| 347 |
+
gap: 14px;
|
| 348 |
+
}
|
| 349 |
+
.hc-header-name {
|
| 350 |
+
font-family: var(--mono);
|
| 351 |
+
font-size: 13px;
|
| 352 |
+
font-weight: 500;
|
| 353 |
+
color: var(--accent);
|
| 354 |
+
letter-spacing: -0.02em;
|
| 355 |
+
}
|
| 356 |
+
.hc-header-sub {
|
| 357 |
+
font-family: var(--sans);
|
| 358 |
+
font-size: 12px;
|
| 359 |
+
color: var(--muted);
|
| 360 |
+
}
|
| 361 |
+
|
| 362 |
+
/* ββ tabs ββ */
|
| 363 |
+
.tabs > .tab-nav {
|
| 364 |
+
background: transparent !important;
|
| 365 |
+
border-bottom: 1px solid var(--border) !important;
|
| 366 |
+
padding: 0 24px !important;
|
| 367 |
+
gap: 0 !important;
|
| 368 |
+
margin-bottom: 0 !important;
|
| 369 |
+
}
|
| 370 |
+
.tabs > .tab-nav > button {
|
| 371 |
+
background: transparent !important;
|
| 372 |
+
border: none !important;
|
| 373 |
+
border-bottom: 2px solid transparent !important;
|
| 374 |
+
border-radius: 0 !important;
|
| 375 |
+
color: var(--muted) !important;
|
| 376 |
+
font-family: var(--mono) !important;
|
| 377 |
+
font-size: 11px !important;
|
| 378 |
+
font-weight: 400 !important;
|
| 379 |
+
letter-spacing: 0.06em !important;
|
| 380 |
+
padding: 11px 20px !important;
|
| 381 |
+
margin: 0 !important;
|
| 382 |
+
margin-bottom: -1px !important;
|
| 383 |
+
text-transform: lowercase !important;
|
| 384 |
+
transition: color 0.12s !important;
|
| 385 |
+
}
|
| 386 |
+
.tabs > .tab-nav > button:hover { color: var(--text) !important; }
|
| 387 |
+
.tabs > .tab-nav > button.selected {
|
| 388 |
+
color: var(--accent) !important;
|
| 389 |
+
border-bottom-color: var(--accent) !important;
|
| 390 |
+
}
|
| 391 |
+
.tabitem { padding: 0 !important; }
|
| 392 |
+
|
| 393 |
+
/* ββ all panels ββ */
|
| 394 |
+
.block, .panel, .form, .contain, .wrap, .box, .gap {
|
| 395 |
+
background: transparent !important;
|
| 396 |
+
border: none !important;
|
| 397 |
+
box-shadow: none !important;
|
| 398 |
+
border-radius: 0 !important;
|
| 399 |
+
gap: 0 !important;
|
| 400 |
+
}
|
| 401 |
+
|
| 402 |
+
/* ββ inner section padding ββ */
|
| 403 |
+
.gradio-container .row { gap: 0 !important; }
|
| 404 |
+
.gradio-container .col { padding: 0 !important; }
|
| 405 |
+
|
| 406 |
+
/* ββ labels ββ */
|
| 407 |
+
label > span,
|
| 408 |
+
.label-wrap span,
|
| 409 |
+
.block > label > span {
|
| 410 |
+
font-family: var(--mono) !important;
|
| 411 |
+
font-size: 10px !important;
|
| 412 |
+
letter-spacing: 0.12em !important;
|
| 413 |
+
text-transform: uppercase !important;
|
| 414 |
+
color: var(--muted) !important;
|
| 415 |
+
font-weight: 400 !important;
|
| 416 |
+
padding-bottom: 5px !important;
|
| 417 |
+
display: block !important;
|
| 418 |
+
}
|
| 419 |
+
|
| 420 |
+
/* ββ text inputs ββ */
|
| 421 |
+
input[type=text], input[type=number], textarea {
|
| 422 |
+
background: var(--s1) !important;
|
| 423 |
+
border: 1px solid var(--border2) !important;
|
| 424 |
+
border-radius: 0 !important;
|
| 425 |
+
color: var(--text) !important;
|
| 426 |
+
font-family: var(--mono) !important;
|
| 427 |
+
font-size: 12px !important;
|
| 428 |
+
padding: 8px 10px !important;
|
| 429 |
+
transition: border-color 0.1s !important;
|
| 430 |
+
}
|
| 431 |
+
input[type=text]:focus, textarea:focus {
|
| 432 |
+
border-color: var(--accent) !important;
|
| 433 |
+
outline: none !important;
|
| 434 |
+
box-shadow: none !important;
|
| 435 |
+
}
|
| 436 |
+
|
| 437 |
+
/* ββ sliders ββ */
|
| 438 |
+
input[type=range] { accent-color: var(--accent) !important; cursor: pointer !important; }
|
| 439 |
+
.wrap .numeral, .wrap .number, input[type=number] {
|
| 440 |
+
font-family: var(--mono) !important;
|
| 441 |
+
font-size: 12px !important;
|
| 442 |
+
color: var(--text) !important;
|
| 443 |
+
}
|
| 444 |
+
|
| 445 |
+
/* ββ checkbox / radio ββ */
|
| 446 |
+
input[type=checkbox], input[type=radio] {
|
| 447 |
+
accent-color: var(--accent) !important;
|
| 448 |
+
cursor: pointer !important;
|
| 449 |
+
}
|
| 450 |
+
|
| 451 |
+
/* ββ select / dropdown ββ */
|
| 452 |
+
select, .dropdown {
|
| 453 |
+
background: var(--s1) !important;
|
| 454 |
+
border: 1px solid var(--border2) !important;
|
| 455 |
+
border-radius: 0 !important;
|
| 456 |
+
color: var(--text) !important;
|
| 457 |
+
font-family: var(--mono) !important;
|
| 458 |
+
font-size: 12px !important;
|
| 459 |
+
}
|
| 460 |
+
.options-wrap {
|
| 461 |
+
background: var(--s1) !important;
|
| 462 |
+
border: 1px solid var(--border2) !important;
|
| 463 |
+
border-radius: 0 !important;
|
| 464 |
+
}
|
| 465 |
+
.item { color: var(--text) !important; }
|
| 466 |
+
.item:hover, .item.selected {
|
| 467 |
+
background: var(--s2) !important;
|
| 468 |
+
color: var(--accent) !important;
|
| 469 |
+
}
|
| 470 |
+
|
| 471 |
+
/* ββ file upload ββ */
|
| 472 |
+
.upload-container, .file-upload, .dnd-container,
|
| 473 |
+
.file-preview-holder, .wrap .wrap {
|
| 474 |
+
background: var(--s1) !important;
|
| 475 |
+
border: 1px dashed var(--border2) !important;
|
| 476 |
+
border-radius: 0 !important;
|
| 477 |
+
color: var(--muted) !important;
|
| 478 |
+
font-family: var(--mono) !important;
|
| 479 |
+
font-size: 11px !important;
|
| 480 |
+
transition: border-color 0.12s !important;
|
| 481 |
+
}
|
| 482 |
+
.upload-container:hover { border-color: var(--accent) !important; }
|
| 483 |
+
.file-name, .file-name span { color: var(--accent) !important; font-family: var(--mono) !important; }
|
| 484 |
+
|
| 485 |
+
/* ββ primary button ββ */
|
| 486 |
+
button.primary {
|
| 487 |
+
background: transparent !important;
|
| 488 |
+
border: 2px solid var(--accent) !important;
|
| 489 |
+
border-radius: 0 !important;
|
| 490 |
+
color: var(--accent) !important;
|
| 491 |
+
font-family: var(--mono) !important;
|
| 492 |
+
font-size: 11px !important;
|
| 493 |
+
font-weight: 500 !important;
|
| 494 |
+
letter-spacing: 0.12em !important;
|
| 495 |
+
padding: 11px 0 !important;
|
| 496 |
+
width: 100% !important;
|
| 497 |
+
text-transform: lowercase !important;
|
| 498 |
+
transition: background 0.1s !important;
|
| 499 |
+
cursor: pointer !important;
|
| 500 |
+
margin-top: 4px !important;
|
| 501 |
+
}
|
| 502 |
+
button.primary:hover { background: rgba(0,255,136,0.06) !important; }
|
| 503 |
+
button.primary:active { background: rgba(0,255,136,0.14) !important; }
|
| 504 |
+
|
| 505 |
+
/* secondary (download, clear, etc.) */
|
| 506 |
+
button.secondary {
|
| 507 |
+
background: transparent !important;
|
| 508 |
+
border: 1px solid var(--border2) !important;
|
| 509 |
+
border-radius: 0 !important;
|
| 510 |
+
color: var(--muted) !important;
|
| 511 |
+
font-family: var(--mono) !important;
|
| 512 |
+
font-size: 10px !important;
|
| 513 |
+
letter-spacing: 0.06em !important;
|
| 514 |
+
text-transform: lowercase !important;
|
| 515 |
+
}
|
| 516 |
+
button.secondary:hover { border-color: var(--border2) !important; color: var(--text) !important; }
|
| 517 |
+
|
| 518 |
+
/* icon-only buttons */
|
| 519 |
+
button.icon { color: var(--muted) !important; background: transparent !important; }
|
| 520 |
+
|
| 521 |
+
/* ββ textbox output ββ */
|
| 522 |
+
.output-text-area textarea,
|
| 523 |
+
textarea.scroll-hide,
|
| 524 |
+
.block textarea {
|
| 525 |
+
background: var(--s1) !important;
|
| 526 |
+
border: 1px solid var(--border) !important;
|
| 527 |
+
border-radius: 0 !important;
|
| 528 |
+
color: var(--text) !important;
|
| 529 |
+
font-family: var(--mono) !important;
|
| 530 |
+
font-size: 11.5px !important;
|
| 531 |
+
line-height: 1.75 !important;
|
| 532 |
+
padding: 12px !important;
|
| 533 |
+
}
|
| 534 |
+
|
| 535 |
+
/* ββ dataframe / table ββ */
|
| 536 |
+
table { border-collapse: collapse !important; width: 100% !important; }
|
| 537 |
+
thead th {
|
| 538 |
+
background: var(--s2) !important;
|
| 539 |
+
border: 1px solid var(--border) !important;
|
| 540 |
+
color: var(--muted) !important;
|
| 541 |
+
font-family: var(--mono) !important;
|
| 542 |
+
font-size: 9.5px !important;
|
| 543 |
+
letter-spacing: 0.12em !important;
|
| 544 |
+
padding: 7px 12px !important;
|
| 545 |
+
text-transform: uppercase !important;
|
| 546 |
+
font-weight: 400 !important;
|
| 547 |
+
}
|
| 548 |
+
tbody td {
|
| 549 |
+
background: var(--s1) !important;
|
| 550 |
+
border: 1px solid var(--border) !important;
|
| 551 |
+
color: var(--text) !important;
|
| 552 |
+
font-family: var(--mono) !important;
|
| 553 |
+
font-size: 11px !important;
|
| 554 |
+
padding: 5px 12px !important;
|
| 555 |
+
}
|
| 556 |
+
tbody tr:hover td { background: var(--s2) !important; }
|
| 557 |
+
|
| 558 |
+
/* ββ plot wrapper ββ */
|
| 559 |
+
.plot-container, .matplotlib-plot, .plot-container > div {
|
| 560 |
+
background: var(--s1) !important;
|
| 561 |
+
border-radius: 0 !important;
|
| 562 |
+
border: 1px solid var(--border) !important;
|
| 563 |
+
}
|
| 564 |
+
|
| 565 |
+
/* ββ markdown ββ */
|
| 566 |
+
.prose, .markdown {
|
| 567 |
+
color: var(--text) !important;
|
| 568 |
+
font-family: var(--sans) !important;
|
| 569 |
+
font-size: 13px !important;
|
| 570 |
+
}
|
| 571 |
+
.prose code, .markdown code {
|
| 572 |
+
background: var(--s2) !important;
|
| 573 |
+
color: var(--accent) !important;
|
| 574 |
+
font-family: var(--mono) !important;
|
| 575 |
+
border-radius: 0 !important;
|
| 576 |
+
padding: 1px 5px !important;
|
| 577 |
+
font-size: 11px !important;
|
| 578 |
+
}
|
| 579 |
+
.prose a, .markdown a { color: var(--accent) !important; text-decoration: none !important; }
|
| 580 |
+
.prose a:hover { text-decoration: underline !important; }
|
| 581 |
+
|
| 582 |
+
/* ββ custom note ββ */
|
| 583 |
+
.hc-note {
|
| 584 |
+
font-family: var(--mono);
|
| 585 |
+
font-size: 11px;
|
| 586 |
+
color: var(--muted);
|
| 587 |
+
padding: 10px 0 16px;
|
| 588 |
+
line-height: 1.5;
|
| 589 |
+
}
|
| 590 |
+
|
| 591 |
+
/* ββ section padding wrapper ββ */
|
| 592 |
+
.hc-col-inputs { padding: 24px 20px 24px 28px !important; border-right: 1px solid var(--border); }
|
| 593 |
+
.hc-col-outputs { padding: 24px 28px 24px 20px !important; }
|
| 594 |
+
|
| 595 |
+
/* ββ footer ββ */
|
| 596 |
+
.hc-footer {
|
| 597 |
+
padding: 14px 28px;
|
| 598 |
+
border-top: 1px solid var(--border);
|
| 599 |
+
font-family: var(--mono);
|
| 600 |
+
font-size: 10.5px;
|
| 601 |
+
color: var(--muted);
|
| 602 |
+
display: flex;
|
| 603 |
+
gap: 0;
|
| 604 |
+
align-items: center;
|
| 605 |
+
line-height: 1;
|
| 606 |
+
}
|
| 607 |
+
.hc-footer a { color: var(--muted); text-decoration: none; }
|
| 608 |
+
.hc-footer a:hover { color: var(--accent); }
|
| 609 |
+
.hc-footer .sep { color: var(--border2); margin: 0 10px; }
|
| 610 |
+
|
| 611 |
+
/* ββ scrollbar ββ */
|
| 612 |
+
::-webkit-scrollbar { width: 5px; height: 5px; }
|
| 613 |
+
::-webkit-scrollbar-track { background: var(--bg); }
|
| 614 |
+
::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 0; }
|
| 615 |
+
::-webkit-scrollbar-thumb:hover { background: #333; }
|
| 616 |
+
|
| 617 |
+
/* ββ input row spacing ββ */
|
| 618 |
+
.input-stack > * + * { margin-top: 16px !important; }
|
| 619 |
+
|
| 620 |
+
/* ββ no blue focus rings ββ */
|
| 621 |
+
*:focus { outline: none !important; box-shadow: none !important; }
|
| 622 |
+
*:focus-visible { outline: 1px solid var(--accent) !important; }
|
| 623 |
+
"""
|
| 624 |
|
| 625 |
+
HEADER_HTML = """
|
| 626 |
+
<div class="hc-header">
|
| 627 |
+
<span class="hc-header-name">haptal-curate</span>
|
| 628 |
+
<span class="hc-header-sub">demonstration quality scoring + curation</span>
|
| 629 |
+
</div>
|
| 630 |
+
"""
|
| 631 |
|
| 632 |
+
FOOTER_HTML = """
|
| 633 |
+
<div class="hc-footer">
|
| 634 |
+
haptal-curate
|
| 635 |
+
<span class="sep">|</span>
|
| 636 |
+
<a href="https://arxiv.org/abs/2606.03134" target="_blank">arxiv:2606.03134</a>
|
| 637 |
+
<span class="sep"> </span>
|
| 638 |
+
<a href="https://arxiv.org/abs/2606.05588" target="_blank">arxiv:2606.05588</a>
|
| 639 |
+
<span class="sep"> </span>
|
| 640 |
+
<a href="https://arxiv.org/abs/2606.10229" target="_blank">arxiv:2606.10229</a>
|
| 641 |
+
<span class="sep">|</span>
|
| 642 |
+
<a href="https://github.com/aaravbedi/haptal-curate" target="_blank">github</a>
|
| 643 |
+
</div>
|
| 644 |
+
"""
|
| 645 |
|
| 646 |
+
NOTE_SYNTHETIC = """
|
| 647 |
+
<div class="hc-note">
|
| 648 |
+
// no robot data needed β generates synthetic demos on the fly
|
| 649 |
+
</div>
|
| 650 |
"""
|
| 651 |
|
| 652 |
+
# ββ UI ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 653 |
with gr.Blocks(title="haptal-curate") as demo:
|
| 654 |
+
|
| 655 |
+
gr.HTML(HEADER_HTML)
|
| 656 |
|
| 657 |
with gr.Tabs():
|
| 658 |
|
| 659 |
+
# ββ tab 1: score & curate βββββββββββββββββββββββββββββββββββββββββ
|
| 660 |
+
with gr.Tab("score & curate"):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 661 |
with gr.Row():
|
| 662 |
+
|
| 663 |
+
# left: inputs
|
| 664 |
+
with gr.Column(scale=4, elem_classes=["hc-col-inputs"]):
|
| 665 |
+
with gr.Column(elem_classes=["input-stack"]):
|
| 666 |
+
t1_file = gr.File(
|
| 667 |
+
label="hdf5 file",
|
| 668 |
+
file_types=[".hdf5", ".h5"],
|
| 669 |
+
)
|
| 670 |
+
t1_metric = gr.Dropdown(
|
| 671 |
+
choices=METRIC_CHOICES,
|
| 672 |
+
value="ensemble",
|
| 673 |
+
label="metric",
|
| 674 |
+
)
|
| 675 |
+
t1_phase = gr.Checkbox(
|
| 676 |
+
label="phase-gated scoring",
|
| 677 |
+
value=False,
|
| 678 |
+
)
|
| 679 |
+
t1_trunc = gr.Slider(
|
| 680 |
+
minimum=50, maximum=500, value=324, step=1,
|
| 681 |
+
label="truncate t",
|
| 682 |
+
)
|
| 683 |
+
t1_frac = gr.Slider(
|
| 684 |
+
minimum=0.05, maximum=1.0, value=0.8, step=0.05,
|
| 685 |
+
label="keep fraction",
|
| 686 |
+
)
|
| 687 |
+
t1_btn = gr.Button("run", variant="primary")
|
| 688 |
+
|
| 689 |
+
# right: outputs
|
| 690 |
+
with gr.Column(scale=6, elem_classes=["hc-col-outputs"]):
|
| 691 |
+
t1_plot = gr.Plot(label="score distribution", show_label=False)
|
| 692 |
+
t1_summary = gr.Textbox(label="stats", lines=9, interactive=False)
|
| 693 |
+
t1_table = gr.Dataframe(
|
| 694 |
+
headers=["rank", "demo id", "score", "decision"],
|
| 695 |
+
label="scores",
|
| 696 |
+
wrap=False,
|
| 697 |
+
row_count=(10, "dynamic"),
|
| 698 |
)
|
| 699 |
+
t1_dl = gr.File(label="download curation json", visible=True)
|
| 700 |
|
| 701 |
t1_btn.click(
|
| 702 |
fn=run_score_curate,
|
| 703 |
+
inputs=[t1_file, t1_metric, t1_phase, t1_trunc, t1_frac],
|
| 704 |
+
outputs=[t1_summary, t1_table, t1_plot, t1_dl],
|
| 705 |
)
|
| 706 |
|
| 707 |
+
# ββ tab 2: synthetic ββββββββββββββββββββββββββββββββββββββββββββββ
|
| 708 |
+
with gr.Tab("synthetic"):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 709 |
with gr.Row():
|
| 710 |
+
|
| 711 |
+
# left: inputs
|
| 712 |
+
with gr.Column(scale=4, elem_classes=["hc-col-inputs"]):
|
| 713 |
+
with gr.Column(elem_classes=["input-stack"]):
|
| 714 |
+
gr.HTML(NOTE_SYNTHETIC)
|
| 715 |
+
t2_clean = gr.Slider(
|
| 716 |
+
minimum=5, maximum=120, value=40, step=1,
|
| 717 |
+
label="clean demos",
|
| 718 |
+
)
|
| 719 |
+
t2_defective = gr.Slider(
|
| 720 |
+
minimum=1, maximum=40, value=7, step=1,
|
| 721 |
+
label="defective demos",
|
| 722 |
+
)
|
| 723 |
+
t2_metric = gr.Dropdown(
|
| 724 |
+
choices=METRIC_CHOICES,
|
| 725 |
+
value="ensemble",
|
| 726 |
+
label="metric",
|
| 727 |
+
)
|
| 728 |
+
t2_frac = gr.Slider(
|
| 729 |
+
minimum=0.05, maximum=1.0, value=0.85, step=0.05,
|
| 730 |
+
label="keep fraction",
|
| 731 |
+
)
|
| 732 |
+
t2_confound = gr.Checkbox(
|
| 733 |
+
label="compare without truncation",
|
| 734 |
+
value=True,
|
| 735 |
+
)
|
| 736 |
+
t2_btn = gr.Button("run", variant="primary")
|
| 737 |
+
|
| 738 |
+
# right: outputs
|
| 739 |
+
with gr.Column(scale=6, elem_classes=["hc-col-outputs"]):
|
| 740 |
+
t2_plot = gr.Plot(label="score distribution", show_label=False)
|
| 741 |
+
t2_summary = gr.Textbox(label="stats", lines=9, interactive=False)
|
| 742 |
+
t2_table = gr.Dataframe(
|
| 743 |
+
headers=["rank", "demo id", "score", "decision", "ground truth"],
|
| 744 |
+
label="scores",
|
| 745 |
+
wrap=False,
|
| 746 |
+
row_count=(10, "dynamic"),
|
| 747 |
)
|
| 748 |
|
| 749 |
t2_btn.click(
|
| 750 |
fn=run_synthetic,
|
| 751 |
+
inputs=[t2_clean, t2_defective, t2_metric, t2_frac, t2_confound],
|
| 752 |
outputs=[t2_summary, t2_table, t2_plot],
|
| 753 |
)
|
| 754 |
|
| 755 |
+
gr.HTML(FOOTER_HTML)
|
| 756 |
|
| 757 |
if __name__ == "__main__":
|
| 758 |
+
demo.launch(theme=gr.themes.Base(), css=CSS)
|