Fire all score requests in parallel via Promise.all
Browse files- assets/index-COGfPvML.js +1 -0
- index.html +1 -1
assets/index-COGfPvML.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
(function(){const c=document.createElement("link").relList;if(c&&c.supports&&c.supports("modulepreload"))return;for(const t of document.querySelectorAll('link[rel="modulepreload"]'))o(t);new MutationObserver(t=>{for(const s of t)if(s.type==="childList")for(const a of s.addedNodes)a.tagName==="LINK"&&a.rel==="modulepreload"&&o(a)}).observe(document,{childList:!0,subtree:!0});function n(t){const s={};return t.integrity&&(s.integrity=t.integrity),t.referrerPolicy&&(s.referrerPolicy=t.referrerPolicy),t.crossOrigin==="use-credentials"?s.credentials="include":t.crossOrigin==="anonymous"?s.credentials="omit":s.credentials="same-origin",s}function o(t){if(t.ep)return;t.ep=!0;const s=n(t);fetch(t.href,s)}})();const I="onnx-community/Qwen3-Reranker-0.6B-ONNX",$="Given a web search query, retrieve relevant passages that answer the query",N=["Paris is the capital and largest city of France, located in northern France.","Berlin is the capital city of Germany.","France is a country in Western Europe known for its wine, cuisine, and art.","The Eiffel Tower is a famous landmark located in Paris, France."];let S=0;const M=document.getElementById("status-bar"),R=document.getElementById("status-text"),b=document.getElementById("progress-bar-wrap"),F=document.getElementById("progress-bar"),i=document.getElementById("rank-btn"),v=document.getElementById("docs-list"),w=document.getElementById("results-header"),g=document.getElementById("dtype-select"),h=document.getElementById("query-input");let E=x();function x(){const e=new Worker(new URL(""+new URL("worker-Cv6xZSLB.js",import.meta.url).href,import.meta.url),{type:"module"});return e.addEventListener("message",O),e}const f=new Map;function O({data:e}){const{type:c}=e;if(c==="progress"){const n=e.progress!=null?Math.round(e.progress):null;m("loading",`${e.file??"model"} — ${n!=null?n+"%":"…"}`,n);return}if(c==="ready"){document.getElementById("runtime-info").textContent=`dtype: ${e.dtype}`,m("ready",`Model ready · ${I}`),i.disabled=!1,g.disabled=!1;return}if(c==="load_error"){m("error",`Failed to load: ${e.message}`),g.disabled=!1;return}if(c==="scored"){const n=f.get(e.id);n&&(n.resolve(e.score),f.delete(e.id));return}if(c==="score_error"){const n=f.get(e.id);n&&(n.reject(new Error(e.message)),f.delete(e.id));return}}function A(e,c,n,o){return new Promise((t,s)=>{f.set(e,{resolve:t,reject:s}),E.postMessage({type:"score",id:e,query:c,doc:n,instruction:o})})}function m(e,c,n=null){M.className=e,R.textContent=c,n!=null?(b.classList.add("visible"),F.style.width=`${n}%`):b.classList.remove("visible")}function C(e){e.style.height="auto",e.style.height=Math.min(e.scrollHeight,128)+"px"}h.addEventListener("input",()=>C(h));function B(e=""){const c=String(++S),n=document.createElement("div");n.className="doc-card",n.dataset.id=c,n.style.animationDelay=`${Math.min((S-1)*30,100)}ms`;const o=document.createElement("span");o.className="doc-index",o.textContent=c.padStart(2,"0");const t=document.createElement("textarea");t.className="doc-text",t.rows=2,t.placeholder="Paste a document or passage…",t.value=e,t.addEventListener("input",()=>C(t));const s=document.createElement("div");s.className="doc-score-wrap";const a=document.createElement("span");a.className="doc-score-num",a.textContent="—";const u=document.createElement("div");u.className="doc-score-bar-wrap";const l=document.createElement("div");l.className="doc-score-bar",u.appendChild(l),s.appendChild(a),s.appendChild(u),n.appendChild(o),n.appendChild(t),n.appendChild(s),v.appendChild(n)}let k=!1;function D(){k&&(i.textContent="↺ Re-rank")}N.forEach(e=>B(e));document.getElementById("add-doc-btn").addEventListener("click",()=>{B(),D()});document.getElementById("clear-btn").addEventListener("click",()=>{document.querySelectorAll(".doc-card").forEach(e=>{e.className="doc-card",e.querySelector(".doc-score-num").textContent="—",e.querySelector(".doc-score-bar").style.width="0%"}),w.classList.remove("visible")});function P(e,c,n){const o=performance.now(),t=a=>(a*100).toFixed(1)+"%";function s(a){const u=Math.min((a-o)/600,1),l=1-Math.pow(1-u,3);e.textContent=t(l*n),c.style.width=`${l*n*100}%`,u<1?requestAnimationFrame(s):e.textContent=t(n)}requestAnimationFrame(s)}function T(e,c){const n=new Map(e.map(o=>[o.dataset.id,o.getBoundingClientRect().top]));c.forEach(o=>{const t=v.querySelector(`[data-id="${CSS.escape(o)}"]`);t&&v.appendChild(t)}),e.forEach(o=>{const t=n.get(o.dataset.id)-o.getBoundingClientRect().top;Math.abs(t)>1&&(o.style.transform=`translateY(${t}px)`,o.style.transition="none",requestAnimationFrame(()=>{o.classList.add("flipping"),o.style.transform="translateY(0)",setTimeout(()=>{o.classList.remove("flipping"),o.style.transition=""},500)}))})}async function L(){const e=h.value.trim(),c=document.getElementById("instruction-input").value.trim()||$;if(!e){h.focus();return}document.querySelectorAll(".doc-card.needs-rank").forEach(r=>r.classList.remove("needs-rank"));const n=[...document.querySelectorAll(".doc-card")],o=n.map(r=>({id:r.dataset.id,text:r.querySelector(".doc-text").value.trim(),card:r})),t=o.filter(r=>r.text);if(!t.length)return;i.disabled=!0,i.classList.add("running"),i.textContent="⟳ Ranking…",t.forEach(({card:r})=>{r.classList.add("computing"),r.querySelector(".doc-score-num").textContent="⟳"});let s=0;m("loading",`Scoring 0 / ${t.length}…`,0);const a=await Promise.all(t.map(({id:r,text:p,card:d})=>A(r,e,p,c).then(y=>(s++,m("loading",`Scoring ${s} / ${t.length}…`,s/t.length*100),d.classList.remove("computing"),P(d.querySelector(".doc-score-num"),d.querySelector(".doc-score-bar"),y),{id:r,score:y,card:d})).catch(y=>(s++,console.error("Scoring failed for doc",r,y),d.classList.remove("computing"),d.querySelector(".doc-score-num").textContent="err",{id:r,score:-1,card:d}))));a.sort((r,p)=>p.score-r.score),a.forEach(({card:r},p)=>{r.className="doc-card",p<3&&r.classList.add(`ranked-${p+1}`)});const u=o.filter(r=>!r.text).map(r=>r.id);T(n,[...a.map(r=>r.id),...u]);const l=o.filter(r=>r.card.querySelector(".doc-text").value.trim()&&!t.some(d=>d.id===r.id));l.forEach(({card:r})=>r.classList.add("needs-rank")),l.length>0?m("ready",`Scored ${t.length} · ${l.length} unscored — hit Rank again ↺`):m("ready",`Scored ${t.length} document${t.length!==1?"s":""} · model ready`),w.classList.add("visible"),k=!0,i.disabled=!1,i.classList.remove("running"),i.textContent="↺ Re-rank"}i.addEventListener("click",L);function q(){const e=g.value;g.disabled=!0,i.disabled=!0,m("loading",`Downloading model (${e})…`,0),E.postMessage({type:"load",dtype:e})}g.addEventListener("change",()=>{i.removeEventListener("click",L),E.terminate(),E=x(),i.addEventListener("click",L),q()});q();
|
index.html
CHANGED
|
@@ -7,7 +7,7 @@
|
|
| 7 |
<link rel="preconnect" href="https://fonts.googleapis.com">
|
| 8 |
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
| 9 |
<link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:ital,wght@0,300;0,400;0,600;0,700;1,300&family=Syne:wght@700;800;900&display=swap" rel="stylesheet">
|
| 10 |
-
<script type="module" crossorigin src="./assets/index-
|
| 11 |
<link rel="stylesheet" crossorigin href="./assets/index-DRl0_D0u.css">
|
| 12 |
</head>
|
| 13 |
<body>
|
|
|
|
| 7 |
<link rel="preconnect" href="https://fonts.googleapis.com">
|
| 8 |
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
| 9 |
<link href="https://fonts.googleapis.com/css2?family=JetBrains+Mono:ital,wght@0,300;0,400;0,600;0,700;1,300&family=Syne:wght@700;800;900&display=swap" rel="stylesheet">
|
| 10 |
+
<script type="module" crossorigin src="./assets/index-COGfPvML.js"></script>
|
| 11 |
<link rel="stylesheet" crossorigin href="./assets/index-DRl0_D0u.css">
|
| 12 |
</head>
|
| 13 |
<body>
|