esilver commited on
Commit
115a2ec
·
1 Parent(s): 18ec5e9

compare to chicory-ui

Browse files
Files changed (1) hide show
  1. main.py +26 -1
main.py CHANGED
@@ -33,7 +33,32 @@ def main():
33
 
34
  # Create and launch the interface
35
  demo = create_demo()
36
- demo.launch(share=args.share)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
37
 
38
  if __name__ == "__main__":
39
  main()
 
33
 
34
  # Create and launch the interface
35
  demo = create_demo()
36
+
37
+ # Register keyboard shortcuts for the interface
38
+ demo.launch(
39
+ share=args.share,
40
+ # These are the keyboard shortcuts - use these options instead of custom JS
41
+ show_api=False,
42
+ # This sets the keyboard shortcuts at the Gradio level which is more reliable
43
+ _js="""
44
+ document.addEventListener('keydown', function(e) {
45
+ if ((e.metaKey || e.ctrlKey) && e.key === 'Enter') {
46
+ // Find visible buttons in the active tab
47
+ const buttons = document.querySelectorAll('button.primary');
48
+ buttons.forEach(button => {
49
+ // Check if the button is visible
50
+ const rect = button.getBoundingClientRect();
51
+ if (rect.width > 0 && rect.height > 0 && getComputedStyle(button).display !== 'none') {
52
+ // Click the first visible button
53
+ button.click();
54
+ e.preventDefault();
55
+ return;
56
+ }
57
+ });
58
+ }
59
+ });
60
+ """
61
+ )
62
 
63
  if __name__ == "__main__":
64
  main()