zchx's picture
update model name
fe35093 verified
Raw History Blame Contribute Delete
6.68 kB
const $ = s => document.querySelector(s);
const tasks = {
pancreas: {tag:'PANCREAS / TYPE 1 DIABETES',title:'The changing architecture of an islet.',description:'Explore H&E regions and predicted cellular organization across non-diabetic, autoantibody-positive and T1D donors. Morph2Mol connects islet remodeling with local immune programs.',metric:'96.4 million',unit:'cells analyzed across 75 pancreatic donors',image:'pancreas',caption:'Figure 3 · islet remodeling and immune programs in type 1 diabetes',note:'Downstream cell annotations use a separate pancreas-specific analysis.'},
lung: {tag:'LUNG / IDIOPATHIC PULMONARY FIBROSIS',title:'Locate the programs of fibrosis.',description:'Spatial domains reveal tissue organization, while reconstructed expression resolves extracellular-matrix and collagen-related programs within the fibrotic region.',metric:'282 / 293',unit:'predicted DEGs match the measured direction',image:'lung',caption:'Lung spatial domains and molecular programs',note:''},
crc: {tag:'COLORECTAL CANCER / LVI',title:'Connect local programs to patient-level outcomes.',description:'Tumor-edge and stromal epithelial programs complement clinical variables for lymphovascular invasion prediction in a held-out patient cohort.',metric:'0.630 → 0.856',unit:'test AUROC · clinical → clinical + Morph2Mol',image:'crc',caption:'Regional programs and held-out prediction',note:'313 development and 55 test patients. Not a clinical diagnostic service.'}
};
let active='pancreas',zoom=1;
function selectTask(key){active=key;const t=tasks[key];for(const b of document.querySelectorAll('[data-task]')){b.setAttribute('aria-selected',String(b.dataset.task===key));b.tabIndex=b.dataset.task===key?0:-1;}$('#application').setAttribute('aria-labelledby','tab-'+key);$('#task-tag').textContent=t.tag;$('#task-title').textContent=t.title;$('#task-description').textContent=t.description;$('#task-metric').replaceChildren(document.createTextNode(t.metric));const unit=document.createElement('span');unit.textContent=t.unit;$('#task-metric').append(unit);$('#task-note').textContent=t.note;$('#task-caption').textContent=t.caption;const image=$('#task-image');image.classList.add('loading');image.onload=()=>image.classList.remove('loading');image.src=`assets/${t.image}.webp`;image.alt=t.caption;}
for(const b of document.querySelectorAll('[data-task]')){b.onclick=()=>selectTask(b.dataset.task);b.onkeydown=e=>{const keys=Object.keys(tasks),i=keys.indexOf(active);if(['ArrowLeft','ArrowRight','Home','End'].includes(e.key)){e.preventDefault();const k=e.key==='Home'?keys[0]:e.key==='End'?keys.at(-1):keys[(i+(e.key==='ArrowRight'?1:2))%3];selectTask(k);$('#tab-'+k).focus();}};}
function openFigure(name,title,note=''){zoom=1;$('#viewer-image').style.width='100%';$('#viewer-image').src=`assets/${name}.webp`;$('#viewer-image').alt=title;$('#viewer-title').textContent=title;$('#viewer-note').textContent=note;$('#viewer').showModal();}
$('#view-figure').onclick=$('#figure-button').onclick=()=>openFigure(tasks[active].image,tasks[active].caption,tasks[active].note);
for(const b of document.querySelectorAll('[data-figure]'))b.onclick=()=>openFigure(b.dataset.figure,b.textContent.replace(' ↗',''),'Original Morph2Mol manuscript figure.');
$('#close-viewer').onclick=()=>$('#viewer').close();$('#viewer').onclick=e=>{if(e.target===$('#viewer'))$('#viewer').close();};
function setZoom(n){zoom=Math.min(4,Math.max(.5,n));$('#viewer-image').style.width=zoom*100+'%';}
$('#zoom-in').onclick=()=>setZoom(zoom+.25);$('#zoom-out').onclick=()=>setZoom(zoom-.25);$('#zoom-reset').onclick=()=>setZoom(1);
$('#citation').onclick=async()=>{const bib='@article{luo2026morph2mol,\n title={Morph2Mol: A Foundation Model for Predicting Single-Cell Spatial Transcriptome from Histology Images},\n author={Luo, Xin and Zeng, Haoxuan and others},\n year={2026},\n eprint={2608.08366},\n archivePrefix={arXiv}\n}';try{await navigator.clipboard.writeText(bib);$('#copy-status').textContent='BibTeX copied.';}catch{$('#copy-status').textContent=bib;}};
async function connect(){const status=$('#service-status');status.textContent='Checking inference service…';$('#retry').disabled=true;try{const r=await fetch('https://huggingface.co/api/spaces/zchx/Morph2Mol-demo',{signal:AbortSignal.timeout(12000)});if(!r.ok)throw Error(r.status===404?'The GPU Space has not been deployed yet.':`Service check returned ${r.status}.`);const s=await r.json();if(s.runtime?.stage!=='RUNNING')throw Error(`GPU service: ${(s.runtime?.stage||'starting').toLowerCase().replaceAll('_',' ')}. Please check again shortly.`);const host=s.host;if(!host||!/^https:\/\/[a-z0-9-]+\.hf\.space\/?$/i.test(host))throw Error('The inference service did not provide a valid app URL.');const iframe=document.createElement('iframe');iframe.src=host;iframe.title='Morph2Mol H&E inference workbench';iframe.allow='clipboard-write';iframe.onload=()=>{status.textContent='GPU workbench connected · queued inference';};status.textContent='Loading GPU workbench…';$('#space-container').replaceChildren(iframe);}catch(e){status.textContent='GPU workbench unavailable';$('#service-message').textContent=e.message+' You can still explore all research figures above.';}finally{if($('#retry'))$('#retry').disabled=false;}}
$('#retry').onclick=connect;selectTask('pancreas');connect();
const compare=$('#compare'),range=$('#compare-range');let swept=false;
range.oninput=()=>{swept=true;compare.style.setProperty('--pos',range.value+'%');};
// One gentle sweep reveals that the hero image is interactive.
if(!matchMedia('(prefers-reduced-motion: reduce)').matches){const start=performance.now();const sweep=now=>{if(swept)return;const t=Math.min(1,(now-start)/2600),v=50+28*Math.sin(t*Math.PI*2)*(1-t);compare.style.setProperty('--pos',v+'%');range.value=v;if(t<1)requestAnimationFrame(sweep);};setTimeout(()=>requestAnimationFrame(sweep),700);}
for(const t of Object.values(tasks))new Image().src=`assets/${t.image}.webp`;
// Download through a blob so hosts that redirect assets to a CDN preserve the filename.
for (const link of document.querySelectorAll('a[download]')) {
link.addEventListener('click', async event => {
event.preventDefault();
try {
const response = await fetch(link.href);
if (!response.ok) throw new Error('Demo download unavailable');
const url = URL.createObjectURL(await response.blob());
const download = document.createElement('a');
download.href = url; download.download = link.download;
document.body.append(download); download.click(); download.remove();
setTimeout(() => URL.revokeObjectURL(url), 10000);
} catch { window.location.assign(link.href); }
});
}