pdufour commited on
Commit
b75228d
·
verified ·
1 Parent(s): 9bd581c

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +4 -8
index.js CHANGED
@@ -27,7 +27,7 @@ status.textContent = 'Ready';
27
 
28
  example.addEventListener('click', (e) => {
29
  e.preventDefault();
30
- detect(EXAMPLE_URL);
31
  });
32
 
33
  fileUpload.addEventListener('change', function (e) {
@@ -39,22 +39,18 @@ fileUpload.addEventListener('change', function (e) {
39
  const reader = new FileReader();
40
 
41
  // Set up a callback when the file is loaded
42
- reader.onload = e2 => detect(e2.target.result);
43
 
44
  reader.readAsDataURL(file);
45
  });
46
 
47
 
48
- // Detect objects in the image
49
- async function detect(img) {
50
  imageContainer.innerHTML = '';
51
  imageContainer.style.backgroundImage = `url(${img})`;
52
 
53
  status.textContent = 'Analysing...';
54
- const output = await detector(img, {
55
- threshold: 0.5,
56
- percentage: true,
57
- });
58
  status.textContent = '';
59
  output.forEach(renderBox);
60
  }
 
27
 
28
  example.addEventListener('click', (e) => {
29
  e.preventDefault();
30
+ parse(EXAMPLE_URL, 'Describe this image.');
31
  });
32
 
33
  fileUpload.addEventListener('change', function (e) {
 
39
  const reader = new FileReader();
40
 
41
  // Set up a callback when the file is loaded
42
+ reader.onload = e2 => parse(e2.target.result, '');
43
 
44
  reader.readAsDataURL(file);
45
  });
46
 
47
 
48
+ async function parse(img, txt) {
 
49
  imageContainer.innerHTML = '';
50
  imageContainer.style.backgroundImage = `url(${img})`;
51
 
52
  status.textContent = 'Analysing...';
53
+ const output = await imageTextToText(img, query);
 
 
 
54
  status.textContent = '';
55
  output.forEach(renderBox);
56
  }