Update index.js
Browse files
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 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
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 |
});
|