Make OPD scan AI processing manual with button
This commit is contained in:
parent
7275d13500
commit
ccbc5d7b72
|
|
@ -36,7 +36,8 @@
|
||||||
<div class="card border-primary mt-2">
|
<div class="card border-primary mt-2">
|
||||||
<div class="card-header py-2"><strong>AI Diagnosis Support</strong></div>
|
<div class="card-header py-2"><strong>AI Diagnosis Support</strong></div>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<div class="small text-muted" id="opd_scan_ai_result">AI analysis runs automatically in background after each scan/upload.</div>
|
<button type="button" id="opd_scan_ai_process_btn" class="btn btn-primary btn-sm mb-2" disabled>Process AI</button>
|
||||||
|
<div class="small text-muted" id="opd_scan_ai_result">Capture or upload a file, then click Process AI when needed.</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
@ -51,11 +52,13 @@
|
||||||
var $captureBtn = $('#opd_scan_capture_btn');
|
var $captureBtn = $('#opd_scan_capture_btn');
|
||||||
var $stopBtn = $('#opd_scan_stop_btn');
|
var $stopBtn = $('#opd_scan_stop_btn');
|
||||||
var $uploadBtn = $('#opd_scan_upload_btn');
|
var $uploadBtn = $('#opd_scan_upload_btn');
|
||||||
|
var $processAiBtn = $('#opd_scan_ai_process_btn');
|
||||||
var $results = $('#opd_scan_results');
|
var $results = $('#opd_scan_results');
|
||||||
var $textBox = $('#opd_scan_text_box');
|
var $textBox = $('#opd_scan_text_box');
|
||||||
var $aiResult = $('#opd_scan_ai_result');
|
var $aiResult = $('#opd_scan_ai_result');
|
||||||
var opdid = parseInt($('#opd_scan_opdid').val() || '0', 10);
|
var opdid = parseInt($('#opd_scan_opdid').val() || '0', 10);
|
||||||
var listPollingTimer = null;
|
var listPollingTimer = null;
|
||||||
|
var latestFileId = 0;
|
||||||
|
|
||||||
function getCsrfPair() {
|
function getCsrfPair() {
|
||||||
var input = document.querySelector('input[name="<?= csrf_token() ?>"]');
|
var input = document.querySelector('input[name="<?= csrf_token() ?>"]');
|
||||||
|
|
@ -114,7 +117,7 @@
|
||||||
|
|
||||||
function renderExtractedText(text) {
|
function renderExtractedText(text) {
|
||||||
if (!text) {
|
if (!text) {
|
||||||
$textBox.html('<div class="text-muted small">AI extraction is running in background. You can continue scanning other documents.</div>');
|
$textBox.html('<div class="text-muted small">AI text is not processed yet. Click Process AI to extract text.</div>');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var safe = $('<div>').text(text).html();
|
var safe = $('<div>').text(text).html();
|
||||||
|
|
@ -128,6 +131,8 @@
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$processAiBtn.prop('disabled', true).text('Processing...');
|
||||||
|
|
||||||
var csrf = getCsrfPair();
|
var csrf = getCsrfPair();
|
||||||
var payload = {
|
var payload = {
|
||||||
file_id: fileId,
|
file_id: fileId,
|
||||||
|
|
@ -140,16 +145,28 @@
|
||||||
if (data && parseInt(data.update || '0', 10) === 1) {
|
if (data && parseInt(data.update || '0', 10) === 1) {
|
||||||
$aiResult.removeClass('text-danger').addClass('text-muted').text('AI completed for latest report.');
|
$aiResult.removeClass('text-danger').addClass('text-muted').text('AI completed for latest report.');
|
||||||
} else {
|
} else {
|
||||||
var msg = (data && data.error_text) ? data.error_text : 'Background AI processing failed for one file.';
|
var msg = (data && data.error_text) ? data.error_text : 'AI processing failed for this file.';
|
||||||
$aiResult.removeClass('text-muted').addClass('text-danger').text(msg);
|
$aiResult.removeClass('text-muted').addClass('text-danger').text(msg);
|
||||||
}
|
}
|
||||||
|
$processAiBtn.prop('disabled', latestFileId <= 0).text('Process AI');
|
||||||
loadLastList();
|
loadLastList();
|
||||||
}, 'json').fail(function() {
|
}, 'json').fail(function() {
|
||||||
$aiResult.removeClass('text-muted').addClass('text-danger').text('Background AI processing failed for one file.');
|
$aiResult.removeClass('text-muted').addClass('text-danger').text('AI processing failed for this file.');
|
||||||
|
$processAiBtn.prop('disabled', latestFileId <= 0).text('Process AI');
|
||||||
loadLastList();
|
loadLastList();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function processLatestAi() {
|
||||||
|
if (latestFileId <= 0) {
|
||||||
|
$aiResult.removeClass('text-muted').addClass('text-danger').text('Capture or upload a file before running AI.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$aiResult.removeClass('text-danger').addClass('text-muted').text('AI processing started...');
|
||||||
|
renderExtractedText('');
|
||||||
|
queueAiProcessing(latestFileId);
|
||||||
|
}
|
||||||
|
|
||||||
function startListPolling() {
|
function startListPolling() {
|
||||||
if (listPollingTimer) {
|
if (listPollingTimer) {
|
||||||
clearInterval(listPollingTimer);
|
clearInterval(listPollingTimer);
|
||||||
|
|
@ -189,8 +206,9 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
renderExtractedText('');
|
renderExtractedText('');
|
||||||
$aiResult.removeClass('text-danger text-success').addClass('text-muted').text('Queued for background AI analysis...');
|
latestFileId = parseInt(data.file_id || '0', 10);
|
||||||
queueAiProcessing(parseInt(data.file_id || '0', 10));
|
$processAiBtn.prop('disabled', latestFileId <= 0).text('Process AI');
|
||||||
|
$aiResult.removeClass('text-danger text-success').addClass('text-muted').text('File saved. Click Process AI when you want analysis.');
|
||||||
loadLastList();
|
loadLastList();
|
||||||
},
|
},
|
||||||
error: function() {
|
error: function() {
|
||||||
|
|
@ -215,7 +233,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
$captureBtn.prop('disabled', true);
|
$captureBtn.prop('disabled', true);
|
||||||
$textBox.html('<div class="text-muted small">Processing scan text...</div>');
|
$textBox.html('<div class="text-muted small">Capturing and uploading file...</div>');
|
||||||
|
|
||||||
var canvas = $canvas.get(0);
|
var canvas = $canvas.get(0);
|
||||||
canvas.width = video.videoWidth;
|
canvas.width = video.videoWidth;
|
||||||
|
|
@ -263,6 +281,7 @@
|
||||||
$captureBtn.off('click.opdscan').on('click.opdscan', captureAndUpload);
|
$captureBtn.off('click.opdscan').on('click.opdscan', captureAndUpload);
|
||||||
$stopBtn.off('click.opdscan').on('click.opdscan', stopCamera);
|
$stopBtn.off('click.opdscan').on('click.opdscan', stopCamera);
|
||||||
$uploadBtn.off('click.opdscan').on('click.opdscan', uploadSelectedFile);
|
$uploadBtn.off('click.opdscan').on('click.opdscan', uploadSelectedFile);
|
||||||
|
$processAiBtn.off('click.opdscan').on('click.opdscan', processLatestAi);
|
||||||
|
|
||||||
window.removeOpdScanImage = function(fileId) {
|
window.removeOpdScanImage = function(fileId) {
|
||||||
if (!fileId) {
|
if (!fileId) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user