Spaces:
Running
Running
Download index.html from chenying-claude/streamtext: direct link, hf CLI and curl.
- Browser
- Download file 6.87 kB
-
https://huggingface.co/spaces/chenying-claude/streamtext/resolve/main/index.html
- Command line
-
hf download hf://spaces/chenying-claude/streamtext/index.html
-
curl -L -o index.html https://huggingface.co/spaces/chenying-claude/streamtext/resolve/main/index.html
6.87 kB
| <html lang="zh-Hant"> | |
| <head> | |
| <meta charset="utf-8"> | |
| <meta name="viewport" content="width=device-width,initial-scale=1"> | |
| <title>streamtext — Not typed. Generated.</title> | |
| <link rel="preconnect" href="https://fonts.googleapis.com"> | |
| <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;600&family=Noto+Serif:ital@0;1&display=swap" rel="stylesheet"> | |
| <style> | |
| :root{--bg:#1f2a36;--fg:#eeeae2} | |
| *{box-sizing:border-box} | |
| html,body{margin:0;height:100%;background:var(--bg);color:var(--fg); | |
| font-family:"Noto Serif SC","Noto Serif",Georgia,serif;transition:background .6s,color .6s} | |
| #stage{min-height:78vh;display:flex;flex-direction:column;justify-content:center;align-items:center;cursor:pointer} | |
| #main{width:72vw;max-width:1100px;text-align:center;font-size:clamp(28px,4.6vw,68px);line-height:1.45; | |
| white-space:pre-wrap;word-break:normal;overflow-wrap:anywhere} | |
| #main.static{opacity:0;transition:opacity .9s ease} | |
| #main.static.on{opacity:1} | |
| #sub{width:72vw;max-width:1100px;text-align:center;font-size:clamp(13px,1.9vw,28px);margin-top:1.1em; | |
| opacity:0;transition:opacity .9s ease;font-style:italic} | |
| #sub.on{opacity:.72} | |
| #panel{position:fixed;left:0;right:0;bottom:0;padding:10px 14px;display:flex;flex-wrap:wrap;gap:8px; | |
| align-items:center;justify-content:center;font-family:system-ui,sans-serif;font-size:13px; | |
| background:rgba(0,0,0,.18);backdrop-filter:blur(6px)} | |
| #panel input,#panel select,#panel textarea,#panel button{font:inherit;color:inherit;background:rgba(255,255,255,.08); | |
| border:1px solid rgba(255,255,255,.25);border-radius:6px;padding:5px 8px} | |
| #panel textarea{width:min(420px,90vw);height:2.4em;resize:vertical} | |
| #panel input[type=color]{padding:0;width:34px;height:30px} | |
| #panel label{opacity:.8} | |
| #tag{position:fixed;top:12px;right:16px;font-size:12px;opacity:.45;font-family:system-ui,sans-serif} | |
| #hide{opacity:.6} | |
| </style> | |
| </head> | |
| <body> | |
| <div id="tag">Not typed. Generated. · chenying-claude</div> | |
| <div id="stage" title="click to replay"> | |
| <div id="main"></div> | |
| <div id="sub"></div> | |
| </div> | |
| <div id="panel"> | |
| <textarea id="t">這裡從來沒有玻璃。</textarea> | |
| <input id="s" size="28" value="Ici, il n'y a jamais eu de vitre." placeholder="subtitle (optional)"> | |
| <input id="bg" type="color" value="#1f2a36" title="background"> | |
| <label>mode <select id="mode"><option>stream</option><option>static</option></select></label> | |
| <label>pace <input id="pace" type="range" min="0.05" max="0.35" step="0.01" value="0.12"></label> | |
| <label>seed <input id="seed" type="number" value="218" style="width:70px"></label> | |
| <button id="go">generate</button> | |
| <button id="hide">hide panel</button> | |
| </div> | |
| <script> | |
| // ---- seeded RNG (mulberry32) ---- | |
| function makeRng(seed){let a=seed>>>0;return function(){a|=0;a=a+0x6D2B79F5|0; | |
| let t=Math.imul(a^a>>>15,1|a);t=t+Math.imul(t^t>>>7,61|t)^t;return((t^t>>>14)>>>0)/4294967296;}} | |
| const CJK=/[\u3400-\u9fff\uf900-\ufaff\u3040-\u30ff]/; | |
| const HAN=/[\u3400-\u9fff]/; | |
| const WS=/\s/; | |
| const PUNCT=new Set(Array.from(`,。、!?;:…—「」『』(),.!?;:)"'»«`)); | |
| const END=new Set(Array.from('。!?.!?…')); | |
| const MID=new Set(Array.from(',、;:,;:—')); | |
| function splitWord(w,R){ | |
| let core=w.trim(), trail=''; | |
| while(core && PUNCT.has(core.slice(-1))){trail=core.slice(-1)+trail;core=core.slice(0,-1);} | |
| const lead=w.slice(0,w.length-w.trimStart().length); | |
| const cps=Array.from(core); | |
| if(cps.length<=6 || R()<0.5) return [lead+core+trail]; | |
| const cut=3+Math.floor(R()*(cps.length-2-3+1)); | |
| return [lead+cps.slice(0,cut).join(''), cps.slice(cut).join('')+trail]; | |
| } | |
| function chunk(text,R){ | |
| const a=Array.from(text), n=a.length, out=[]; let i=0; | |
| const wordEnd=k=>{while(k<n && !WS.test(a[k]) && !HAN.test(a[k])) k++; return k;}; | |
| while(i<n){ | |
| const ch=a[i]; | |
| if(CJK.test(ch)){ | |
| const r=R(); const k=r<0.45?1:(r<0.87?2:3); | |
| let j=i; while(j<n && j-i<k && CJK.test(a[j])) j++; | |
| out.push(a.slice(i,j).join('')); i=j; | |
| }else if(WS.test(ch)){ | |
| let j=i; while(j<n && WS.test(a[j])) j++; | |
| const k=wordEnd(j); | |
| out.push(...splitWord(a.slice(i,k).join(''),R)); i=k; | |
| }else if(PUNCT.has(ch)){ | |
| if(out.length) out[out.length-1]+=ch; else out.push(ch); i++; | |
| }else{ | |
| const k=wordEnd(i); | |
| out.push(...splitWord(a.slice(i,k).join(''),R)); i=k; | |
| } | |
| } | |
| const fixed=[]; | |
| for(const c of out){const s=c.trim(); | |
| if(fixed.length && s && Array.from(s).every(x=>PUNCT.has(x))) fixed[fixed.length-1]+=c; else fixed.push(c);} | |
| return fixed; | |
| } | |
| function lognorm(R,mu,sigma){const u1=1-R(),u2=R(); | |
| return Math.exp(mu+sigma*Math.sqrt(-2*Math.log(u1))*Math.cos(2*Math.PI*u2));} | |
| function timings(chunks,R,base=0.12,sigma=0.55){ | |
| let t=0,burst=0; const out=[]; | |
| chunks.forEach((c,idx)=>{ | |
| let dt; | |
| if(burst>0){dt=0.012+R()*0.018;burst--;} | |
| else{dt=lognorm(R,Math.log(base),sigma); if(R()<0.12) burst=2+Math.floor(R()*3);} | |
| if(idx>0){const prev=chunks[idx-1].trimEnd(); const last=prev.slice(-1); | |
| if(END.has(last)) dt+=0.35+R()*0.35; else if(MID.has(last)) dt+=0.12+R()*0.16; | |
| if(R()<0.05) dt+=0.2+R()*0.25;} | |
| t+= idx>0?dt:0.25; out.push(t); | |
| }); | |
| return out; | |
| } | |
| function autoFg(hex){const h=hex.replace('#','');const r=parseInt(h.slice(0,2),16),g=parseInt(h.slice(2,4),16),b=parseInt(h.slice(4,6),16); | |
| return (0.2126*r+0.7152*g+0.0722*b)<140?'#eeeae2':'#1c1c1e';} | |
| const $=id=>document.getElementById(id); | |
| let timers=[]; | |
| function clear(){timers.forEach(clearTimeout);timers=[];} | |
| function play(){ | |
| clear(); | |
| const text=$('t').value, sub=$('s').value.trim(), mode=$('mode').value; | |
| const seed=parseInt($('seed').value)||0, pace=parseFloat($('pace').value); | |
| const bg=$('bg').value; | |
| document.documentElement.style.setProperty('--bg',bg); | |
| document.documentElement.style.setProperty('--fg',autoFg(bg)); | |
| const main=$('main'), subEl=$('sub'); | |
| main.textContent=''; main.className=''; subEl.className=''; subEl.textContent=sub; | |
| let tDone; | |
| if(mode==='stream'){ | |
| const R=makeRng(seed); const cs=chunk(text,R); const ts=timings(cs,R,pace); | |
| cs.forEach((c,k)=>timers.push(setTimeout(()=>{main.textContent+=c;},ts[k]*1000))); | |
| tDone=ts[ts.length-1]||0; | |
| }else{ | |
| main.textContent=text; main.className='static'; | |
| timers.push(setTimeout(()=>main.classList.add('on'),250)); | |
| tDone=0.25+0.9; | |
| } | |
| if(sub) timers.push(setTimeout(()=>subEl.classList.add('on'),(tDone+0.8)*1000)); | |
| } | |
| $('go').onclick=play; $('stage').onclick=play; | |
| $('bg').oninput=()=>{document.documentElement.style.setProperty('--bg',$('bg').value); | |
| document.documentElement.style.setProperty('--fg',autoFg($('bg').value));}; | |
| $('hide').onclick=e=>{e.stopPropagation();$('panel').style.display='none';}; | |
| document.addEventListener('keydown',e=>{if(e.key==='Escape')$('panel').style.display='flex';}); | |
| play(); | |
| </script> | |
| </body> | |
| </html> | |