Spaces:
Sleeping
Sleeping
Enlarge source image with responsive uncropped layout
Browse files- app.py +1 -1
- index.html +63 -0
app.py
CHANGED
|
@@ -62,7 +62,7 @@ def asset(path):
|
|
| 62 |
return FileResponse(p, headers={'Cache-Control': 'no-store'})
|
| 63 |
|
| 64 |
@app.get('/')
|
| 65 |
-
def home(): return FileResponse(ROOT / '
|
| 66 |
|
| 67 |
@app.get('/api/study')
|
| 68 |
def study(pid: str):
|
|
|
|
| 62 |
return FileResponse(p, headers={'Cache-Control': 'no-store'})
|
| 63 |
|
| 64 |
@app.get('/')
|
| 65 |
+
def home(): return FileResponse(ROOT / 'index.html', headers={'Cache-Control': 'no-store'})
|
| 66 |
|
| 67 |
@app.get('/api/study')
|
| 68 |
def study(pid: str):
|
index.html
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!doctype html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
|
| 4 |
+
<title>Comparative Evaluation of Image Editing</title>
|
| 5 |
+
<style>
|
| 6 |
+
:root{--ink:#243750;--muted:#66768b;--accent:#407a9e;--line:#dce5ee;--surface:#f3f7fa;--pink:#f8edf2}*{box-sizing:border-box}body{margin:0;background:var(--surface);color:var(--ink);font:14px/1.6 system-ui,-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif}button{font:inherit;cursor:pointer}button:focus-visible,img:focus-visible,a:focus-visible{outline:3px solid #61a5cb;outline-offset:3px}header{min-height:74px;padding:18px max(24px,calc((100vw - 1380px)/2));background:white;border-bottom:1px solid var(--line);display:flex;justify-content:space-between;align-items:center;gap:24px}.brand{font-size:16px;font-weight:650;letter-spacing:.1px}.caption{font-size:12px;color:var(--muted);font-weight:400;margin-top:2px}.badge{font-size:12px;color:var(--muted);white-space:nowrap}.shell{max-width:1380px;margin:32px auto 48px;padding:0 24px}.intro{display:flex;justify-content:space-between;align-items:flex-start;gap:30px;margin-bottom:22px}h1{font-size:28px;line-height:1.3;letter-spacing:-.6px;margin:0 0 9px}h2{font-size:20px;line-height:1.4;margin:0 0 10px}h3{font-size:16px;margin:0 0 8px}.sub{color:var(--muted);margin:0;max-width:850px}.progress{min-width:140px;font-size:12px;color:var(--muted);padding-top:4px}.track{height:5px;background:#dce6ee;margin-top:10px;border-radius:5px}.track span{display:block;height:100%;background:#76b4d6;border-radius:5px}.workspace{display:grid;grid-template-columns:minmax(0,1fr) 310px;gap:24px}.source{background:white;border:1px solid var(--line);border-radius:12px;padding:16px;display:flex;gap:22px;align-items:center;margin-bottom:18px}.source img{width:360px;height:270px;flex-shrink:0;object-fit:contain;background:#eef1f4;border-radius:6px;cursor:zoom-in}.kicker{font-size:11px;color:#617b93;font-weight:650;letter-spacing:.8px;text-transform:uppercase}.instruction{font-size:17px;font-weight:550;line-height:1.6;margin:7px 0}.tiny{font-size:12px;color:var(--muted)}.sectionline{display:flex;justify-content:space-between;align-items:center;gap:14px;font-size:13px;margin:18px 0 10px}.grid{display:grid;grid-template-columns:1fr 1fr;gap:16px}.card{background:white;border:1px solid var(--line);border-radius:10px;overflow:hidden}.cardtop{display:flex;justify-content:space-between;align-items:center;padding:9px 13px}.letter{background:#eaf3f9;border-radius:5px;padding:2px 10px;font-weight:650}.zoom,.textbutton{border:0;background:transparent;color:var(--accent);font-size:12px;padding:4px}.card img{display:block;width:100%;height:300px;object-fit:contain;object-position:center;background:#eef1f4;cursor:zoom-in}.panel{align-self:start;border:1px solid var(--line);background:white;border-radius:12px;padding:22px;position:sticky;top:20px}.panel h2{font-size:18px}.question{padding:19px 0;border-bottom:1px solid #e9eef3}.qtitle{display:flex;align-items:center;gap:8px;font-size:13px;font-weight:650}.num{font-size:11px;color:#7390a9}.question p{font-size:12px;line-height:1.65;color:var(--muted);margin:9px 0 13px}.choices{display:flex;gap:8px}.choice{flex:1;border:1px solid #dce5ee;border-radius:6px;background:white;height:38px;color:var(--ink);font-weight:650}.choice:hover{background:#edf6fb}.choice[aria-pressed=true]{border-color:#a36983;background:var(--pink);color:#81465f;box-shadow:0 0 0 1px #a36983}.submit{border:0;border-radius:7px;background:var(--ink);color:white;padding:13px 22px;font-weight:600}.panel .submit{width:100%;margin-top:20px}.submit:disabled{background:#dce5ee;color:#8191a4;cursor:default}.status{font-size:12px;line-height:1.6;min-height:38px;color:var(--muted);margin-top:10px}.footer{display:flex;justify-content:space-between;gap:20px;color:var(--muted);font-size:11px;margin-top:26px}.demo{background:#e7f2f8;color:#4b6c84;font-size:12px;padding:10px 14px;border-radius:7px;margin-bottom:20px}.done{text-align:center;padding:70px 20px;background:white;border:1px solid var(--line);border-radius:12px}.done h2{font-size:26px}.guide{background:white;border:1px solid var(--line);border-radius:12px;padding:28px;margin-bottom:20px}.guide p{max-width:1000px}.criteria{display:grid;grid-template-columns:repeat(3,1fr);gap:22px;margin:25px 0}.criterion{border-top:3px solid #abcddd;padding-top:14px}.criterion p{color:var(--muted);font-size:13px;margin:0}.notice{padding:12px 15px;background:#f2f6f9;border-left:3px solid #94b8cf;font-size:13px}.example{border-top:1px solid var(--line);padding-top:22px;margin-top:24px}.example-grid{display:grid;grid-template-columns:repeat(3,1fr);gap:16px}.example figure{margin:0}.example img{width:100%;height:230px;object-fit:contain;background:#eef1f4;display:block;cursor:zoom-in;border-radius:5px}.example figcaption{font-size:12px;color:var(--muted);margin-top:7px}.example figcaption strong{display:block;color:var(--ink);font-size:13px;margin-bottom:3px}.guide-actions{display:flex;justify-content:space-between;align-items:center;gap:24px;margin-top:26px}.guide-actions p{font-size:12px;color:var(--muted);margin:0}.guide-actions .submit{white-space:nowrap}dialog{border:0;border-radius:10px;padding:14px;max-width:96vw;background:white}dialog::backdrop{background:#182b42d6}dialog img{display:block;max-width:90vw;max-height:82vh;object-fit:contain}dialog button{display:block;margin:0 0 10px auto;border:0;background:#eaf2f7;border-radius:5px;padding:7px 13px}.example-instruction{font-weight:550;margin-bottom:15px}.example-note{font-size:12px;color:var(--muted)}[hidden]{display:none!important}@media(max-width:1050px){.card img{height:250px}}@media(max-width:900px){.workspace{grid-template-columns:1fr}.panel{position:static}.criteria{grid-template-columns:1fr}.card img{height:280px}.example img{height:180px}}@media(max-width:600px){header{padding:14px 18px}.badge{display:none}.shell{padding:0 14px;margin-top:23px}h1{font-size:24px}.intro{gap:16px}.progress{min-width:80px}.source{gap:14px;padding:12px;align-items:flex-start}.source{flex-direction:column}.source img{width:100%;height:260px}.instruction{font-size:14px}.grid{gap:10px}.card img{height:190px}.guide{padding:20px}.example-grid{grid-template-columns:1fr}.example img{height:240px}.guide-actions{align-items:stretch;flex-direction:column}.footer{flex-direction:column;gap:4px}.sectionline{align-items:flex-start}.brand{font-size:14px}}
|
| 7 |
+
</style>
|
| 8 |
+
<header><div class="brand">Comparative Evaluation of Image Editing<div class="caption">Human preference study</div></div><span class="badge">Anonymous model comparison</span></header>
|
| 9 |
+
<main class="shell"><div class="intro"><div><h1 id="heading">Evaluation Guidelines</h1><p class="sub" id="subtitle">Please review the evaluation criteria and examples before starting.</p></div><div class="progress" id="progress" hidden><span id="count"></span><div class="track"><span id="bar"></span></div></div></div><div id="demo" class="demo" hidden>Preview mode. Responses are not saved to the server.</div><div id="content"></div><footer class="footer"><span>No names or email addresses are requested.</span><span>Model identities are concealed during evaluation.</span></footer></main>
|
| 10 |
+
<dialog id="lightbox"><button id="close">Close</button><img alt="Enlarged image" id="large"></dialog>
|
| 11 |
+
<script src="/static/outbox.js"></script>
|
| 12 |
+
<script>
|
| 13 |
+
const $=s=>document.querySelector(s), KEYS=['instruction','physics','overall'];
|
| 14 |
+
const questions=[['Instruction Following','Which result best implements the requested edit while preserving unrelated content?'],['Physical Plausibility','Which result is most consistent with real-world physical behavior and the consequences of the edit?'],['Overall Preference','Considering instruction following, physical plausibility, and visual quality, which result do you prefer overall?']];
|
| 15 |
+
let pid=localStorage.getItem('study_pid')||crypto.randomUUID();localStorage.setItem('study_pid',pid);
|
| 16 |
+
let config,state,storageKey,answers={},busy=false,tutorials=[],outbox;
|
| 17 |
+
function media(slot){return `/api/media/${pid}/${config.samples[state.index].id}/${slot}`}
|
| 18 |
+
function enlarge(src){$('#large').src=src;$('#lightbox').showModal()}$('#close').onclick=()=>$('#lightbox').close();
|
| 19 |
+
function persist(){localStorage.setItem(storageKey,JSON.stringify(state))}
|
| 20 |
+
function bindZoom(){document.querySelectorAll('img[data-zoom]').forEach(el=>{el.onclick=()=>enlarge(el.src);el.onkeydown=e=>{if(e.key==='Enter'||e.key===' '){e.preventDefault();enlarge(el.src)}}})}
|
| 21 |
+
function showGuidelines(){
|
| 22 |
+
$('#heading').textContent='Evaluation Guidelines';$('#subtitle').textContent='Please review the criteria and examples before starting.';$('#progress').hidden=true;$('#demo').hidden=!config.demo;
|
| 23 |
+
$('#content').innerHTML=`<section class="guide"><h2>Study procedure</h2><p>For each of the ${config.samples.length} items, compare the source image and editing instruction with four edited results. Select one result for each criterion. You may select different results for different criteria.</p><div class="criteria"><section class="criterion"><h3>1. Instruction Following</h3><p>Assess whether the requested change has been made correctly. Content unrelated to the instruction should be preserved unless a change is a necessary consequence of the edit.</p></section><section class="criterion"><h3>2. Physical Plausibility</h3><p>Assess whether the edited scene is physically coherent. Consider effects such as gravity, support, contact, liquid behavior, shadows, and reflections where relevant. Photorealistic appearance alone does not guarantee physical plausibility.</p></section><section class="criterion"><h3>3. Overall Preference</h3><p>Assess the result as a whole, considering the requested edit, physical plausibility, preservation of the source scene, and visual quality.</p></section></div><div class="notice">The labels A–D are assigned independently for each item and participant. They do not identify a particular model or indicate a correct answer. Select the result that best satisfies each criterion.</div><div id="tutorials"></div><div class="guide-actions"><p>Click any image to inspect it at a larger size. The examples are for guidance only and are not part of the questionnaire.</p><button id="start" class="submit">${state.index>0?'Continue Evaluation':'Start Evaluation'}</button></div></section>`;
|
| 24 |
+
const holder=$('#tutorials');tutorials.forEach(t=>{const section=document.createElement('section');section.className='example';const title=document.createElement('h3');title.textContent=t.title;section.append(title);const instruction=document.createElement('p');instruction.className='example-instruction';instruction.textContent=`Instruction: “${t.instruction}”`;section.append(instruction);const grid=document.createElement('div');grid.className='example-grid';t.images.forEach(i=>{const f=document.createElement('figure'),im=document.createElement('img'),cap=document.createElement('figcaption'),label=document.createElement('strong');im.src=i.src;im.alt=i.label;im.dataset.zoom='1';im.tabIndex=0;label.textContent=i.label;cap.append(label,document.createTextNode(i.caption||''));f.append(im,cap);grid.append(f)});section.append(grid);const note=document.createElement('p');note.className='example-note';note.textContent=t.note||'';section.append(note);holder.append(section)});bindZoom();$('#start').onclick=()=>{state.guidelinesReviewed=true;persist();render();window.scrollTo(0,0)};
|
| 25 |
+
}
|
| 26 |
+
function render(){
|
| 27 |
+
if(!state.guidelinesReviewed){showGuidelines();return}answers=state.pending?.answers||{};let n=config.samples.length;$('#heading').textContent='Image Editing Evaluation';$('#subtitle').textContent='Compare the four results and select one response for each criterion.';$('#progress').hidden=false;$('#count').textContent=`Item ${Math.min(state.index+1,n)} of ${n}`;$('#bar').style.width=`${state.index/n*100}%`;$('#demo').hidden=!config.demo;
|
| 28 |
+
if(state.index>=n){$('#bar').style.width='100%';renderCompletion();return}
|
| 29 |
+
$('#content').innerHTML=`<div class="workspace"><section><div class="source"><img id="sourceimg" alt="Source image" tabindex="0"><div><div class="kicker">Editing instruction</div><div class="instruction" id="instruction"></div><span class="tiny">Source image shown on the left.</span></div></div><div class="sectionline"><b>Edited results</b><span class="tiny">Click an image to enlarge. Images are shown without cropping.</span></div><div class="grid">${[...'ABCD'].map(l=>`<article class="card"><div class="cardtop"><span class="letter">${l}</span><button class="zoom" data-slot="${l}" aria-label="Enlarge result ${l}">Enlarge</button></div><img data-slot="${l}" alt="Edited result ${l}" tabindex="0"></article>`).join('')}</div></section><aside class="panel"><h2>Evaluation</h2><p class="tiny">Select one result for each criterion.</p><button class="textbutton" id="guidelines">Review evaluation guidelines</button>${questions.map((q,i)=>`<div class="question"><div class="qtitle"><span class="num">${i+1}.</span>${q[0]}</div><p>${q[1]}</p><div class="choices" role="group" aria-label="${q[0]}">${[...'ABCD'].map(l=>`<button class="choice" data-key="${KEYS[i]}" data-value="${l}" aria-pressed="false" aria-label="${q[0]}: result ${l}">${l}</button>`).join('')}</div></div>`).join('')}<button id="submit" class="submit" disabled>Continue</button><div id="status" class="status" role="status">Please answer all three questions.</div></aside></div>`;
|
| 30 |
+
$('#instruction').textContent=config.samples[state.index].instruction;$('#sourceimg').src=media('input');$('#sourceimg').onclick=()=>enlarge(media('input'));$('#sourceimg').onkeydown=e=>{if(e.key==='Enter')enlarge(media('input'))};document.querySelectorAll('[data-slot]').forEach(el=>{let src=media(el.dataset.slot);if(el.tagName==='IMG')el.src=src;el.onclick=()=>enlarge(src);el.onkeydown=e=>{if(e.key==='Enter')enlarge(src)}});
|
| 31 |
+
document.querySelectorAll('.choice').forEach(el=>{el.onclick=()=>{if(busy||state.pending)return;answers[el.dataset.key]=el.dataset.value;update()}});$('#submit').onclick=submit;$('#guidelines').onclick=()=>{if(!busy)showGuidelines()};update();
|
| 32 |
+
}
|
| 33 |
+
function update(){document.querySelectorAll('.choice').forEach(el=>{el.setAttribute('aria-pressed',answers[el.dataset.key]===el.dataset.value);el.disabled=busy||!!state.pending});$('#submit').disabled=busy||KEYS.some(k=>!answers[k]);if(state.pending)$('#status').textContent='This response has not been confirmed. Select Save and Continue to retry.'}
|
| 34 |
+
function renderSyncStatus(){
|
| 35 |
+
if(!outbox||!config)return;
|
| 36 |
+
let el=$('#syncstatus');if(!el){el=document.createElement('div');el.id='syncstatus';el.className='notice';el.setAttribute('role','status');$('#demo').after(el)}
|
| 37 |
+
const q=outbox.summary();
|
| 38 |
+
el.textContent=config.demo?'Preview mode: responses are not stored on the server.':q.pending?`${q.acknowledged} response(s) confirmed on the server; ${q.pending} saved on this browser and awaiting upload. You may continue evaluating. Keep this page open until all responses are confirmed.`:`${q.acknowledged} response(s) confirmed on the server.`;
|
| 39 |
+
if(!config.demo&&q.pending){const retry=document.createElement('button');retry.className='textbutton';retry.textContent='Retry upload';retry.onclick=()=>outbox.retryNow();el.append(document.createTextNode(' '),retry)}
|
| 40 |
+
if(state&&state.guidelinesReviewed&&state.index>=config.samples.length)renderCompletion();
|
| 41 |
+
}
|
| 42 |
+
function renderCompletion(){
|
| 43 |
+
const q=outbox.summary();const complete=q.pending===0;
|
| 44 |
+
$('#content').innerHTML=`<div class="done"><h2>${complete?'Evaluation Complete':'Finalizing Responses'}</h2><p class="sub" style="margin:auto">${config.demo?'The preview is complete. No responses were saved to the server.':complete?'All responses have been confirmed on the server. Thank you for participating. You may now close this window.':`${q.pending} response(s) are stored on this browser but have not yet been confirmed on the server. Please keep this page open. Uploads are retried automatically; do not clear browser data.`}</p>${!complete?'<button class="submit" style="margin-top:24px" id="retryfinal">Retry upload</button>':''}</div>`;
|
| 45 |
+
if(!complete)$('#retryfinal').onclick=()=>outbox.retryNow();
|
| 46 |
+
}
|
| 47 |
+
async function submit(){
|
| 48 |
+
if(busy)return;busy=true;update();
|
| 49 |
+
try{
|
| 50 |
+
const body=state.pending||{participant_id:pid,sample_id:config.samples[state.index].id,version:config.version,answers:{...answers},submitted_at:new Date().toISOString()};
|
| 51 |
+
await outbox.enqueue(body); // synchronous persistent browser write, not remote acknowledgement
|
| 52 |
+
state.index++;delete state.pending;persist();busy=false;render();renderSyncStatus();window.scrollTo(0,0);
|
| 53 |
+
}catch(e){busy=false;update();if(e.code==='ALREADY_RECORDED'){$('#status').textContent=e.message;$('#submit').textContent='Continue with the recorded response';$('#submit').onclick=()=>{state.index++;persist();render();renderSyncStatus()};return}$('#status').textContent='The response could not be saved on this browser. Please do not close this page or clear browser data. Check storage availability and try again.';}
|
| 54 |
+
}
|
| 55 |
+
async function init(){try{let r=await fetch(`/api/study?pid=${pid}`);if(!r.ok)throw Error();config=await r.json();const tr=await fetch('/api/tutorials');if(tr.ok)tutorials=await tr.json()}catch(e){$('#content').textContent='The questionnaire could not be loaded. Please refresh the page and try again.';return}storageKey=`study_${config.version}_${config.demo?'demo':'live'}_${pid}`;try{state=JSON.parse(localStorage.getItem(storageKey))||{index:0}}catch(e){state={index:0}}try{
|
| 56 |
+
outbox=new StudyOutbox({version:config.version,participantId:pid,demo:config.demo,onChange:renderSyncStatus});
|
| 57 |
+
if(state.pending){await outbox.enqueue(state.pending);delete state.pending;}
|
| 58 |
+
while(state.index<config.samples.length&&outbox.read(config.samples[state.index].id))state.index++;
|
| 59 |
+
persist();render();renderSyncStatus();outbox.kick();
|
| 60 |
+
}catch(e){$('#content').textContent='Browser storage is unavailable or unreadable. Please keep your existing browser data and contact the researcher.'}
|
| 61 |
+
}init();
|
| 62 |
+
</script>
|
| 63 |
+
</html>
|