Spaces:
Running
Running
fix(studio): prioritize coords for vertical bbox, connect corrections API, remove duplicate renderQueue
Browse files1519 unmodified lines152015211522152315241525152615271528152915301531153251 unmodified lines158415851586158715881589159015911592159315941595159615971598165 unmodified lines1764176517661767176817696 unmodified lines177617771778177917801781318 unmodified lines210021012102210321042105330 unmodified lines2436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524861519 unmodified linesfinalCharXmin = 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 missinglet 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;}// Draw custom dashed bbox overlay for selected characterconst charBbox = document.createElement('div');51 unmodified linesif (!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 missingif ((!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;}if (overlayMode === "line") {const rect = document.createElement('div');165 unmodified lineseditEl.focus();}function exitEditMode(idx, saveChanges) {const viewEl = document.getElementById(`line-text-view-${idx}`);const editEl = document.getElementById(`line-text-edit-${idx}`);6 unmodified linesrenderEditor();renderBboxes();updateQueueItemStatus(imageQueue.findIndex(x => x.active === true), 'Verified');}}318 unmodified linesrenderBboxes();showToast(`Đã đồng ý dòng #${lineId + 1}`);updateQueueItemStatus(imageQueue.findIndex(x => x.active === true), 'Verified');// Select next line automaticallyif (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>1519 unmodified lines152015211522152315241525152615271528152915301531153251 unmodified lines158415851586158715881589159015911592159315941595159615971598165 unmodified lines176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817896 unmodified lines1796179717981799180018011802318 unmodified lines2121212221232124212521262127330 unmodified lines2458245924602461246224631519 unmodified linesfinalCharXmin = Math.round(xmin + boxWidth * (xOffset / (totalWidth || 1)));finalCharXmax = Math.round(xmin + boxWidth * ((xOffset + widths[charIdx]) / (totalWidth || 1)));// Prioritize core band coords for vertical height to avoid expanding into neighbor lineslet 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 characterconst charBbox = document.createElement('div');51 unmodified linesif (!box) return;const left = box[0];const width = box[2] - box[0];// Prioritize core band coords for vertical height to prevent diacritics from overlapping neighbor lineslet 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 lineseditEl.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 linesrenderEditor();renderBboxes();updateQueueItemStatus(imageQueue.findIndex(x => x.active === true), 'Verified');saveCorrectionToBackend(idx, newVal);}}318 unmodified linesrenderBboxes();showToast(`Đã đồng ý dòng #${lineId + 1}`);updateQueueItemStatus(imageQueue.findIndex(x => x.active === true), 'Verified');saveCorrectionToBackend(lineId, responseLines[lineId].text);// Select next line automaticallyif (lineId + 1 < responseLines.length) {330 unmodified lines}};</script></body></html>
ocr-studio/index.html+36-59