musk12 commited on
Commit
99f297c
·
verified ·
1 Parent(s): 79641be

Update templates/index.html

Browse files
Files changed (1) hide show
  1. templates/index.html +57 -69
templates/index.html CHANGED
@@ -225,95 +225,83 @@
225
  {% else %}
226
  {% endif %}
227
 
228
- <script>
229
- document.addEventListener("DOMContentLoaded", () => {
230
- const slider = document.getElementById("alphaSlider");
231
- const morphedImg = document.getElementById("morphed");
232
- const alphaDisplay = document.getElementById("alphaValue");
233
-
234
- slider.addEventListener("input", () => {
235
- let alpha = parseFloat(slider.value);
236
- alphaDisplay.textContent = alpha.toFixed(2);
237
-
238
- fetch("/morph_ajax", {
239
- method: "POST",
240
- headers: { "Content-Type": "application/json" },
241
- body: JSON.stringify({ alpha: alpha })
242
- })
243
- .then(res => res.json())
244
- .then(data => {
245
- if (data.filename) {
246
- morphedImg.src = `/tmp/${data.filename}?t=${data.ts}`;
247
- }
248
- })
249
- .catch(err => console.error(err));
250
- });
251
- });
252
- </script>
253
 
254
 
255
- <script>
256
- const imgEl = document.getElementById('morphed');
257
- imgEl.src = `/tmp/${data.filename}?t=${data.ts}`;
258
- const generate100Button = document.querySelector('button[value="generate100"]');
259
- const loadingDiv = document.getElementById('loading');
260
- generate100Button.addEventListener('click', function() {
261
- loadingDiv.style.display = 'block';
262
- console.log('Generate 100 clicked');
263
- });
264
- const batchImages = document.querySelectorAll('.row-cols-md-5 img');
265
- if (batchImages.length === 0) {
266
- loadingDiv.style.display = 'none';
267
- console.log('No batch images to load');
268
- } else {
269
- let loadedCount = 0;
270
- batchImages.forEach((img, index) => {
271
- img.addEventListener('load', () => {
272
- loadedCount++;
273
- console.log(`Image ${index} loaded`);
274
- if (loadedCount === batchImages.length) {
275
- loadingDiv.style.display = 'none';
276
- console.log('All batch images loaded');
277
- }
278
- });
279
- img.addEventListener('error', () => {
280
- loadedCount++;
281
- console.log(`Image ${index} failed to load: ${img.src}`);
282
- img.style.display = 'none';
283
- if (loadedCount === batchImages.length) {
284
- loadingDiv.style.display = 'none';
285
- console.log('All batch images processed (some failed)');
286
- }
287
- });
288
- });
289
-
290
 
291
- }
292
- </script>
 
 
293
 
 
 
 
 
 
 
 
 
 
 
 
 
 
294
 
295
- <script>
296
- document.getElementById("morph-btn").addEventListener("click", function () {
297
- const slider = document.getElementById("alphaSlider"); // correct id
298
  slider.value = 0.5;
299
- document.getElementById("alphaValue").textContent = "0.50"; // correct id
300
 
301
  fetch("/morph_ajax", {
302
  method: "POST",
303
  headers: { "Content-Type": "application/json" },
304
  body: JSON.stringify({ alpha: 0.5 })
305
  })
306
- .then(response => response.json())
307
  .then(data => {
308
  if (data.filename) {
309
- const morphedImg = document.getElementById("morphed");
310
  morphedImg.src = `/tmp/${data.filename}?t=${data.ts}`;
311
  }
312
  })
313
  .catch(err => console.error("Morph reset error:", err));
314
  });
315
 
316
- </script>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
317
 
318
 
319
  </div>
 
225
  {% else %}
226
  {% endif %}
227
 
228
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
229
 
230
 
231
+ <script>
232
+ document.addEventListener("DOMContentLoaded", () => {
233
+ const slider = document.getElementById("alphaSlider");
234
+ const morphedImg = document.getElementById("morphed");
235
+ const alphaDisplay = document.getElementById("alphaValue");
236
+ const morphBtn = document.getElementById("morph-btn");
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
237
 
238
+ // Slider: live morphing
239
+ slider.addEventListener("input", () => {
240
+ let alpha = parseFloat(slider.value);
241
+ alphaDisplay.textContent = alpha.toFixed(2);
242
 
243
+ fetch("/morph_ajax", {
244
+ method: "POST",
245
+ headers: { "Content-Type": "application/json" },
246
+ body: JSON.stringify({ alpha: alpha })
247
+ })
248
+ .then(res => res.json())
249
+ .then(data => {
250
+ if (data.filename) {
251
+ morphedImg.src = `/tmp/${data.filename}?t=${data.ts}`;
252
+ }
253
+ })
254
+ .catch(err => console.error("Morph fetch error:", err));
255
+ });
256
 
257
+ // Reset morph to α=0.5
258
+ morphBtn.addEventListener("click", () => {
 
259
  slider.value = 0.5;
260
+ alphaDisplay.textContent = "0.50";
261
 
262
  fetch("/morph_ajax", {
263
  method: "POST",
264
  headers: { "Content-Type": "application/json" },
265
  body: JSON.stringify({ alpha: 0.5 })
266
  })
267
+ .then(res => res.json())
268
  .then(data => {
269
  if (data.filename) {
 
270
  morphedImg.src = `/tmp/${data.filename}?t=${data.ts}`;
271
  }
272
  })
273
  .catch(err => console.error("Morph reset error:", err));
274
  });
275
 
276
+ // Batch generation spinner
277
+ const generate100Button = document.querySelector('button[value="generate100"]');
278
+ const loadingDiv = document.getElementById("loading");
279
+
280
+ generate100Button.addEventListener("click", () => {
281
+ loadingDiv.style.display = "block";
282
+ console.log("Generate 100 clicked");
283
+
284
+ let loadedCount = 0;
285
+ const batchImages = document.querySelectorAll('.row-cols-md-5 img');
286
+ batchImages.forEach((img, index) => {
287
+ img.addEventListener("load", () => {
288
+ loadedCount++;
289
+ if (loadedCount === batchImages.length) {
290
+ loadingDiv.style.display = "none";
291
+ }
292
+ });
293
+ img.addEventListener("error", () => {
294
+ loadedCount++;
295
+ img.style.display = "none";
296
+ if (loadedCount === batchImages.length) {
297
+ loadingDiv.style.display = "none";
298
+ }
299
+ });
300
+ });
301
+ });
302
+ });
303
+ </script>
304
+
305
 
306
 
307
  </div>