Spaces:
Running
Running
fix(studio): prioritize coords for vertical bbox, connect corrections API, remove duplicate renderQueue
Browse files1519 unmodified lines1520152115221523152415251526152715281529152315241525152615271528152915301531153251 unmodified lines1584158515861587158715891588159115921593159415951589159015911592159315941595159615971598165 unmodified lines176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817896 unmodified lines1796179717981799180018011802318 unmodified lines2121212221232124212521262127330 unmodified lines2458245924602439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832461246224631519 unmodified lines finalCharXmin = Math.round(xmin + boxWidth * (xOffset / (totalWidth || 1))); finalCharXmax = Math.round(xmin + boxWidth * ((xOffset + widths[charIdx]) / (totalWidth || 1))); // Use tight ymin and ymax from bbox, fall back to coords only if bbox is missing let visualTop = Math.max(0, ymin - 2); let visualHeight = (ymax - ymin) + 4; if ((!lineData.bbox || lineData.bbox.length < 4) && lineData.coords && lineData.coords.length === 2) { visualTop = Math.max(0, lineData.coords[0] - 4); visualHeight = (lineData.coords[1] - lineData.coords[0]) + 8; } // Prioritize core band coords for vertical height to avoid expanding into neighbor lines let visualTop = (lineData.coords && lineData.coords.length === 2) ? Math.max(0, lineData.coords[0] - 2) : Math.max(0, ymin - 2); let visualHeight = (lineData.coords && lineData.coords.length === 2) ? (lineData.coords[1] - lineData.coords[0]) + 4 : (ymax - ymin) + 4;
// Draw custom dashed bbox overlay for selected character const charBbox = document.createElement('div');51 unmodified lines if (!box) return;
const left = box[0]; let top = Math.max(0, box[1] - 2); const width = box[2] - box[0]; let height = (box[3] - box[1]) + 4;
// Fall back to core band coords only if bbox is missing if ((!box || box.length < 4) && item.coords && item.coords.length === 2) { top = Math.max(0, item.coords[0] - 4); height = (item.coords[1] - item.coords[0]) + 8; } // Prioritize core band coords for vertical height to prevent diacritics from overlapping neighbor lines let top = (item.coords && item.coords.length === 2) ? Math.max(0, item.coords[0] - 2) : Math.max(0, box[1] - 2); let height = (item.coords && item.coords.length === 2) ? (item.coords[1] - item.coords[0]) + 4 : (box[3] - box[1]) + 4;
if (overlayMode === "line") { const rect = document.createElement('div');165 unmodified lines editEl.focus(); }
function saveCorrectionToBackend(lineIdx, text) { if (!text || !text.trim()) return; const activeItem = imageQueue.find(x => x.active === true); const imageName = activeItem ? activeItem.name : "unknown.png"; fetch('/save_correction', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ text: text.trim(), line_idx: lineIdx + 1, image_name: imageName }) }).then(res => res.json()) .then(data => { appendLog(`Đã ghi nhận hiệu chỉnh dòng #${lineIdx + 1} vào ocr_corrections.txt`, 'success'); }).catch(err => { console.warn("Failed to save correction to backend:", err); }); }
function exitEditMode(idx, saveChanges) { const viewEl = document.getElementById(`line-text-view-${idx}`); const editEl = document.getElementById(`line-text-edit-${idx}`);6 unmodified lines renderEditor(); renderBboxes(); updateQueueItemStatus(imageQueue.findIndex(x => x.active === true), 'Verified'); saveCorrectionToBackend(idx, newVal); } } 318 unmodified lines renderBboxes(); showToast(`Đã đồng ý dòng #${lineId + 1}`); updateQueueItemStatus(imageQueue.findIndex(x => x.active === true), 'Verified'); saveCorrectionToBackend(lineId, responseLines[lineId].text); // Select next line automatically if (lineId + 1 < responseLines.length) {330 unmodified lines } };
function renderQueue() { const qList = document.getElementById('queue-list'); qList.innerHTML = ""; if (imageQueue.length === 0) { qList.innerHTML = '<div style="color: var(--text-muted); padding: 20px; text-align: center; font-size: 12px;">Hàng đợi trống</div>'; return; }
imageQueue.forEach((item, qIdx) => { const row = document.createElement('div'); row.className = `queue-item ${item.active ? 'active' : ''}`; row.onclick = () => selectQueueItem(item.id);
const thumb = document.createElement('div'); thumb.className = 'queue-thumb'; thumb.innerHTML = `<img src="data:image/png;base64,${item.image}" alt="">`;
const info = document.createElement('div'); info.className = 'queue-info';
const name = document.createElement('div'); name.className = 'queue-name'; name.innerText = item.name; name.title = item.name;
const meta = document.createElement('div'); meta.className = 'queue-meta'; const timeSpan = document.createElement('span'); timeSpan.innerText = item.time; const statusSpan = document.createElement('span'); statusSpan.className = `status-badge status-${item.status.toLowerCase().replace(/ /g, '_')}`; statusSpan.innerText = item.status;
meta.appendChild(timeSpan); meta.appendChild(statusSpan); info.appendChild(name); info.appendChild(meta); row.appendChild(thumb); row.appendChild(info); qList.appendChild(row); }); } </script></body></html>ocr-studio/index.html+36-59