HanningChen commited on
Commit
02bed5c
·
1 Parent(s): 8cd1ab1
Files changed (2) hide show
  1. webui/app.py +5 -0
  2. webui/static/main.js +80 -29
webui/app.py CHANGED
@@ -206,6 +206,7 @@ async def api_run(
206
  noise_type: str = Form("none"),
207
  noise_strength: int = Form(0),
208
  upload: UploadFile = File(...),
 
209
  ):
210
  # validate + pick decoder
211
  if score_function not in SCORE_FUNCS:
@@ -252,6 +253,10 @@ async def api_run(
252
  hdv_dim=int(hdv_dim),
253
  taskclip_ckpt=taskclip_ckpt,
254
  viz_mode=viz_mode,
 
 
 
 
255
  )
256
  except Exception as e:
257
  tb = traceback.format_exc()
 
206
  noise_type: str = Form("none"),
207
  noise_strength: int = Form(0),
208
  upload: UploadFile = File(...),
209
+ hdc_bits: int = Form(32),
210
  ):
211
  # validate + pick decoder
212
  if score_function not in SCORE_FUNCS:
 
253
  hdv_dim=int(hdv_dim),
254
  taskclip_ckpt=taskclip_ckpt,
255
  viz_mode=viz_mode,
256
+ hw_noise_dist=hw_noise_dist,
257
+ hw_noise_width=int(hw_noise_width),
258
+ hw_noise_strength=int(hw_noise_strength),
259
+ hdc_bits=hdc_bits
260
  )
261
  except Exception as e:
262
  tb = traceback.format_exc()
webui/static/main.js CHANGED
@@ -46,16 +46,17 @@
46
  const noiseValLinear = $("noiseValLinear");
47
  const noiseValAdv = $("noiseValAdv");
48
 
49
- // HW noise elements (UI only; backend currently doesn't accept them unless you add to api_run)
50
  const hwNoiseWidth = $("hwNoiseWidth");
51
  const hwNoiseStrength = $("hwNoiseStrength");
52
  const hwNoiseWidthVal = $("hwNoiseWidthVal");
53
  const hwNoiseStrengthVal = $("hwNoiseStrengthVal");
54
 
55
  function setStatus(kind, text, logLine) {
 
56
  if (statusDot) statusDot.className = `dot ${kind}`;
57
  if (statusText) statusText.textContent = text;
58
- if (statusLog && logLine) statusLog.textContent = logLine;
59
  }
60
 
61
  function setRunning(isRunning) {
@@ -87,7 +88,7 @@
87
  fileInput.files = dt.files;
88
  }
89
 
90
- // Tabs
91
  function initTabs() {
92
  const tabBtns = qsa(".tabBtn");
93
  const tabPanels = qsa(".tabPanel");
@@ -105,7 +106,29 @@
105
  });
106
  }
107
 
108
- // Noise panel switching
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109
  function noiseFamily(val) {
110
  const t = String(val || "none").toLowerCase();
111
  if (t === "none" || t === "default" || t === "off") return "none";
@@ -145,34 +168,50 @@
145
 
146
  function initNoise() {
147
  if (!noiseType) return;
 
148
  noiseType.addEventListener("change", showNoisePanel);
149
 
150
- if (noiseGaussian) noiseGaussian.addEventListener("input", () => {
151
- if (noiseValGaussian) noiseValGaussian.textContent = noiseGaussian.value;
152
- updateNoiseHidden();
153
- });
154
- if (noiseLinear) noiseLinear.addEventListener("input", () => {
155
- if (noiseValLinear) noiseValLinear.textContent = noiseLinear.value;
156
- updateNoiseHidden();
157
- });
158
- if (noiseAdv) noiseAdv.addEventListener("input", () => {
159
- if (noiseValAdv) noiseValAdv.textContent = noiseAdv.value;
160
- updateNoiseHidden();
161
- });
 
 
 
 
 
 
 
 
162
 
163
  showNoisePanel();
164
  }
165
 
 
166
  function initHwNoiseLabels() {
167
  if (hwNoiseWidth && hwNoiseWidthVal) {
168
- hwNoiseWidth.addEventListener("input", () => (hwNoiseWidthVal.textContent = hwNoiseWidth.value));
 
 
 
169
  }
170
  if (hwNoiseStrength && hwNoiseStrengthVal) {
171
- hwNoiseStrength.addEventListener("input", () => (hwNoiseStrengthVal.textContent = hwNoiseStrength.value));
 
 
 
172
  }
173
  }
174
 
175
- // Upload handlers
176
  function initUpload() {
177
  if (!fileInput || !dropzone) return;
178
 
@@ -193,7 +232,10 @@
193
  e.preventDefault();
194
  dropzone.classList.add("drag");
195
  });
196
- dropzone.addEventListener("dragleave", () => dropzone.classList.remove("drag"));
 
 
 
197
 
198
  dropzone.addEventListener("drop", (e) => {
199
  e.preventDefault();
@@ -205,25 +247,34 @@
205
  });
206
  }
207
 
208
- // Reset
209
  function initReset() {
210
  if (!resetBtn || !form) return;
211
  resetBtn.addEventListener("click", () => {
212
  form.reset();
213
  if (fileInput) fileInput.value = "";
214
  setPreview(null);
 
215
  if (jobPill) jobPill.textContent = "job: —";
216
  if (imgInput) imgInput.removeAttribute("src");
217
  if (imgYolo) imgYolo.removeAttribute("src");
218
  if (imgSelected) imgSelected.removeAttribute("src");
219
  if (meta) meta.textContent = "";
 
 
 
 
 
 
 
 
 
220
  setStatus("idle", "Idle", "Waiting for input…");
221
  setRunning(false);
222
- showNoisePanel();
223
  });
224
  }
225
 
226
- // Copy metadata
227
  function initCopyMeta() {
228
  if (!copyMetaBtn || !meta) return;
229
  copyMetaBtn.addEventListener("click", async () => {
@@ -234,7 +285,7 @@
234
  });
235
  }
236
 
237
- // Submit
238
  function initSubmit() {
239
  if (!form) return;
240
 
@@ -247,14 +298,12 @@
247
  return;
248
  }
249
 
250
- updateNoiseHidden(); // ensure hidden noise_strength matches slider
251
  setRunning(true);
252
  setStatus("run", "Running", "Submitting request…");
253
 
254
  try {
255
  const fd = new FormData(form);
256
-
257
- // NOTE: backend currently ignores HW noise + hdc_bits unless you add them to api_run.
258
  const resp = await fetch("/api/run", { method: "POST", body: fd });
259
  const data = await resp.json();
260
 
@@ -295,19 +344,21 @@
295
 
296
  // Boot
297
  document.addEventListener("DOMContentLoaded", () => {
298
- // Basic sanity: show you in logs if ids are missing
299
  if (!form || !fileInput || !dropzone) {
300
- console.error("DOM ids mismatch: runForm/fileInput/dropzone not found.");
301
  if (statusLog) statusLog.textContent = "JS init failed: missing DOM elements (check ids).";
302
  return;
303
  }
 
304
  initTabs();
 
305
  initNoise();
306
  initHwNoiseLabels();
307
  initUpload();
308
  initReset();
309
  initCopyMeta();
310
  initSubmit();
 
311
  setStatus("idle", "Idle", "Waiting for input…");
312
  });
313
  })();
 
46
  const noiseValLinear = $("noiseValLinear");
47
  const noiseValAdv = $("noiseValAdv");
48
 
49
+ // HW noise elements (UI labels only unless backend supports)
50
  const hwNoiseWidth = $("hwNoiseWidth");
51
  const hwNoiseStrength = $("hwNoiseStrength");
52
  const hwNoiseWidthVal = $("hwNoiseWidthVal");
53
  const hwNoiseStrengthVal = $("hwNoiseStrengthVal");
54
 
55
  function setStatus(kind, text, logLine) {
56
+ // kind: idle | run | ok | bad
57
  if (statusDot) statusDot.className = `dot ${kind}`;
58
  if (statusText) statusText.textContent = text;
59
+ if (statusLog && logLine != null) statusLog.textContent = logLine;
60
  }
61
 
62
  function setRunning(isRunning) {
 
88
  fileInput.files = dt.files;
89
  }
90
 
91
+ // ---------------- Tabs ----------------
92
  function initTabs() {
93
  const tabBtns = qsa(".tabBtn");
94
  const tabPanels = qsa(".tabPanel");
 
106
  });
107
  }
108
 
109
+ // ------------- HDC bits toggle -------------
110
+ function initHdcBitsToggle() {
111
+ // score function select has NAME but no ID in your HTML
112
+ const scoreSel = document.querySelector('select[name="score_function"]');
113
+ const bitsField = $("hdcBitsField");
114
+ const bitsSel = $("hdcBits");
115
+
116
+ if (!scoreSel || !bitsField || !bitsSel) {
117
+ console.warn("HDC bits toggle: missing DOM elements");
118
+ return;
119
+ }
120
+
121
+ const update = () => {
122
+ const isHDC = scoreSel.value === "HDC";
123
+ bitsField.style.display = isHDC ? "" : "none";
124
+ bitsSel.disabled = !isHDC;
125
+ };
126
+
127
+ scoreSel.addEventListener("change", update);
128
+ update();
129
+ }
130
+
131
+ // ------------- Noise panel switching -------------
132
  function noiseFamily(val) {
133
  const t = String(val || "none").toLowerCase();
134
  if (t === "none" || t === "default" || t === "off") return "none";
 
168
 
169
  function initNoise() {
170
  if (!noiseType) return;
171
+
172
  noiseType.addEventListener("change", showNoisePanel);
173
 
174
+ if (noiseGaussian) {
175
+ noiseGaussian.addEventListener("input", () => {
176
+ if (noiseValGaussian) noiseValGaussian.textContent = noiseGaussian.value;
177
+ if (noiseFamily(noiseType.value) === "gaussian") updateNoiseHidden();
178
+ });
179
+ }
180
+
181
+ if (noiseLinear) {
182
+ noiseLinear.addEventListener("input", () => {
183
+ if (noiseValLinear) noiseValLinear.textContent = noiseLinear.value;
184
+ if (noiseFamily(noiseType.value) === "linear") updateNoiseHidden();
185
+ });
186
+ }
187
+
188
+ if (noiseAdv) {
189
+ noiseAdv.addEventListener("input", () => {
190
+ if (noiseValAdv) noiseValAdv.textContent = noiseAdv.value;
191
+ if (noiseFamily(noiseType.value) === "adv") updateNoiseHidden();
192
+ });
193
+ }
194
 
195
  showNoisePanel();
196
  }
197
 
198
+ // ------------- HW noise label updates -------------
199
  function initHwNoiseLabels() {
200
  if (hwNoiseWidth && hwNoiseWidthVal) {
201
+ hwNoiseWidthVal.textContent = hwNoiseWidth.value;
202
+ hwNoiseWidth.addEventListener("input", () => {
203
+ hwNoiseWidthVal.textContent = hwNoiseWidth.value;
204
+ });
205
  }
206
  if (hwNoiseStrength && hwNoiseStrengthVal) {
207
+ hwNoiseStrengthVal.textContent = hwNoiseStrength.value;
208
+ hwNoiseStrength.addEventListener("input", () => {
209
+ hwNoiseStrengthVal.textContent = hwNoiseStrength.value;
210
+ });
211
  }
212
  }
213
 
214
+ // ------------- Upload / Dropzone -------------
215
  function initUpload() {
216
  if (!fileInput || !dropzone) return;
217
 
 
232
  e.preventDefault();
233
  dropzone.classList.add("drag");
234
  });
235
+
236
+ dropzone.addEventListener("dragleave", () => {
237
+ dropzone.classList.remove("drag");
238
+ });
239
 
240
  dropzone.addEventListener("drop", (e) => {
241
  e.preventDefault();
 
247
  });
248
  }
249
 
250
+ // ------------- Reset -------------
251
  function initReset() {
252
  if (!resetBtn || !form) return;
253
  resetBtn.addEventListener("click", () => {
254
  form.reset();
255
  if (fileInput) fileInput.value = "";
256
  setPreview(null);
257
+
258
  if (jobPill) jobPill.textContent = "job: —";
259
  if (imgInput) imgInput.removeAttribute("src");
260
  if (imgYolo) imgYolo.removeAttribute("src");
261
  if (imgSelected) imgSelected.removeAttribute("src");
262
  if (meta) meta.textContent = "";
263
+
264
+ // reset labels
265
+ if (noiseValGaussian && noiseGaussian) noiseValGaussian.textContent = noiseGaussian.value;
266
+ if (noiseValLinear && noiseLinear) noiseValLinear.textContent = noiseLinear.value;
267
+ if (noiseValAdv && noiseAdv) noiseValAdv.textContent = noiseAdv.value;
268
+
269
+ initHdcBitsToggle();
270
+ showNoisePanel();
271
+
272
  setStatus("idle", "Idle", "Waiting for input…");
273
  setRunning(false);
 
274
  });
275
  }
276
 
277
+ // ------------- Copy meta -------------
278
  function initCopyMeta() {
279
  if (!copyMetaBtn || !meta) return;
280
  copyMetaBtn.addEventListener("click", async () => {
 
285
  });
286
  }
287
 
288
+ // ------------- Submit -------------
289
  function initSubmit() {
290
  if (!form) return;
291
 
 
298
  return;
299
  }
300
 
301
+ updateNoiseHidden();
302
  setRunning(true);
303
  setStatus("run", "Running", "Submitting request…");
304
 
305
  try {
306
  const fd = new FormData(form);
 
 
307
  const resp = await fetch("/api/run", { method: "POST", body: fd });
308
  const data = await resp.json();
309
 
 
344
 
345
  // Boot
346
  document.addEventListener("DOMContentLoaded", () => {
 
347
  if (!form || !fileInput || !dropzone) {
348
+ console.error("Missing DOM elements: check ids in HTML.");
349
  if (statusLog) statusLog.textContent = "JS init failed: missing DOM elements (check ids).";
350
  return;
351
  }
352
+
353
  initTabs();
354
+ initHdcBitsToggle();
355
  initNoise();
356
  initHwNoiseLabels();
357
  initUpload();
358
  initReset();
359
  initCopyMeta();
360
  initSubmit();
361
+
362
  setStatus("idle", "Idle", "Waiting for input…");
363
  });
364
  })();