NeoSapian commited on
Commit
b548ab1
·
verified ·
1 Parent(s): b02deae

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +52 -4
index.html CHANGED
@@ -158,6 +158,19 @@ kbd{font-size:.7rem;background:rgba(6,16,31,.25);padding:2px 7px;border-radius:5
158
  .ins{background:linear-gradient(var(--surf2),var(--surf2)) padding-box,linear-gradient(120deg,#4d8dff,#2dd4e8,#9b72cb) border-box}
159
  .empty{background:var(--bg);border-color:var(--line)}details{border-color:var(--line)}
160
  footer{background:none;font-size:.78rem}
 
 
 
 
 
 
 
 
 
 
 
 
 
161
  </style></head><body>
162
  <nav><div class="w"><div class="logo">jev<i>/</i>fin <b class="ver mono">0.8b</b></div>
163
  <button class="nl on" data-v="play">Try it</button><button class="nl" data-v="port">Portfolio lab</button><button class="nl" data-v="about">About</button>
@@ -174,6 +187,7 @@ footer{background:none;font-size:.78rem}
174
  <label class="opt"><span><b>Auto-update on edit</b><small>Re-runs about a second after you stop typing</small></span><input type="checkbox" id="auto" checked></label>
175
  <button class="btn run" id="go">▶ Run analysis <kbd>Shift ↵</kbd></button></div></div>
176
  <div class="pane res"><div class="rhead"><div><div class="ph" style="margin:0"><span class="n">3</span>Calibrated probabilities</div><p class="sub" style="margin:6px 0 0 34px">Temperature-scaled on held-out data</p></div><div class="acts"><button class="btn t s mono" id="copy">Copy JSON</button><button class="btn t s mono" id="csv">CSV</button></div></div>
 
177
  <div id="out"><div class="empty">No results yet. Choose a scenario and select Run analysis.</div></div>
178
  <details id="pdet" class="hide"><summary>What the model sees</summary><pre id="prompts"></pre></details><details id="rdet" class="hide"><summary>Raw output</summary><pre id="raw"></pre></details></div>
179
  </div></section>
@@ -193,7 +207,7 @@ footer{background:none;font-size:.78rem}
193
  <pre class="code mono">from gradio_client import Client
194
  c = Client("&lt;your-space&gt;")
195
  out = c.predict(state, questions_json, True, api_name="/decide")</pre>
196
- <h3 style="margin-top:32px">Held-out test metrics</h3><div style="overflow:auto"><table class="m" id="metrics"><tbody><tr><td>Loading…</td></tr></tbody></table></div>
197
  </div></section>
198
  </main>
199
  <footer class="mono"><div class="w">jev-fin · inference runtime 0.8b · not financial advice · non-commercial use only</div></footer>
@@ -277,6 +291,39 @@ function primary(t,r,prev){const n=r.type==='noul',p=n?r.noul:r.confidence,c=n?M
277
  $('#csv').onclick=()=>{if(!LAST.length)return;const q=v=>'"'+String(v).replace(/"/g,'""')+'"';
278
  const rows=[['question','type','answer','probability_or_confidence','probabilities'].map(q).join(',')].concat(LAST.map(({q:t,r})=>[t,r.type,r.type==='noul'?(r.noul>=.5?'Yes':'No'):(r.choice||r.level),(r.type==='noul'?r.noul:r.confidence).toFixed(4),J(r.probabilities||{Yes:r.noul,No:1-r.noul})].map(q).join(',')));
279
  const a=document.createElement('a');a.href=URL.createObjectURL(new Blob([rows.join('\n')],{type:'text/csv'}));a.download='jev-fin-results.csv';a.click()};
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
280
  const busy=(b,on)=>{b.disabled=on;b.innerHTML=on?'Running…':(b.id==='go'?'▶ Run analysis <kbd>Shift ↵</kbd>':'Run')};
281
 
282
  const NEWS='Acme Corp cut full-year guidance and the CFO resigned effective immediately.';
@@ -331,8 +378,9 @@ async function analyze(){const state=$('#state').value,out=$('#out'),btn=$('#go'
331
  if(running){pending=true;return}
332
  clearTimeout(T);running=true;out.classList.remove('stale');busy(btn,true);out.innerHTML=skeleton(Object.keys(qs).length);const t0=performance.now();
333
  try{const p=await decide(state,qs,$('#debias').checked),dt=(performance.now()-t0)/1000,keys=Object.keys(qs);
334
- out.innerHTML=sumline(dt,p.device,keys.length)+insight(keys.map(k=>[info[k],p.result[k]]))+primary(info[keys[0]],p.result[keys[0]],prevPlay[info[keys[0]]])+(keys.length>1?`<div class="grid2">${keys.slice(1).map(k=>card(info[k],p.result[k],prevPlay[info[k]])).join('')}</div>`:'');LAST=keys.map(k=>({q:info[k],r:p.result[k]}));
335
  const np={};keys.forEach(k=>np[info[k]]=snap(p.result[k]));prevPlay=np;
 
336
  $('#prompts').textContent=prompts.join('\n\n');$('#raw').textContent=J(p.result,null,2);$('#pdet').classList.remove('hide');$('#rdet').classList.remove('hide')}
337
  catch(err){out.innerHTML=errBox(err.message)}busy(btn,false);running=false;if(pending){pending=false;analyze()}}
338
  $('#go').onclick=analyze;
@@ -364,7 +412,7 @@ async function analyzePortfolio(){const out=$('#pfout'),btn=$('#pfgo');let h;try
364
  busy(btn,true);out.innerHTML=skeleton(4);const t0=performance.now();
365
  try{const p=await decide(J({portfolio:h}),qs,true),dt=(performance.now()-t0)/1000,truth=exactPF(h),np={};
366
  let agree=0;const cards=PFQ.map((x,i)=>{const r=p.result['q'+i],ans=x.type==='noul'?(r.noul>=.5?'Yes':'No'):x.type==='choice'?r.choice:r.level,short=x.q.split(' (')[0].split(', i.e.')[0];np[short]=snap(r);if(ans===truth[i][0])agree++;return card(short,r,prevPf[short],truth[i][1],[truth[i][0],ans===truth[i][0]])}).join('');
367
- prevPf=np;out.innerHTML=sumline(dt,p.device,PFQ.length)+(warn.length?`<div class="rc"><span class="mini warn">Heads-up</span> ${esc(warn.join('; '))}. Answers may be less reliable.</div>`:'')+ins(`<b>Overall read.</b> The model matched the exact calculation on <b>${agree} of ${PFQ.length}</b> checks. ${agree<PFQ.length?'Verify the mismatches with code before relying on them.':'Every answer agrees with the math.'}`)+chart(h)+cards}
368
  catch(err){out.innerHTML=errBox(err.message)}busy(btn,false)}
369
  $('#pfgo').onclick=analyzePortfolio;
370
 
@@ -375,7 +423,7 @@ async function pollStatus(){try{const i=await (await fetch('/api/info')).json(),
375
  if(i.error){dot.className='dot err';tx.textContent='Model failed to load';tx.title=i.error;return}}catch(e){}setTimeout(pollStatus,2500)}
376
  let ml=false;async function loadMetrics(){if(ml)return;ml=true;
377
  try{const d=await (await fetch('/api/metrics')).json();if(!d.rows||!d.rows.length)throw 0;
378
- $('#metrics').innerHTML='<thead><tr><th>Slice</th><th>Test rows</th><th>Accuracy</th><th>ECE raw</th><th>ECE calibrated</th></tr></thead><tbody>'+d.rows.map(r=>`<tr><td>${esc(r.slice)}</td><td>${r.n}</td><td>${(r.acc*100).toFixed(1)}%</td><td>${r.ece_raw.toFixed(3)}</td><td>${r.ece_cal.toFixed(3)}</td></tr>`).join('')+'</tbody>'}
379
  catch(e){ml=false;$('#metrics').innerHTML='<tbody><tr><td>Metrics aren’t available (private repo without HF_TOKEN?).</td></tr></tbody>'}}
380
  renderPF();loadPreset(0,false);pollStatus();
381
  </script></body></html>
 
158
  .ins{background:linear-gradient(var(--surf2),var(--surf2)) padding-box,linear-gradient(120deg,#4d8dff,#2dd4e8,#9b72cb) border-box}
159
  .empty{background:var(--bg);border-color:var(--line)}details{border-color:var(--line)}
160
  footer{background:none;font-size:.78rem}
161
+
162
+ /* ---- charts ---- */
163
+ .tiles{display:grid;grid-template-columns:repeat(4,minmax(0,1fr));gap:10px;margin-bottom:14px}@media(max-width:640px){.tiles{grid-template-columns:repeat(2,1fr)}}
164
+ .tile{background:var(--surf2);border:1px solid var(--line);border-radius:12px;padding:14px}.tile b{display:block;font:500 1.45rem "JetBrains Mono",monospace;color:var(--ink)}.tile span{font-size:.76rem;color:var(--mut)}
165
+ .dn{display:flex;gap:18px;align-items:center;flex-wrap:wrap}.lg{flex:1;min-width:170px}.lg div{font-size:.84rem;margin:5px 0;display:flex;align-items:center;gap:8px}.lg i,.hl i,.lgi i{width:9px;height:9px;border-radius:3px;flex:none;display:inline-block}.lg b{margin-left:auto;font:500 .8rem "JetBrains Mono",monospace;color:var(--mut)}
166
+ .two{display:grid;grid-template-columns:1fr 1fr;gap:22px}@media(max-width:760px){.two{grid-template-columns:1fr}}
167
+ .sm{display:grid;grid-template-columns:minmax(90px,1.2fr) 1.6fr minmax(90px,.9fr);gap:12px;align-items:center;margin:12px 0;font-size:.84rem}.smq{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}.sm b{text-align:right;font-weight:500;font-size:.78rem}
168
+ .smt{position:relative;height:10px;border-radius:99px;background:linear-gradient(90deg,#fb7185,#fbbf24 50%,#34d399)}.smt.c{background:var(--bg);overflow:hidden}.smt.c i{display:block;height:100%;border-radius:99px;background:linear-gradient(90deg,var(--blue),var(--cyan));animation:gr .8s cubic-bezier(.2,.8,.2,1)}
169
+ .smt .mid{position:absolute;left:50%;top:0;bottom:0;width:1px;background:rgba(0,0,0,.35)}.smt .smk{position:absolute;top:-4px;width:4px;height:18px;border-radius:2px;background:#fff;transform:translateX(-2px);box-shadow:0 0 0 2px var(--surf2)}
170
+ .sdq{font-size:.84rem;margin:14px 0 6px}.stk{display:flex;height:14px;border-radius:99px;overflow:hidden;gap:2px;background:var(--bg)}.stk span{display:block;min-width:2px}
171
+ .lgi{display:flex;flex-wrap:wrap;gap:4px 14px;margin-top:8px;font-size:.78rem;color:var(--mut)}.lgi span{display:inline-flex;align-items:center;gap:6px}.lgi b{color:var(--ink);font-weight:500}
172
+ .hl{display:grid;grid-template-columns:12px 1fr 64px 72px;gap:10px;align-items:center;font-size:.84rem;margin:8px 0}.hl em{font-style:normal;text-align:right;color:var(--mut);font-size:.76rem}.hl b{text-align:right;font-weight:500}
173
+ .mrow{display:grid;grid-template-columns:minmax(90px,180px) 1fr 140px;gap:12px;align-items:center;margin:10px 0;font-size:.85rem}.mrow b{text-align:right;font-weight:500;font-size:.78rem}
174
  </style></head><body>
175
  <nav><div class="w"><div class="logo">jev<i>/</i>fin <b class="ver mono">0.8b</b></div>
176
  <button class="nl on" data-v="play">Try it</button><button class="nl" data-v="port">Portfolio lab</button><button class="nl" data-v="about">About</button>
 
187
  <label class="opt"><span><b>Auto-update on edit</b><small>Re-runs about a second after you stop typing</small></span><input type="checkbox" id="auto" checked></label>
188
  <button class="btn run" id="go">▶ Run analysis <kbd>Shift ↵</kbd></button></div></div>
189
  <div class="pane res"><div class="rhead"><div><div class="ph" style="margin:0"><span class="n">3</span>Calibrated probabilities</div><p class="sub" style="margin:6px 0 0 34px">Temperature-scaled on held-out data</p></div><div class="acts"><button class="btn t s mono" id="copy">Copy JSON</button><button class="btn t s mono" id="csv">CSV</button></div></div>
190
+ <div class="seg" id="rv" style="margin-bottom:16px"><button data-v="over" class="on">Overview</button><button data-v="det">Details</button><button data-v="hist">History</button></div>
191
  <div id="out"><div class="empty">No results yet. Choose a scenario and select Run analysis.</div></div>
192
  <details id="pdet" class="hide"><summary>What the model sees</summary><pre id="prompts"></pre></details><details id="rdet" class="hide"><summary>Raw output</summary><pre id="raw"></pre></details></div>
193
  </div></section>
 
207
  <pre class="code mono">from gradio_client import Client
208
  c = Client("&lt;your-space&gt;")
209
  out = c.predict(state, questions_json, True, api_name="/decide")</pre>
210
+ <h3 style="margin-top:32px">Held-out test metrics</h3><div id="mchart" style="margin-bottom:24px"></div><div style="overflow:auto"><table class="m" id="metrics"><tbody><tr><td>Loading…</td></tr></tbody></table></div>
211
  </div></section>
212
  </main>
213
  <footer class="mono"><div class="w">jev-fin · inference runtime 0.8b · not financial advice · non-commercial use only</div></footer>
 
291
  $('#csv').onclick=()=>{if(!LAST.length)return;const q=v=>'"'+String(v).replace(/"/g,'""')+'"';
292
  const rows=[['question','type','answer','probability_or_confidence','probabilities'].map(q).join(',')].concat(LAST.map(({q:t,r})=>[t,r.type,r.type==='noul'?(r.noul>=.5?'Yes':'No'):(r.choice||r.level),(r.type==='noul'?r.noul:r.confidence).toFixed(4),J(r.probabilities||{Yes:r.noul,No:1-r.noul})].map(q).join(',')));
293
  const a=document.createElement('a');a.href=URL.createObjectURL(new Blob([rows.join('\n')],{type:'text/csv'}));a.download='jev-fin-results.csv';a.click()};
294
+ /* ---------- charts and views ---------- */
295
+ let RUN=null,RV='over',HIST=[];
296
+ const cfd=r=>r.type==='noul'?Math.max(r.noul,1-r.noul):r.confidence,pn=(t,b)=>`<div class="rc"><div class="rh"><span class="rq">${t}</span></div>${b}</div>`;
297
+ function donut(parts,txt,sub){const R=46,C=2*Math.PI*R,tot=parts.reduce((a,p)=>a+p[1],0)||1;let off=0;
298
+ const seg=parts.filter(p=>p[1]>0).map(([l,v,c])=>{const len=v/tot*C,o=off;off+=len;return`<circle cx="60" cy="60" r="${R}" fill="none" stroke="${c}" stroke-width="14" stroke-dasharray="${len.toFixed(2)} ${(C-len).toFixed(2)}" stroke-dashoffset="${(-o).toFixed(2)}" transform="rotate(-90 60 60)"><title>${esc(l)}</title></circle>`}).join('');
299
+ return`<svg viewBox="0 0 120 120" width="124" height="124" role="img"><circle cx="60" cy="60" r="${R}" fill="none" stroke="var(--bg)" stroke-width="14"/>${seg}<text x="60" y="60" text-anchor="middle" font-size="19" font-weight="500" fill="var(--ink)" font-family="JetBrains Mono">${txt}</text><text x="60" y="75" text-anchor="middle" font-size="8" fill="var(--mut)">${sub}</text></svg>`}
300
+ function lineChart(series,N){const w=560,h=210,l=36,r=12,t=12,b=26,iw=w-l-r,ih=h-t-b,X=i=>l+(N<2?iw/2:i/(N-1)*iw),Y=v=>t+ih*(1-v/100),f='font-size="9" fill="var(--mut)" font-family="JetBrains Mono"';
301
+ const grid=[0,25,50,75,100].map(v=>`<line x1="${l}" x2="${w-r}" y1="${Y(v)}" y2="${Y(v)}" stroke="var(--line)" ${v===50?'stroke-dasharray="4 4"':''}/><text x="${l-8}" y="${Y(v)+3}" text-anchor="end" ${f}>${v}</text>`).join('');
302
+ const xl=Array.from({length:N},(_,i)=>i%(N>12?2:1)?'':`<text x="${X(i)}" y="${h-8}" text-anchor="middle" ${f}>${i+1}</text>`).join('');
303
+ const lines=series.map(s=>{let d='',pv=false;s.pts.forEach((v,i)=>{if(v==null){pv=false;return}d+=(pv?'L':'M')+X(i).toFixed(1)+' '+Y(v).toFixed(1);pv=true});
304
+ return`<path d="${d}" fill="none" stroke="${s.c}" stroke-width="2" stroke-linejoin="round"/>`+s.pts.map((v,i)=>v==null?'':`<circle cx="${X(i).toFixed(1)}" cy="${Y(v).toFixed(1)}" r="3" fill="${s.c}"><title>${esc(s.q)}: ${v.toFixed(1)}%</title></circle>`).join('')}).join('');
305
+ return`<svg viewBox="0 0 ${w} ${h}" width="100%" role="img" aria-label="Results across runs">${grid}${xl}${lines}</svg>`}
306
+ function overview(it){const cf=it.map(i=>cfd(i.r)),avg=cf.reduce((a,b)=>a+b,0)/cf.length,yes=it.filter(i=>i.r.type==='noul'&&i.r.noul>=.65).length,no=it.filter(i=>i.r.type==='noul'&&i.r.noul<=.35).length,
307
+ hi=cf.filter(c=>c>=.85).length,mo=cf.filter(c=>c>=.65&&c<.85).length,lo=cf.length-hi-mo;
308
+ const tile=(v,l)=>`<div class="tile"><b>${v}</b><span>${l}</span></div>`;
309
+ const tiles=`<div class="tiles">${tile(it.length,'Questions')}${tile(pct0(avg),'Average confidence')}${tile(yes+' / '+no,'Lean Yes / No')}${tile(Math.round(RUN.dt*1000)+' ms','Latency')}</div>`;
310
+ const mix=pn('Conviction mix',`<div class="dn">${donut([['High',hi,GOOD],['Moderate',mo,WARN],['Low',lo,BAD]],pct0(avg),'avg confidence')}<div class="lg"><div><i style="background:${GOOD}"></i>High (85%+)<b>${hi}</b></div><div><i style="background:${WARN}"></i>Moderate (65–85%)<b>${mo}</b></div><div><i style="background:${BAD}"></i>Low (under 65%)<b>${lo}</b></div></div></div>`);
311
+ const map=pn('Signal map',it.map(({q,r})=>{const n=r.type==='noul',p=n?r.noul:r.confidence;
312
+ return`<div class="sm"><span class="smq" title="${esc(q)}">${esc(sh(q))}</span><div class="smt${n?'':' c'}">${n?`<i class="mid"></i><i class="smk" style="left:${(p*100).toFixed(1)}%"></i>`:`<i style="width:${(p*100).toFixed(1)}%"></i>`}</div><b class="mono">${n?pct(p)+' Yes':esc(r.choice||r.level)+' · '+pct0(p)}</b></div>`}).join('')+'<div class="hint">Yes/no rows: marker shows P(Yes), from No on the left to Yes on the right. Other rows: bar shows confidence in the top answer.</div>');
313
+ const oth=it.filter(i=>i.r.type!=='noul'),dist=oth.length?pn('Option distribution',oth.map(({q,r})=>{const e=Object.entries(r.probabilities);return`<div class="sdq">${esc(sh(q))}</div><div class="stk">${e.map(([k,v],i)=>`<span style="width:${(v*100).toFixed(1)}%;background:${PAL[i%PAL.length]}" title="${esc(k)} ${pct(v)}"></span>`).join('')}</div><div class="lgi">${e.map(([k,v],i)=>`<span><i style="background:${PAL[i%PAL.length]}"></i>${esc(k)} <b class="mono">${pct0(v)}</b></span>`).join('')}</div>`}).join('')):'';
314
+ return tiles+insight(it.map(i=>[i.q,i.r]))+mix+map+dist}
315
+ function histView(it){if(HIST.length<2)return`<div class="empty">Run again, or edit a question, to build a history. Each run adds a point.</div>`;
316
+ const N=HIST.length,ser=it.map((i,k)=>({q:i.q,c:PAL[k%PAL.length],pts:HIST.map(h=>h.vals[i.q]??null)}));
317
+ return pn('Results across runs',lineChart(ser,N)+'<div class="hint">x: run number · y: % (yes/no shows P(Yes), other types show confidence)</div>'+ser.map(s=>{const v=s.pts.filter(x=>x!=null),last=v[v.length-1],pv=v.length>1?v[v.length-2]:null;
318
+ return`<div class="hl"><i style="background:${s.c}"></i><span>${esc(sh(s.q))}</span><b class="mono">${last.toFixed(1)}%</b><em class="mono">${pv==null?'':(last-pv>=0?'+':'')+(last-pv).toFixed(1)+' pp'}</em></div>`}).join(''))}
319
+ function renderPlay(){if(!RUN)return;const {dt,dev,items,n}=RUN;sumline(dt,dev,n);$('#out').classList.remove('stale');
320
+ $('#out').innerHTML=RV==='over'?overview(items):RV==='hist'?histView(items):primary(items[0].q,items[0].r,items[0].prev)+(items.length>1?`<div class="grid2">${items.slice(1).map(i=>card(i.q,i.r,i.prev)).join('')}</div>`:'')}
321
+ $('#rv').addEventListener('click',e=>{const b=e.target.closest('button');if(!b)return;RV=b.dataset.v;$$('#rv button').forEach(x=>x.classList.toggle('on',x===b));renderPlay()});
322
+ function pfCharts(h){const tw=h.reduce((a,x)=>a+x.weight_pct,0)||1,sec={};h.forEach(x=>sec[x.sector]=(sec[x.sector]||0)+x.weight_pct);
323
+ const nm=Object.keys(sec).sort(),col=Object.fromEntries(nm.map((n,i)=>[n,PAL[i%PAL.length]])),ct=h.map(x=>x.weight_pct*x.annual_vol_pct),cs=ct.reduce((a,b)=>a+b,0)||1;
324
+ return pn('Allocation and risk contribution',`<div class="two"><div class="dn">${donut(nm.map(n=>[n,sec[n],col[n]]),h.length,'holdings')}<div class="lg">${nm.map(n=>`<div><i style="background:${col[n]}"></i>${esc(n)}<b>${(sec[n]/tw*100).toFixed(0)}%</b></div>`).join('')}</div></div><div><div class="lbl">Share of weighted volatility</div>${bars(h.map((x,i)=>[x.ticker,ct[i]/cs,col[x.sector]]))}</div></div>`)}
325
+ function metricChart(rows){const mx=Math.max(...rows.map(x=>Math.max(x.ece_raw,x.ece_cal)))||1;
326
+ $('#mchart').innerHTML='<div class="lbl">Calibration error by slice (lower is better)</div>'+rows.map(r=>`<div class="mrow"><span>${esc(r.slice)}</span><div><div class="track"><i style="width:${r.ece_raw/mx*100}%;background:${BAD}"></i></div><div class="track" style="margin-top:4px"><i style="width:${r.ece_cal/mx*100}%;background:var(--cyan)"></i></div></div><b class="mono">${r.ece_raw.toFixed(3)} → ${r.ece_cal.toFixed(3)}</b></div>`).join('')+'<div class="hint">Red: raw · Cyan: calibrated</div>'}
327
  const busy=(b,on)=>{b.disabled=on;b.innerHTML=on?'Running…':(b.id==='go'?'▶ Run analysis <kbd>Shift ↵</kbd>':'Run')};
328
 
329
  const NEWS='Acme Corp cut full-year guidance and the CFO resigned effective immediately.';
 
378
  if(running){pending=true;return}
379
  clearTimeout(T);running=true;out.classList.remove('stale');busy(btn,true);out.innerHTML=skeleton(Object.keys(qs).length);const t0=performance.now();
380
  try{const p=await decide(state,qs,$('#debias').checked),dt=(performance.now()-t0)/1000,keys=Object.keys(qs);
381
+ const items=keys.map(k=>({q:info[k],r:p.result[k],prev:prevPlay[info[k]]}));RUN={dt,dev:p.device,items,n:keys.length};LAST=items.map(({q,r})=>({q,r}));
382
  const np={};keys.forEach(k=>np[info[k]]=snap(p.result[k]));prevPlay=np;
383
+ HIST.push({vals:Object.fromEntries(items.map(i=>[i.q,i.r.type==='noul'?i.r.noul*100:i.r.confidence*100]))});if(HIST.length>20)HIST.shift();renderPlay();
384
  $('#prompts').textContent=prompts.join('\n\n');$('#raw').textContent=J(p.result,null,2);$('#pdet').classList.remove('hide');$('#rdet').classList.remove('hide')}
385
  catch(err){out.innerHTML=errBox(err.message)}busy(btn,false);running=false;if(pending){pending=false;analyze()}}
386
  $('#go').onclick=analyze;
 
412
  busy(btn,true);out.innerHTML=skeleton(4);const t0=performance.now();
413
  try{const p=await decide(J({portfolio:h}),qs,true),dt=(performance.now()-t0)/1000,truth=exactPF(h),np={};
414
  let agree=0;const cards=PFQ.map((x,i)=>{const r=p.result['q'+i],ans=x.type==='noul'?(r.noul>=.5?'Yes':'No'):x.type==='choice'?r.choice:r.level,short=x.q.split(' (')[0].split(', i.e.')[0];np[short]=snap(r);if(ans===truth[i][0])agree++;return card(short,r,prevPf[short],truth[i][1],[truth[i][0],ans===truth[i][0]])}).join('');
415
+ prevPf=np;out.innerHTML=sumline(dt,p.device,PFQ.length)+(warn.length?`<div class="rc"><span class="mini warn">Heads-up</span> ${esc(warn.join('; '))}. Answers may be less reliable.</div>`:'')+ins(`<b>Overall read.</b> The model matched the exact calculation on <b>${agree} of ${PFQ.length}</b> checks. ${agree<PFQ.length?'Verify the mismatches with code before relying on them.':'Every answer agrees with the math.'}`)+pfCharts(h)+chart(h)+cards}
416
  catch(err){out.innerHTML=errBox(err.message)}busy(btn,false)}
417
  $('#pfgo').onclick=analyzePortfolio;
418
 
 
423
  if(i.error){dot.className='dot err';tx.textContent='Model failed to load';tx.title=i.error;return}}catch(e){}setTimeout(pollStatus,2500)}
424
  let ml=false;async function loadMetrics(){if(ml)return;ml=true;
425
  try{const d=await (await fetch('/api/metrics')).json();if(!d.rows||!d.rows.length)throw 0;
426
+ $('#metrics').innerHTML='<thead><tr><th>Slice</th><th>Test rows</th><th>Accuracy</th><th>ECE raw</th><th>ECE calibrated</th></tr></thead><tbody>'+d.rows.map(r=>`<tr><td>${esc(r.slice)}</td><td>${r.n}</td><td>${(r.acc*100).toFixed(1)}%</td><td>${r.ece_raw.toFixed(3)}</td><td>${r.ece_cal.toFixed(3)}</td></tr>`).join('')+'</tbody>';metricChart(d.rows)}
427
  catch(e){ml=false;$('#metrics').innerHTML='<tbody><tr><td>Metrics aren’t available (private repo without HF_TOKEN?).</td></tr></tbody>'}}
428
  renderPF();loadPreset(0,false);pollStatus();
429
  </script></body></html>