jfrery-zama commited on
Commit
75bf83f
·
unverified ·
1 Parent(s): d34d52f

add estimation of completion time

Browse files
Files changed (2) hide show
  1. index.html +1 -0
  2. wasm-demo.js +22 -2
index.html CHANGED
@@ -431,6 +431,7 @@ sequenceDiagram
431
  <div>
432
  <p id="srvStatus" class="status" aria-live="polite">Waiting for encrypted data...</p>
433
  <p id="srvComputing" class="status" aria-live="polite" hidden>Server computing...</p>
 
434
  </div>
435
  <div class="controls" style="margin-top: auto;">
436
  <button id="btnSend" class="btn" disabled>📡 Send</button>
 
431
  <div>
432
  <p id="srvStatus" class="status" aria-live="polite">Waiting for encrypted data...</p>
433
  <p id="srvComputing" class="status" aria-live="polite" hidden>Server computing...</p>
434
+ <p id="srvProgress" class="status" aria-live="polite" hidden></p>
435
  </div>
436
  <div class="controls" style="margin-top: auto;">
437
  <button id="btnSend" class="btn" disabled>📡 Send</button>
wasm-demo.js CHANGED
@@ -173,6 +173,7 @@ $('btnSend').onclick = async () => {
173
  show('spin', true);
174
  $('srvStatus').textContent = 'Preparing request…';
175
  $('srvComputing').hidden = true;
 
176
  const startTime = performance.now();
177
  try {
178
  const ciphertext_b64 = await uint8ToBase64(encTokens);
@@ -198,16 +199,34 @@ $('btnSend').onclick = async () => {
198
 
199
  $('srvStatus').textContent = '✓ sent';
200
  $('srvComputing').hidden = false;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
201
 
202
  const {result_b64} = await response.json();
203
- const endTime = performance.now();
204
- const duration = ((endTime - startTime) / 1000).toFixed(2);
 
205
  console.log(`[Main] Server request completed in ${duration}s`);
206
  console.log('[Main] Processing server response...');
207
  encServerResult = Uint8Array.from(atob(result_b64), c=>c.charCodeAt(0));
208
  console.log(`[Main] Received encrypted result: ${encServerResult.length} bytes`);
209
  $('encResult').value = `(${encServerResult.length} B)`;
210
  $('srvComputing').hidden = true;
 
211
  $('srvStatus').textContent = `✓ received (${duration}s)`;
212
  enable('btnDecrypt');
213
  } catch (e) {
@@ -215,6 +234,7 @@ $('btnSend').onclick = async () => {
215
  const duration = ((endTime - startTime) / 1000).toFixed(2);
216
  console.error(`[Main] Server request failed after ${duration}s:`, e);
217
  $('srvComputing').hidden = true;
 
218
  $('srvStatus').textContent = `Server error: ${e.message} (${duration}s)`;
219
  show('spin', false);
220
  }
 
173
  show('spin', true);
174
  $('srvStatus').textContent = 'Preparing request…';
175
  $('srvComputing').hidden = true;
176
+ $('srvProgress').hidden = true;
177
  const startTime = performance.now();
178
  try {
179
  const ciphertext_b64 = await uint8ToBase64(encTokens);
 
199
 
200
  $('srvStatus').textContent = '✓ sent';
201
  $('srvComputing').hidden = false;
202
+ $('srvProgress').hidden = false;
203
+
204
+ const tokenCount = llama3Tokenizer.encode($('tokenInput').value.trim()).length;
205
+ const estimatedTime = tokenCount * 15;
206
+ const endTime = startTime + (estimatedTime * 1000);
207
+
208
+ const progressInterval = setInterval(() => {
209
+ const now = performance.now();
210
+ const elapsed = (now - startTime) / 1000;
211
+ const remaining = Math.max(0, estimatedTime - elapsed);
212
+ $('srvProgress').textContent = `Estimated time remaining: ${Math.ceil(remaining)}s`;
213
+
214
+ if (remaining <= 0) {
215
+ clearInterval(progressInterval);
216
+ }
217
+ }, 1000);
218
 
219
  const {result_b64} = await response.json();
220
+ clearInterval(progressInterval);
221
+ const actualEndTime = performance.now();
222
+ const duration = ((actualEndTime - startTime) / 1000).toFixed(2);
223
  console.log(`[Main] Server request completed in ${duration}s`);
224
  console.log('[Main] Processing server response...');
225
  encServerResult = Uint8Array.from(atob(result_b64), c=>c.charCodeAt(0));
226
  console.log(`[Main] Received encrypted result: ${encServerResult.length} bytes`);
227
  $('encResult').value = `(${encServerResult.length} B)`;
228
  $('srvComputing').hidden = true;
229
+ $('srvProgress').hidden = true;
230
  $('srvStatus').textContent = `✓ received (${duration}s)`;
231
  enable('btnDecrypt');
232
  } catch (e) {
 
234
  const duration = ((endTime - startTime) / 1000).toFixed(2);
235
  console.error(`[Main] Server request failed after ${duration}s:`, e);
236
  $('srvComputing').hidden = true;
237
+ $('srvProgress').hidden = true;
238
  $('srvStatus').textContent = `Server error: ${e.message} (${duration}s)`;
239
  show('spin', false);
240
  }