Mike0021 commited on
Commit
687af5a
·
verified ·
1 Parent(s): 928d899

Autosave benchmark evidence rows per deployed build

Browse files
Files changed (2) hide show
  1. README.md +1 -1
  2. app.js +74 -3
README.md CHANGED
@@ -104,7 +104,7 @@ Candidate comparisons to run:
104
 
105
  For model comparisons, choose the candidate model before **Load models**, run **Run benchmark suite**, add at least three real microphone rows with **Run 3 real-mic series**, then click **Unload models** and choose the next candidate. The benchmark table is preserved across unloads, so **Copy JSON** can export the summary and all rows after the comparison set. For TTS voice/step comparisons, change the voice or step slider after loading and rerun **Run TTS benchmark** plus the text/loopback benchmarks; those values are captured per row.
106
 
107
- Use **Download JSON** after benchmark or real-mic runs on the hosted Space to save a timestamped evidence file with the same payload as **Copy JSON** and `window.browserSpeakBench.exportResults()`. The export includes `generatedAt`, `hostMetadata` with the hosted Space commit when the static host exposes it, the current `runtime`, an `evidence` summary for real-mic/hardware-WebGPU/hosted-build readiness, aggregate `summary`, and raw `results`.
108
 
109
  Use `node tools/audit-browser-evidence.mjs path/to/browser-speak-benchmarks.json` to audit a JSON file downloaded from the hosted browser UI. This checks that the export came from the static Space revision, reports the page-generated `evidence` summary, verifies that at least three real-mic rows meet the WER/identity/latency gates from raw rows, and verifies that at least one completed row reports hardware WebGPU rather than a software adapter. Browser-downloaded JSON cannot prove no-server network behavior or Chrome launch flags by itself, so pair it with `node tools/run-hosted-smoke.mjs` for network evidence or `node tools/run-real-mic-series.mjs` for harness-collected real-mic provenance.
110
 
 
104
 
105
  For model comparisons, choose the candidate model before **Load models**, run **Run benchmark suite**, add at least three real microphone rows with **Run 3 real-mic series**, then click **Unload models** and choose the next candidate. The benchmark table is preserved across unloads, so **Copy JSON** can export the summary and all rows after the comparison set. For TTS voice/step comparisons, change the voice or step slider after loading and rerun **Run TTS benchmark** plus the text/loopback benchmarks; those values are captured per row.
106
 
107
+ Use **Download JSON** after benchmark or real-mic runs on the hosted Space to save a timestamped evidence file with the same payload as **Copy JSON** and `window.browserSpeakBench.exportResults()`. The export includes `generatedAt`, `hostMetadata` with the hosted Space commit when the static host exposes it, the current `runtime`, an `evidence` summary for real-mic/hardware-WebGPU/hosted-build readiness, aggregate `summary`, and raw `results`. Benchmark rows are also autosaved in browser storage for the current host and Space commit, so a reload during manual evidence capture can restore rows from the same deployed build; **Clear** removes both the visible rows and the saved copy.
108
 
109
  Use `node tools/audit-browser-evidence.mjs path/to/browser-speak-benchmarks.json` to audit a JSON file downloaded from the hosted browser UI. This checks that the export came from the static Space revision, reports the page-generated `evidence` summary, verifies that at least three real-mic rows meet the WER/identity/latency gates from raw rows, and verifies that at least one completed row reports hardware WebGPU rather than a software adapter. Browser-downloaded JSON cannot prove no-server network behavior or Chrome launch flags by itself, so pair it with `node tools/run-hosted-smoke.mjs` for network evidence or `node tools/run-real-mic-series.mjs` for harness-collected real-mic provenance.
110
 
app.js CHANGED
@@ -133,6 +133,9 @@ const DEFAULT_LOOPBACK_PREROLL_MS = 180;
133
  const DEFAULT_LOOPBACK_PROMPT = "Identify this browser demo.";
134
  const REAL_MIC_TARGET_RUNS = 3;
135
  const REAL_MIC_MAX_WER = 0.25;
 
 
 
136
  const HARDWARE_WEBGPU_EVIDENCE_STACK = Object.freeze({
137
  device: "webgpu",
138
  llm: "HuggingFaceTB/SmolLM2-135M-Instruct",
@@ -221,6 +224,7 @@ const state = {
221
  ttsChunking: { ...DEFAULT_TTS_CHUNKING },
222
  benchmarkResults: [],
223
  };
 
224
 
225
  class PlaybackQueue {
226
  constructor() {
@@ -450,6 +454,7 @@ function updateBuildStatus() {
450
  const commit = state.hostMetadata.hfSpaceCommit;
451
  const label = commit ? `Space build ${commit.slice(0, 8)}` : `${location.hostname || "local"} build`;
452
  elements.runtimeBuildStatus.textContent = label;
 
453
  }
454
 
455
  function setLoadButton(mode) {
@@ -1597,6 +1602,7 @@ function failActiveBenchmark(message) {
1597
  }
1598
  const result = { ...state.activeBenchmark };
1599
  state.benchmarkResults.unshift(result);
 
1600
  state.activeBenchmark = null;
1601
  renderBenchmarkResults();
1602
  logEvent(message);
@@ -1609,6 +1615,7 @@ function completeActiveBenchmark() {
1609
  clearBenchmarkTimeout();
1610
  const result = { ...state.activeBenchmark };
1611
  state.benchmarkResults.unshift(result);
 
1612
  state.activeBenchmark = null;
1613
  renderBenchmarkResults();
1614
  handleBenchmarkRowAdded(result);
@@ -1716,6 +1723,59 @@ function renderBenchmarkResults() {
1716
  }
1717
  }
1718
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1719
  function renderBenchmarkSummary() {
1720
  const summary = displayBenchmarkSummary();
1721
  const evidence = evidenceSummaryForRows(state.benchmarkResults);
@@ -2874,6 +2934,7 @@ function installAutomationApi() {
2874
  return automationSnapshot();
2875
  },
2876
  async loadStack(options = {}) {
 
2877
  applyAutomationStack(options);
2878
  await loadModels({ ttsWarmup: options.ttsWarmup !== false });
2879
  if (!state.modelsLoaded) throw new Error("Model load did not complete.");
@@ -2913,6 +2974,7 @@ function installAutomationApi() {
2913
  clearBenchmarkTimeout();
2914
  state.benchmarkResults = [];
2915
  state.activeBenchmark = null;
 
2916
  renderBenchmarkResults();
2917
  return automationSnapshot();
2918
  },
@@ -2928,7 +2990,10 @@ function installAutomationApi() {
2928
  }
2929
 
2930
  elements.loadButton.addEventListener("click", () => {
2931
- const action = state.modelsLoaded ? unloadModels() : loadModels();
 
 
 
2932
  action.catch((error) => logEvent(`Model control failed: ${error.message}`));
2933
  });
2934
  elements.micButton.addEventListener("click", () => {
@@ -2965,6 +3030,7 @@ elements.clearResultsButton.addEventListener("click", () => {
2965
  clearBenchmarkTimeout();
2966
  state.benchmarkResults = [];
2967
  state.activeBenchmark = null;
 
2968
  renderBenchmarkResults();
2969
  });
2970
  elements.clearLogButton.addEventListener("click", () => {
@@ -2993,8 +3059,13 @@ updateTtsStepsLabel();
2993
  updateVadSilenceLabel();
2994
  updateMicValidationStatus();
2995
  installAutomationApi();
2996
- refreshHostMetadata().catch(() => {});
2997
- initRuntimeSupport();
 
 
 
 
 
2998
 
2999
  async function initRuntimeSupport() {
3000
  if (!window.isSecureContext) {
 
133
  const DEFAULT_LOOPBACK_PROMPT = "Identify this browser demo.";
134
  const REAL_MIC_TARGET_RUNS = 3;
135
  const REAL_MIC_MAX_WER = 0.25;
136
+ const BENCHMARK_STORAGE_KEY = "browser-speak:benchmark-results:v1";
137
+ const BENCHMARK_STORAGE_VERSION = 1;
138
+ const BENCHMARK_STORAGE_MAX_ROWS = 80;
139
  const HARDWARE_WEBGPU_EVIDENCE_STACK = Object.freeze({
140
  device: "webgpu",
141
  llm: "HuggingFaceTB/SmolLM2-135M-Instruct",
 
224
  ttsChunking: { ...DEFAULT_TTS_CHUNKING },
225
  benchmarkResults: [],
226
  };
227
+ let pageInitPromise = null;
228
 
229
  class PlaybackQueue {
230
  constructor() {
 
454
  const commit = state.hostMetadata.hfSpaceCommit;
455
  const label = commit ? `Space build ${commit.slice(0, 8)}` : `${location.hostname || "local"} build`;
456
  elements.runtimeBuildStatus.textContent = label;
457
+ if (state.benchmarkResults.length > 0) renderBenchmarkSummary();
458
  }
459
 
460
  function setLoadButton(mode) {
 
1602
  }
1603
  const result = { ...state.activeBenchmark };
1604
  state.benchmarkResults.unshift(result);
1605
+ persistBenchmarkResults();
1606
  state.activeBenchmark = null;
1607
  renderBenchmarkResults();
1608
  logEvent(message);
 
1615
  clearBenchmarkTimeout();
1616
  const result = { ...state.activeBenchmark };
1617
  state.benchmarkResults.unshift(result);
1618
+ persistBenchmarkResults();
1619
  state.activeBenchmark = null;
1620
  renderBenchmarkResults();
1621
  handleBenchmarkRowAdded(result);
 
1723
  }
1724
  }
1725
 
1726
+ function benchmarkStorageScope() {
1727
+ const commit = state.hostMetadata.hfSpaceCommit || "local";
1728
+ return `${location.origin}${location.pathname}#${commit}`;
1729
+ }
1730
+
1731
+ function persistBenchmarkResults() {
1732
+ if (state.benchmarkResults.length === 0) {
1733
+ clearPersistedBenchmarkResults();
1734
+ return;
1735
+ }
1736
+ try {
1737
+ const payload = {
1738
+ version: BENCHMARK_STORAGE_VERSION,
1739
+ scope: benchmarkStorageScope(),
1740
+ savedAt: new Date().toISOString(),
1741
+ hostMetadata: { ...state.hostMetadata },
1742
+ results: state.benchmarkResults.slice(0, BENCHMARK_STORAGE_MAX_ROWS),
1743
+ };
1744
+ localStorage.setItem(BENCHMARK_STORAGE_KEY, JSON.stringify(payload));
1745
+ } catch {
1746
+ // Storage can be disabled or full; benchmark export still works in memory.
1747
+ }
1748
+ }
1749
+
1750
+ function restoreBenchmarkResults() {
1751
+ let payload = null;
1752
+ try {
1753
+ payload = JSON.parse(localStorage.getItem(BENCHMARK_STORAGE_KEY) || "null");
1754
+ } catch {
1755
+ return;
1756
+ }
1757
+ if (!payload || payload.version !== BENCHMARK_STORAGE_VERSION) return;
1758
+ if (payload.scope !== benchmarkStorageScope()) {
1759
+ logEvent("Saved benchmark rows belong to a different build and were not restored.");
1760
+ return;
1761
+ }
1762
+ const rows = Array.isArray(payload.results)
1763
+ ? payload.results.filter((result) => result && typeof result === "object").slice(0, BENCHMARK_STORAGE_MAX_ROWS)
1764
+ : [];
1765
+ if (rows.length === 0) return;
1766
+ state.benchmarkResults = rows;
1767
+ renderBenchmarkResults();
1768
+ logEvent(`Restored ${rows.length} saved benchmark row${rows.length === 1 ? "" : "s"}.`);
1769
+ }
1770
+
1771
+ function clearPersistedBenchmarkResults() {
1772
+ try {
1773
+ localStorage.removeItem(BENCHMARK_STORAGE_KEY);
1774
+ } catch {
1775
+ // Ignore storage failures; in-memory rows are already cleared.
1776
+ }
1777
+ }
1778
+
1779
  function renderBenchmarkSummary() {
1780
  const summary = displayBenchmarkSummary();
1781
  const evidence = evidenceSummaryForRows(state.benchmarkResults);
 
2934
  return automationSnapshot();
2935
  },
2936
  async loadStack(options = {}) {
2937
+ await pageInitPromise;
2938
  applyAutomationStack(options);
2939
  await loadModels({ ttsWarmup: options.ttsWarmup !== false });
2940
  if (!state.modelsLoaded) throw new Error("Model load did not complete.");
 
2974
  clearBenchmarkTimeout();
2975
  state.benchmarkResults = [];
2976
  state.activeBenchmark = null;
2977
+ clearPersistedBenchmarkResults();
2978
  renderBenchmarkResults();
2979
  return automationSnapshot();
2980
  },
 
2990
  }
2991
 
2992
  elements.loadButton.addEventListener("click", () => {
2993
+ const action = (async () => {
2994
+ await pageInitPromise;
2995
+ return state.modelsLoaded ? unloadModels() : loadModels();
2996
+ })();
2997
  action.catch((error) => logEvent(`Model control failed: ${error.message}`));
2998
  });
2999
  elements.micButton.addEventListener("click", () => {
 
3030
  clearBenchmarkTimeout();
3031
  state.benchmarkResults = [];
3032
  state.activeBenchmark = null;
3033
+ clearPersistedBenchmarkResults();
3034
  renderBenchmarkResults();
3035
  });
3036
  elements.clearLogButton.addEventListener("click", () => {
 
3059
  updateVadSilenceLabel();
3060
  updateMicValidationStatus();
3061
  installAutomationApi();
3062
+ pageInitPromise = initPage();
3063
+
3064
+ async function initPage() {
3065
+ await refreshHostMetadata().catch(() => {});
3066
+ restoreBenchmarkResults();
3067
+ await initRuntimeSupport();
3068
+ }
3069
 
3070
  async function initRuntimeSupport() {
3071
  if (!window.isSecureContext) {