Spaces:
Running
Running
Update index.html
Browse files- index.html +11 -111
index.html
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
<!DOCTYPE html>
|
| 2 |
<html lang="en">
|
| 3 |
<head>
|
|
@@ -148,7 +149,7 @@ body{
|
|
| 148 |
#settingsBtn:hover{transform:rotate(20deg)scale(1.15)}
|
| 149 |
|
| 150 |
/* ───────── header ───────── */
|
| 151 |
-
.header{text-align:center;margin-bottom:34px;padding-bottom:18px;border-bottom:1px solid rgba(0,0,0,.05
|
| 152 |
h1{font-family:'Libre Baskerville',serif;margin:0;font-size:30px;letter-spacing:.5px}
|
| 153 |
.subtitle{font-family:'PT Mono',monospace;font-size:14px;color:#666;margin-top:6px;letter-spacing:1px}
|
| 154 |
|
|
@@ -276,27 +277,6 @@ th{font-weight:600}
|
|
| 276 |
margin-top: 8px; /* Add some spacing */
|
| 277 |
}
|
| 278 |
|
| 279 |
-
/* Copy button styles */
|
| 280 |
-
.copy-btn{
|
| 281 |
-
display:inline-flex;
|
| 282 |
-
align-items:center;
|
| 283 |
-
justify-content:center;
|
| 284 |
-
gap:6px;
|
| 285 |
-
font-family:'PT Mono',monospace;
|
| 286 |
-
font-size:13px;
|
| 287 |
-
padding:6px 8px;
|
| 288 |
-
margin-left:8px;
|
| 289 |
-
background: #efefef;
|
| 290 |
-
color:var(--paper-text);
|
| 291 |
-
border:1px solid var(--code-border);
|
| 292 |
-
border-radius:6px;
|
| 293 |
-
cursor:pointer;
|
| 294 |
-
user-select:none;
|
| 295 |
-
}
|
| 296 |
-
.copy-btn.small{ padding:4px 6px; font-size:12px; border-radius:5px; }
|
| 297 |
-
.copy-btn:active{ transform: translateY(1px); }
|
| 298 |
-
body.dark .copy-btn{ background:#444; color:var(--paper-text); border-color:var(--code-border); }
|
| 299 |
-
|
| 300 |
/* responsive & print */
|
| 301 |
@media(max-width:768px){
|
| 302 |
.container{margin:20px 16px;padding:28px}
|
|
@@ -387,13 +367,9 @@ function processContent(text){
|
|
| 387 |
content.innerHTML = html;
|
| 388 |
|
| 389 |
if(window.MathJax?.typesetPromise){
|
| 390 |
-
|
| 391 |
-
.
|
| 392 |
-
|
| 393 |
-
}else{
|
| 394 |
-
hideProcessing();
|
| 395 |
-
return Promise.resolve();
|
| 396 |
-
}
|
| 397 |
}
|
| 398 |
|
| 399 |
/* ======= Image to Base64 converter ======= */
|
|
@@ -437,7 +413,7 @@ async function ocrImage(base64Image) {
|
|
| 437 |
messages: [
|
| 438 |
{
|
| 439 |
role: 'system',
|
| 440 |
-
content: '
|
| 441 |
},
|
| 442 |
{
|
| 443 |
role: 'user',
|
|
@@ -467,104 +443,28 @@ async function ocrImage(base64Image) {
|
|
| 467 |
}
|
| 468 |
}
|
| 469 |
|
| 470 |
-
/* ======= UI Helpers for Streaming
|
| 471 |
-
|
| 472 |
-
/* Copy helper with fallback and small "Copied!" feedback */
|
| 473 |
-
async function copyTextToClipboard(text, btn) {
|
| 474 |
-
if (!btn) { // make a dummy if none supplied
|
| 475 |
-
btn = document.createElement('button');
|
| 476 |
-
}
|
| 477 |
-
const origLabel = btn.textContent;
|
| 478 |
-
try {
|
| 479 |
-
if (navigator.clipboard && navigator.clipboard.writeText) {
|
| 480 |
-
await navigator.clipboard.writeText(text);
|
| 481 |
-
} else {
|
| 482 |
-
const ta = document.createElement('textarea');
|
| 483 |
-
ta.value = text;
|
| 484 |
-
ta.setAttribute('readonly', '');
|
| 485 |
-
ta.style.position = 'absolute';
|
| 486 |
-
ta.style.left = '-9999px';
|
| 487 |
-
document.body.appendChild(ta);
|
| 488 |
-
ta.select();
|
| 489 |
-
document.execCommand('copy');
|
| 490 |
-
document.body.removeChild(ta);
|
| 491 |
-
}
|
| 492 |
-
btn.textContent = 'Copied!';
|
| 493 |
-
setTimeout(()=>{ btn.textContent = origLabel; }, 1100);
|
| 494 |
-
} catch (e) {
|
| 495 |
-
console.error('Copy failed', e);
|
| 496 |
-
alert('Copy failed: ' + e.message);
|
| 497 |
-
}
|
| 498 |
-
}
|
| 499 |
-
|
| 500 |
function beginStreamingUI(question){
|
| 501 |
// Show a lightweight, non-MathJax view while the model streams
|
| 502 |
content.innerHTML = `
|
| 503 |
<div>
|
| 504 |
-
<p><strong>Question</strong
|
| 505 |
-
<button class="copy-btn small" id="copyQBtn" title="Copy question">📋</button>
|
| 506 |
-
</p>
|
| 507 |
<div class="mono-stream" id="qStream"></div>
|
| 508 |
<hr style="opacity:.35; margin: 20px 0;">
|
| 509 |
-
<p><strong>Answer</strong
|
| 510 |
-
<button class="copy-btn small" id="copyABtn" title="Copy answer">📋</button>
|
| 511 |
-
</p>
|
| 512 |
<div class="mono-stream" id="aStream">(generating...)</div>
|
| 513 |
</div>`;
|
| 514 |
const qEl = document.getElementById('qStream');
|
| 515 |
const aEl = document.getElementById('aStream');
|
| 516 |
qEl.textContent = question; // plain text now; pretty render later
|
| 517 |
aEl.textContent = ''; // clear "(generating...)"
|
| 518 |
-
|
| 519 |
-
// attach copy handlers
|
| 520 |
-
const qBtn = document.getElementById('copyQBtn');
|
| 521 |
-
const aBtn = document.getElementById('copyABtn');
|
| 522 |
-
if (qBtn) qBtn.addEventListener('click', ()=> copyTextToClipboard(question, qBtn));
|
| 523 |
-
if (aBtn) aBtn.addEventListener('click', ()=> copyTextToClipboard(aEl.textContent, aBtn));
|
| 524 |
-
|
| 525 |
-
return { qEl, aEl, qBtn, aBtn };
|
| 526 |
-
}
|
| 527 |
-
|
| 528 |
-
/* After final render, add copy buttons next to the rendered Question/Answer
|
| 529 |
-
(copies the original plain-text question/answer passed in) */
|
| 530 |
-
function addCopyButtonsToRenderedContent(question, answer){
|
| 531 |
-
// Find paragraphs containing <strong>Question</strong> or <strong>Answer</strong>
|
| 532 |
-
const pEls = content.querySelectorAll('p');
|
| 533 |
-
pEls.forEach(p => {
|
| 534 |
-
const st = p.querySelector('strong');
|
| 535 |
-
if(!st) return;
|
| 536 |
-
const label = st.textContent.replace(':','').trim().toLowerCase();
|
| 537 |
-
if(label.startsWith('question')){
|
| 538 |
-
// remove existing copy if present
|
| 539 |
-
const existing = p.querySelector('.copy-btn');
|
| 540 |
-
if(existing) existing.remove();
|
| 541 |
-
const btn = document.createElement('button');
|
| 542 |
-
btn.className = 'copy-btn small';
|
| 543 |
-
btn.title = 'Copy question text';
|
| 544 |
-
btn.innerHTML = '📋';
|
| 545 |
-
btn.addEventListener('click', ()=> copyTextToClipboard(question, btn));
|
| 546 |
-
// insert right after the strong label
|
| 547 |
-
st.after(btn);
|
| 548 |
-
} else if(label.startsWith('answer')){
|
| 549 |
-
const existing = p.querySelector('.copy-btn');
|
| 550 |
-
if(existing) existing.remove();
|
| 551 |
-
const btn = document.createElement('button');
|
| 552 |
-
btn.className = 'copy-btn small';
|
| 553 |
-
btn.title = 'Copy answer text';
|
| 554 |
-
btn.innerHTML = '📋';
|
| 555 |
-
btn.addEventListener('click', ()=> copyTextToClipboard(answer, btn));
|
| 556 |
-
st.after(btn);
|
| 557 |
-
}
|
| 558 |
-
});
|
| 559 |
}
|
| 560 |
|
| 561 |
function finalizeStreaming(question, fullAnswer){
|
| 562 |
// One single heavy render (Markdown + MathJax) at the end
|
| 563 |
const formatted = `**Question**: ${question}\n\n**Answer**: ${fullAnswer}`;
|
| 564 |
-
processContent(formatted)
|
| 565 |
-
// After render + MathJax finished, add copy buttons that copy the *raw* texts
|
| 566 |
-
addCopyButtonsToRenderedContent(question, fullAnswer);
|
| 567 |
-
});
|
| 568 |
}
|
| 569 |
|
| 570 |
/* ======= Solve with Cerebras API (Streaming Optimization) ======= */
|
|
|
|
| 1 |
+
|
| 2 |
<!DOCTYPE html>
|
| 3 |
<html lang="en">
|
| 4 |
<head>
|
|
|
|
| 149 |
#settingsBtn:hover{transform:rotate(20deg)scale(1.15)}
|
| 150 |
|
| 151 |
/* ───────── header ───────── */
|
| 152 |
+
.header{text-align:center;margin-bottom:34px;padding-bottom:18px;border-bottom:1px solid rgba(0,0,0,.05)}
|
| 153 |
h1{font-family:'Libre Baskerville',serif;margin:0;font-size:30px;letter-spacing:.5px}
|
| 154 |
.subtitle{font-family:'PT Mono',monospace;font-size:14px;color:#666;margin-top:6px;letter-spacing:1px}
|
| 155 |
|
|
|
|
| 277 |
margin-top: 8px; /* Add some spacing */
|
| 278 |
}
|
| 279 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 280 |
/* responsive & print */
|
| 281 |
@media(max-width:768px){
|
| 282 |
.container{margin:20px 16px;padding:28px}
|
|
|
|
| 367 |
content.innerHTML = html;
|
| 368 |
|
| 369 |
if(window.MathJax?.typesetPromise){
|
| 370 |
+
MathJax.typesetPromise([content]).then(hideProcessing)
|
| 371 |
+
.catch(e=>{console.error('MathJax error:',e);hideProcessing()});
|
| 372 |
+
}else{hideProcessing()}
|
|
|
|
|
|
|
|
|
|
|
|
|
| 373 |
}
|
| 374 |
|
| 375 |
/* ======= Image to Base64 converter ======= */
|
|
|
|
| 413 |
messages: [
|
| 414 |
{
|
| 415 |
role: 'system',
|
| 416 |
+
content: 'GIVE AS TEXT WITH LATEX like $this$ or $$this$$. DO NOT USE ITEMIZE. DO NOT SOLVE THE QUESTION. DO NOT OUTPUT ANYTHING BUT THE FORMAT OF THE QUESTION.'
|
| 417 |
},
|
| 418 |
{
|
| 419 |
role: 'user',
|
|
|
|
| 443 |
}
|
| 444 |
}
|
| 445 |
|
| 446 |
+
/* ======= UI Helpers for Streaming ======= */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 447 |
function beginStreamingUI(question){
|
| 448 |
// Show a lightweight, non-MathJax view while the model streams
|
| 449 |
content.innerHTML = `
|
| 450 |
<div>
|
| 451 |
+
<p><strong>Question</strong>:</p>
|
|
|
|
|
|
|
| 452 |
<div class="mono-stream" id="qStream"></div>
|
| 453 |
<hr style="opacity:.35; margin: 20px 0;">
|
| 454 |
+
<p><strong>Answer</strong>:</p>
|
|
|
|
|
|
|
| 455 |
<div class="mono-stream" id="aStream">(generating...)</div>
|
| 456 |
</div>`;
|
| 457 |
const qEl = document.getElementById('qStream');
|
| 458 |
const aEl = document.getElementById('aStream');
|
| 459 |
qEl.textContent = question; // plain text now; pretty render later
|
| 460 |
aEl.textContent = ''; // clear "(generating...)"
|
| 461 |
+
return { qEl, aEl };
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 462 |
}
|
| 463 |
|
| 464 |
function finalizeStreaming(question, fullAnswer){
|
| 465 |
// One single heavy render (Markdown + MathJax) at the end
|
| 466 |
const formatted = `**Question**: ${question}\n\n**Answer**: ${fullAnswer}`;
|
| 467 |
+
processContent(formatted); // processContent calls hideProcessing after MathJax
|
|
|
|
|
|
|
|
|
|
| 468 |
}
|
| 469 |
|
| 470 |
/* ======= Solve with Cerebras API (Streaming Optimization) ======= */
|