esilver commited on
Commit
9ad55c4
·
1 Parent(s): 5cacb67

compare to chicory-ui

Browse files
Files changed (1) hide show
  1. ui.py +9 -30
ui.py CHANGED
@@ -123,7 +123,7 @@ def create_demo():
123
  }
124
  """) as demo:
125
  gr.Markdown("# Product Categorization Tool\nAnalyze products and find the most similar ingredients using AI embeddings.")
126
- gr.Markdown("Use **Cmd+Enter** (Mac) or **Ctrl+Enter** (Windows/Linux) to quickly categorize products.")
127
 
128
  with gr.Tabs() as tabs:
129
  with gr.TabItem("Text Input"):
@@ -177,41 +177,20 @@ def create_demo():
177
  outputs=text_input
178
  )
179
 
 
 
 
 
 
 
 
180
  process_btn.click(
181
  fn=categorize_products,
182
  inputs=[file_input, gr.State(True), file_top_n, file_confidence],
183
  outputs=file_output
184
  )
185
 
186
- # Add keyboard shortcut handler for both tabs
187
- text_input.change(None, None, None, js="""
188
- function() {
189
- // Set up the keyboard event listener
190
- document.removeEventListener('keydown', cmdEnterHandler);
191
- document.addEventListener('keydown', cmdEnterHandler);
192
-
193
- function cmdEnterHandler(e) {
194
- if ((e.metaKey || e.ctrlKey) && e.key === 'Enter') {
195
- // Find the currently visible tab content
196
- const textTab = document.querySelector('.tabitem:nth-child(1)');
197
- const fileTab = document.querySelector('.tabitem:nth-child(2)');
198
-
199
- if (textTab && window.getComputedStyle(textTab).display !== 'none') {
200
- // Text tab is active
201
- const button = textTab.querySelector('button');
202
- if (button) button.click();
203
- } else if (fileTab && window.getComputedStyle(fileTab).display !== 'none') {
204
- // File tab is active
205
- const button = fileTab.querySelector('button');
206
- if (button) button.click();
207
- }
208
- e.preventDefault();
209
- }
210
- }
211
-
212
- return [];
213
- }
214
- """)
215
 
216
  gr.Markdown("Powered by Voyage AI embeddings • Built with Gradio")
217
 
 
123
  }
124
  """) as demo:
125
  gr.Markdown("# Product Categorization Tool\nAnalyze products and find the most similar ingredients using AI embeddings.")
126
+ gr.Markdown("Use **Enter** to quickly categorize products (shortcut works in both tabs).")
127
 
128
  with gr.Tabs() as tabs:
129
  with gr.TabItem("Text Input"):
 
177
  outputs=text_input
178
  )
179
 
180
+ # Add Enter key submission capability using submit event
181
+ text_input.submit(
182
+ fn=categorize_products,
183
+ inputs=[text_input, gr.State(False), top_n, confidence],
184
+ outputs=text_output
185
+ )
186
+
187
  process_btn.click(
188
  fn=categorize_products,
189
  inputs=[file_input, gr.State(True), file_top_n, file_confidence],
190
  outputs=file_output
191
  )
192
 
193
+ # Remove the custom JavaScript keyboard handler since we're using Gradio's built-in submit event
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
194
 
195
  gr.Markdown("Powered by Voyage AI embeddings • Built with Gradio")
196