pdufour commited on
Commit
76ac858
1 Parent(s): 55fd388

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +14 -10
index.js CHANGED
@@ -323,11 +323,21 @@ export async function imageTextToText(
323
  }
324
  }
325
 
 
 
 
 
 
 
 
 
 
326
  await initializeSessions();
327
 
328
  // UI Event Handlers
329
  example.addEventListener('click', (e) => {
330
  e.preventDefault();
 
331
  parse(EXAMPLE_URL, 'Describe this image.');
332
  });
333
 
@@ -338,16 +348,10 @@ fileUpload.addEventListener('change', async function(e) {
338
  const reader = new FileReader();
339
 
340
  reader.onload = async (e2) => {
341
- const url = e2.target.result;
342
-
343
- const image = await RawImage.fromURL(url);
344
- const ar = image.width / image.height;
345
- const [cw, ch] = (ar > 1) ? [640, 640 / ar] : [640 * ar, 640];
346
- imageContainer.style.width = `${cw}px`;
347
- imageContainer.style.height = `${ch}px`;
348
- imageContainer.style.backgroundImage = `url(${url})`;
349
- // reader.onload = e2 => parse(e2.target.result, '');
350
-
351
  }
352
  reader.readAsDataURL(file);
353
  });
 
323
  }
324
  }
325
 
326
+ async function updatePreview(url) {
327
+ const image = await RawImage.fromURL(url);
328
+ const ar = image.width / image.height;
329
+ const [cw, ch] = (ar > 1) ? [640, 640 / ar] : [640 * ar, 640];
330
+ imageContainer.style.width = `${cw}px`;
331
+ imageContainer.style.height = `${ch}px`;
332
+ imageContainer.style.backgroundImage = `url(${url})`;
333
+ }
334
+
335
  await initializeSessions();
336
 
337
  // UI Event Handlers
338
  example.addEventListener('click', (e) => {
339
  e.preventDefault();
340
+ updatepreview(EXAMPLE_URL);
341
  parse(EXAMPLE_URL, 'Describe this image.');
342
  });
343
 
 
348
  const reader = new FileReader();
349
 
350
  reader.onload = async (e2) => {
351
+ reader.onload = function() {
352
+ updatePreview(e2.target.result);
353
+ // parse(e2.target.result)
354
+ }
 
 
 
 
 
 
355
  }
356
  reader.readAsDataURL(file);
357
  });