chuckfinca Claude Opus 4.6 (1M context) commited on
Commit
04d3f5a
·
1 Parent(s): 350eca4

Use head= for JS injection instead of js= parameter

Browse files

Gradio js= wraps code in AsyncFunction which rejects function
declarations. head= injects raw script tags into head section.
Wrap app code in DOMContentLoaded listener.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

Files changed (1) hide show
  1. app.py +4 -3
app.py CHANGED
@@ -274,7 +274,7 @@ CUSTOM_CSS = _CHAT_UI_CSS + """
274
  """
275
 
276
  CUSTOM_JS = _CHAT_UI_JS + """
277
- ;(function() {
278
  var API_BASE = window.location.origin;
279
  var tokenInput = document.getElementById('token-input');
280
  var fileInput = document.getElementById('file-input');
@@ -452,12 +452,13 @@ CUSTOM_JS = _CHAT_UI_JS + """
452
  chatInput.placeholder = 'Ask a question about your documents...';
453
  });
454
  });
455
- })();
456
  """
457
 
458
 
459
  def build_app() -> gr.Blocks:
460
- with gr.Blocks(title="Document Explorer", css=CUSTOM_CSS, js=CUSTOM_JS) as demo:
 
461
  gr.HTML(CUSTOM_HTML)
462
 
463
  # Hidden state for file upload workspace
 
274
  """
275
 
276
  CUSTOM_JS = _CHAT_UI_JS + """
277
+ ;document.addEventListener('DOMContentLoaded', function() {
278
  var API_BASE = window.location.origin;
279
  var tokenInput = document.getElementById('token-input');
280
  var fileInput = document.getElementById('file-input');
 
452
  chatInput.placeholder = 'Ask a question about your documents...';
453
  });
454
  });
455
+ });
456
  """
457
 
458
 
459
  def build_app() -> gr.Blocks:
460
+ custom_head = f"<script>{CUSTOM_JS}</script>"
461
+ with gr.Blocks(title="Document Explorer", css=CUSTOM_CSS, head=custom_head) as demo:
462
  gr.HTML(CUSTOM_HTML)
463
 
464
  # Hidden state for file upload workspace