BoxOfColors commited on
Commit
83e14c2
·
1 Parent(s): 0219f72

Randomize seed fields on every page load via JS

Browse files
Files changed (1) hide show
  1. app.py +18 -0
app.py CHANGED
@@ -1507,6 +1507,24 @@ _GLOBAL_JS = """
1507
  if (window._wf_global_listener) return; // already registered
1508
  window._wf_global_listener = true;
1509
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1510
  // Cache: api_name -> fn_index, built once from gradio_config.dependencies
1511
  let _fnIndexCache = null;
1512
  function getFnIndex(apiName) {
 
1507
  if (window._wf_global_listener) return; // already registered
1508
  window._wf_global_listener = true;
1509
 
1510
+ // Randomize seed fields on every page load so each session gets a fresh seed.
1511
+ function randomizeSeedFields() {
1512
+ ['taro_seed', 'mma_seed', 'hf_seed'].forEach(function(id) {
1513
+ var el = document.getElementById(id);
1514
+ if (!el) return;
1515
+ var input = el.querySelector('input');
1516
+ if (!input) return;
1517
+ var newSeed = Math.floor(Math.random() * 4294967296);
1518
+ // Set value and fire input+change events so Gradio picks up the new value
1519
+ var nativeInputValueSetter = Object.getOwnPropertyDescriptor(window.HTMLInputElement.prototype, 'value').set;
1520
+ nativeInputValueSetter.call(input, newSeed);
1521
+ input.dispatchEvent(new Event('input', {bubbles: true}));
1522
+ input.dispatchEvent(new Event('change', {bubbles: true}));
1523
+ });
1524
+ }
1525
+ // Run after a short delay to let Gradio finish mounting the components
1526
+ setTimeout(randomizeSeedFields, 800);
1527
+
1528
  // Cache: api_name -> fn_index, built once from gradio_config.dependencies
1529
  let _fnIndexCache = null;
1530
  function getFnIndex(apiName) {