Update index.js
Browse files
index.js
CHANGED
@@ -331,17 +331,16 @@ example.addEventListener('click', (e) => {
|
|
331 |
parse(EXAMPLE_URL, 'Describe this image.');
|
332 |
});
|
333 |
|
334 |
-
fileUpload.addEventListener('change', function(e) {
|
335 |
const file = e.target.files[0];
|
336 |
if (!file) return;
|
337 |
|
338 |
const image = await RawImage.fromURL(url);
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
// imageContainer.style.backgroundImage = `url(${url})`;
|
345 |
|
346 |
const reader = new FileReader();
|
347 |
// reader.onload = e2 => parse(e2.target.result, '');
|
|
|
331 |
parse(EXAMPLE_URL, 'Describe this image.');
|
332 |
});
|
333 |
|
334 |
+
fileUpload.addEventListener('change', async function(e) {
|
335 |
const file = e.target.files[0];
|
336 |
if (!file) return;
|
337 |
|
338 |
const image = await RawImage.fromURL(url);
|
339 |
+
const ar = image.width / image.height;
|
340 |
+
const [cw, ch] = (ar > 1) ? [640, 640 / ar] : [640 * ar, 640];
|
341 |
+
imageContainer.style.width = `${cw}px`;
|
342 |
+
imageContainer.style.height = `${ch}px`;
|
343 |
+
imageContainer.style.backgroundImage = `url(${url})`;
|
|
|
344 |
|
345 |
const reader = new FileReader();
|
346 |
// reader.onload = e2 => parse(e2.target.result, '');
|