esilver commited on
Commit
25f9523
·
1 Parent(s): 6743e90

compare to chicory-ui

Browse files
Files changed (1) hide show
  1. ui.py +19 -7
ui.py CHANGED
@@ -81,8 +81,25 @@ def create_demo():
81
  border-bottom: 2px solid #555 !important; /* Adjusted for dark background */
82
  padding-bottom: 5px !important;
83
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
84
  """) as demo:
85
  gr.Markdown("# Product Categorization Tool\nAnalyze products and find the most similar ingredients using AI embeddings.")
 
86
 
87
  with gr.Tabs():
88
  with gr.TabItem("Text Input"):
@@ -104,19 +121,14 @@ def create_demo():
104
  # Results section
105
  text_output = gr.HTML(label="Categorization Results", elem_classes="results-container")
106
 
107
- # Connect both button click and Enter key press to the categorize function
108
  categorize_btn.click(
109
  fn=categorize_products,
110
  inputs=[text_input, gr.State(False), top_n, confidence],
111
  outputs=text_output
112
  )
113
 
114
- # Add Enter key functionality
115
- text_input.submit(
116
- fn=categorize_products,
117
- inputs=[text_input, gr.State(False), top_n, confidence],
118
- outputs=text_output
119
- )
120
 
121
  with gr.TabItem("File Upload"):
122
  with gr.Row():
 
81
  border-bottom: 2px solid #555 !important; /* Adjusted for dark background */
82
  padding-bottom: 5px !important;
83
  }
84
+ """, js="""
85
+ // Add keyboard shortcut support for Cmd+Enter (Mac) or Ctrl+Enter (Windows/Linux)
86
+ document.addEventListener('keydown', function(e) {
87
+ if ((e.metaKey || e.ctrlKey) && e.key === 'Enter') {
88
+ // Check if we're in the text input tab
89
+ const activeTextarea = document.querySelector('.tab-nav button[aria-selected="true"]').textContent.includes("Text Input") ?
90
+ document.querySelector('.tab-panel[style*="display: block"] textarea') : null;
91
+
92
+ if (activeTextarea) {
93
+ // Find and click the corresponding button
94
+ const categorizeBtn = document.querySelector('.tab-panel[style*="display: block"] button:contains("Categorize")');
95
+ if (categorizeBtn) categorizeBtn.click();
96
+ e.preventDefault();
97
+ }
98
+ }
99
+ });
100
  """) as demo:
101
  gr.Markdown("# Product Categorization Tool\nAnalyze products and find the most similar ingredients using AI embeddings.")
102
+ gr.Markdown("Use **Cmd+Enter** (Mac) or **Ctrl+Enter** (Windows/Linux) to quickly categorize products.")
103
 
104
  with gr.Tabs():
105
  with gr.TabItem("Text Input"):
 
121
  # Results section
122
  text_output = gr.HTML(label="Categorization Results", elem_classes="results-container")
123
 
124
+ # Connect button click to the categorize function
125
  categorize_btn.click(
126
  fn=categorize_products,
127
  inputs=[text_input, gr.State(False), top_n, confidence],
128
  outputs=text_output
129
  )
130
 
131
+ # Custom JS handling of Cmd+Enter/Ctrl+Enter is configured in js parameter above
 
 
 
 
 
132
 
133
  with gr.TabItem("File Upload"):
134
  with gr.Row():