Spaces:
Sleeping
Sleeping
Placebo Deploy commited on
Commit ·
e7d708e
1
Parent(s): d7fb8f2
Feature: Add Medical Tooltips and Secure Clinical PDF Export
Browse files12 unmodified lines1314151617181026 unmodified lines10451046104710481049105010511 unmodified line105310541055105610571058105989 unmodified lines114911501151115211531154115512 unmodified lines<link rel="icon" type="image/png" sizes="16x16" href="/static/favicon-16x16.png"><link rel="shortcut icon" href="/static/favicon.ico"><link rel="manifest" href="/static/site.webmanifest"><style>/* Anti-Copy and Anti-Select Protection */body {1026 unmodified lines});// Manually update the view since sources arrive last in the stream nowresponseText.innerHTML = queryHTML + badgeHTML + DOMPurify.sanitize(marked.parse(fullAnswer));window.scrollTo({ top: document.body.scrollHeight, behavior: 'smooth' });} else if (json.type === 'start_answer') {1 unmodified linefullAnswer = ""; // Reset buffer} else if (json.type === 'content') {fullAnswer += json.data;responseText.innerHTML = queryHTML + badgeHTML + DOMPurify.sanitize(marked.parse(fullAnswer));window.scrollTo({ top: document.body.scrollHeight, behavior: 'smooth' });}} catch (e) { }89 unmodified lines}});}sendBtn.addEventListener('click', handleSend);chatInput.addEventListener('keypress', (e) => { if (e.key === 'Enter') handleSend(); });</script>12 unmodified lines13141516171819201026 unmodified lines1047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821 unmodified line1084108510861087108810891090109189 unmodified lines11811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312 unmodified lines<link rel="icon" type="image/png" sizes="16x16" href="/static/favicon-16x16.png"><link rel="shortcut icon" href="/static/favicon.ico"><link rel="manifest" href="/static/site.webmanifest"><!-- html2pdf for Secure PDF Generation --><script src="https://cdnjs.cloudflare.com/ajax/libs/html2pdf.js/0.10.1/html2pdf.bundle.min.js"></script><style>/* Anti-Copy and Anti-Select Protection */body {1026 unmodified lines});// Manually update the view since sources arrive last in the stream nowconst finalHtml = DOMPurify.sanitize(applyMedicalTooltips(marked.parse(fullAnswer)), { ADD_ATTR: ['data-tooltip'] });responseText.innerHTML = queryHTML + badgeHTML + finalHtml;// Add PDF Export Buttonconst pdfBtn = document.createElement('button');pdfBtn.className = 'export-pdf-btn';pdfBtn.innerHTML = `<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"></path><polyline points="7 10 12 15 17 10"></polyline><line x1="12" y1="15" x2="12" y2="3"></line></svg>Export Clinical Report`;pdfBtn.onclick = () => {pdfBtn.innerHTML = "Generating PDF...";const opt = {margin: 1,filename: 'Clinical_Report.pdf',image: { type: 'jpeg', quality: 0.98 },html2canvas: { scale: 2, useCORS: true },jsPDF: { unit: 'in', format: 'letter', orientation: 'portrait' }};const elementToExport = responseText.cloneNode(true);elementToExport.removeChild(elementToExport.lastChild); // Remove the button from the PDFelementToExport.style.color = '#000'; // Make text black for PDFelementToExport.style.background = '#fff';elementToExport.style.padding = '20px';html2pdf().set(opt).from(elementToExport).save().then(() => {pdfBtn.innerHTML = `<svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"></path><polyline points="7 10 12 15 17 10"></polyline><line x1="12" y1="15" x2="12" y2="3"></line></svg> Export Clinical Report`;});};responseText.appendChild(pdfBtn);window.scrollTo({ top: document.body.scrollHeight, behavior: 'smooth' });} else if (json.type === 'start_answer') {1 unmodified linefullAnswer = ""; // Reset buffer} else if (json.type === 'content') {fullAnswer += json.data;const parsedHtml = DOMPurify.sanitize(applyMedicalTooltips(marked.parse(fullAnswer)), { ADD_ATTR: ['data-tooltip'] });responseText.innerHTML = queryHTML + badgeHTML + parsedHtml;window.scrollTo({ top: document.body.scrollHeight, behavior: 'smooth' });}} catch (e) { }89 unmodified lines}});}</script><script src="https://cdnjs.cloudflare.com/ajax/libs/html2pdf.js/0.10.1/html2pdf.bundle.min.js"></script><style>.medical-tooltip { border-bottom: 1px dotted var(--primary); cursor: help; position: relative; }.medical-tooltip:hover::after { content: attr(data-tooltip); position: absolute; bottom: 100%; left: 0; background: #333; color: #fff; padding: 5px; border-radius: 4px; width: 200px; z-index: 1000; font-size: 12px; }.export-pdf-btn { display: flex; align-items: center; gap: 8px; margin-top: 15px; background: var(--primary); color: white; border: none; padding: 10px 15px; border-radius: 6px; cursor: pointer; }</style><script>const medicalDictionary = {"myocardial infarction": "A heart attack; tissue death of the heart muscle due to lack of blood supply.","hypertension": "High blood pressure, which can lead to heart disease and stroke.","tachycardia": "A rapid heart rate, usually defined as greater than 100 beats per minute.","ischemia": "An inadequate blood supply to an organ or part of the body, especially the heart muscles.","hyperlipidemia": "High levels of fat particles (lipids) in the blood.","arrhythmia": "An irregular heartbeat or abnormal heart rhythm."};function applyMedicalTooltips(html) {let modifiedHtml = html;for (const [term, definition] of Object.entries(medicalDictionary)) {const regex = new RegExp(`\\b(${term})\\b`, 'gi');modifiedHtml = modifiedHtml.replace(regex, `<span class="medical-tooltip" data-tooltip="${definition}">$1</span>`);}return modifiedHtml;}const sendBtn = document.getElementById('send-btn');sendBtn.addEventListener('click', handleSend);chatInput.addEventListener('keypress', (e) => { if (e.key === 'Enter') handleSend(); });</script>
src/static/index.html+60-2