pdufour commited on
Commit
e1e8a25
·
verified ·
1 Parent(s): efb6eb2

Update index.js

Browse files
Files changed (1) hide show
  1. index.js +8 -3
index.js CHANGED
@@ -22,6 +22,7 @@ const example = document.getElementById('example');
22
  const thumb = document.getElementById('thumb');
23
  const uploadInput = document.getElementById('upload');
24
  const form = document.getElementById('form');
 
25
 
26
  let ortSessionA, ortSessionB, ortSessionC, ortSessionD, ortSessionE;
27
  let config;
@@ -134,7 +135,9 @@ async function handleQuery(imageUrl, query) {
134
  try {
135
  status.textContent = 'Analyzing...';
136
 
137
- const result = await imageTextToText(imageUrl, query);
 
 
138
  status.textContent = result;
139
  } catch (err) {
140
  status.textContent = 'Error processing request';
@@ -146,7 +149,8 @@ async function handleQuery(imageUrl, query) {
146
  export async function imageTextToText(
147
  imagePath,
148
  query,
149
- vision = true
 
150
  ) {
151
 
152
  const prompt_head_len = new Tensor("int64", new BigInt64Array([5n]), [1]);
@@ -333,11 +337,12 @@ export async function imageTextToText(
333
  throw new Error(`Token ID is not an integer`);
334
  } else {
335
  const decoded = tokenizer.decode([...token_id.data]);
336
- console.log({decoded});
337
 
338
  output += decoded;
339
  }
340
  }
 
341
  }
342
 
343
  async function updatePreview(url) {
 
22
  const thumb = document.getElementById('thumb');
23
  const uploadInput = document.getElementById('upload');
24
  const form = document.getElementById('form');
25
+ const output = document.getElementById('llm-output');
26
 
27
  let ortSessionA, ortSessionB, ortSessionC, ortSessionD, ortSessionE;
28
  let config;
 
135
  try {
136
  status.textContent = 'Analyzing...';
137
 
138
+ const result = await imageTextToText(imageUrl, query, function cb(out) {
139
+ output.textContent = out;
140
+ });
141
  status.textContent = result;
142
  } catch (err) {
143
  status.textContent = 'Error processing request';
 
149
  export async function imageTextToText(
150
  imagePath,
151
  query,
152
+ cb,
153
+ vision = true,
154
  ) {
155
 
156
  const prompt_head_len = new Tensor("int64", new BigInt64Array([5n]), [1]);
 
337
  throw new Error(`Token ID is not an integer`);
338
  } else {
339
  const decoded = tokenizer.decode([...token_id.data]);
340
+ cb(output);
341
 
342
  output += decoded;
343
  }
344
  }
345
+ return output;
346
  }
347
 
348
  async function updatePreview(url) {