Spaces:
Running on T4
Running on T4
serving: manual load + GenerationMixin + use_cache=False + streaming
Browse files- index.html +16 -6
index.html
CHANGED
|
@@ -134,14 +134,24 @@ const out=document.getElementById('out'), btn=document.getElementById('go'), sta
|
|
| 134 |
async function gen(){
|
| 135 |
const prompt=document.getElementById('prompt').value.trim();
|
| 136 |
if(!prompt){return}
|
| 137 |
-
btn.disabled=true; out.textContent='
|
|
|
|
| 138 |
try{
|
| 139 |
-
const r=await fetch('/api/
|
| 140 |
body:JSON.stringify({prompt:prompt,max_new_tokens:200,temperature:0.7})});
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 145 |
}catch(e){ out.textContent='Request failed: '+e; stat.textContent=''; }
|
| 146 |
btn.disabled=false;
|
| 147 |
}
|
|
|
|
| 134 |
async function gen(){
|
| 135 |
const prompt=document.getElementById('prompt').value.trim();
|
| 136 |
if(!prompt){return}
|
| 137 |
+
btn.disabled=true; out.textContent=''; stat.textContent='generating (model may be loading on first call)…';
|
| 138 |
+
const t0=performance.now();
|
| 139 |
try{
|
| 140 |
+
const r=await fetch('/api/stream',{method:'POST',headers:{'Content-Type':'application/json'},
|
| 141 |
body:JSON.stringify({prompt:prompt,max_new_tokens:200,temperature:0.7})});
|
| 142 |
+
if(!r.body){ out.textContent=await r.text(); stat.textContent=''; btn.disabled=false; return; }
|
| 143 |
+
const reader=r.body.getReader(), dec=new TextDecoder();
|
| 144 |
+
let text='';
|
| 145 |
+
while(true){
|
| 146 |
+
const {done,value}=await reader.read();
|
| 147 |
+
if(done) break;
|
| 148 |
+
text+=dec.decode(value,{stream:true});
|
| 149 |
+
out.textContent=text;
|
| 150 |
+
stat.textContent=`streaming… ${((performance.now()-t0)/1000).toFixed(1)}s`;
|
| 151 |
+
}
|
| 152 |
+
const secs=((performance.now()-t0)/1000).toFixed(1);
|
| 153 |
+
out.textContent=text||'(empty)';
|
| 154 |
+
stat.textContent = r.status>=400 ? '' : `done · ${secs}s · live token streaming`;
|
| 155 |
}catch(e){ out.textContent='Request failed: '+e; stat.textContent=''; }
|
| 156 |
btn.disabled=false;
|
| 157 |
}
|