pdufour commited on
Commit
350ff37
1 Parent(s): e00846c

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +7 -18
index.js CHANGED
@@ -20,6 +20,7 @@ const status = document.getElementById('status');
20
  const imageContainer = document.getElementById('container');
21
  const example = document.getElementById('example');
22
  const uploadInput = document.getElementById('upload');
 
23
 
24
  let ortSessionA, ortSessionB, ortSessionC, ortSessionD, ortSessionE;
25
  let config;
@@ -368,7 +369,6 @@ exampleButton.addEventListener('click', (e) => {
368
  e.preventDefault();
369
  e.stopPropagation();
370
  currentImage = EXAMPLE_URL;
371
- status.textContent = promptInput.value.trim() ? 'Press Enter to analyze' : 'Add a prompt and press Enter';
372
  });
373
 
374
  uploadInput.addEventListener('change', (e) => {
@@ -378,26 +378,15 @@ uploadInput.addEventListener('change', (e) => {
378
  const reader = new FileReader();
379
  reader.onload = (e2) => {
380
  currentImage = e2.target.result;
381
- status.textContent = promptInput.value.trim() ? 'Press Enter to analyze' : 'Add a prompt and press Enter';
382
  };
383
  reader.readAsDataURL(file);
384
  });
385
 
386
- promptInput.addEventListener('keypress', (e) => {
387
- currentQuery = e.target.value;
388
- if (e.key === 'Enter') {
389
- if (!currentImage) {
390
- status.textContent = 'Please select an image first';
391
- return;
392
- }
393
- handleQuery(currentImage, currentQuery);
394
- }
395
- });
396
 
397
- promptInput.addEventListener('input', () => {
398
- if (currentImage && !promptInput.value.trim()) {
399
- status.textContent = 'Add a prompt and press Enter';
400
- } else if (currentImage && promptInput.value.trim()) {
401
- status.textContent = 'Press Enter to analyze';
402
  }
403
- });
 
20
  const imageContainer = document.getElementById('container');
21
  const example = document.getElementById('example');
22
  const uploadInput = document.getElementById('upload');
23
+ const form = document.getElementById('form');
24
 
25
  let ortSessionA, ortSessionB, ortSessionC, ortSessionD, ortSessionE;
26
  let config;
 
369
  e.preventDefault();
370
  e.stopPropagation();
371
  currentImage = EXAMPLE_URL;
 
372
  });
373
 
374
  uploadInput.addEventListener('change', (e) => {
 
378
  const reader = new FileReader();
379
  reader.onload = (e2) => {
380
  currentImage = e2.target.result;
 
381
  };
382
  reader.readAsDataURL(file);
383
  });
384
 
 
 
 
 
 
 
 
 
 
 
385
 
386
+ form.addEventListener('submit', () => {
387
+ if (!currentImage || !currentQuery) {
388
+ status.textContent = 'Please select an image and type a prompt';
389
+ } else {
390
+ handleQuery(currentImage, currentQuery);
391
  }
392
+ });