Skip to content

Commit

Permalink
Merge pull request dwhly-proj#106 from dwhly-proj/paul/ocr_force_update
Browse files Browse the repository at this point in the history
Paul/ocr force update
  • Loading branch information
genuineBuildMonkey authored Aug 21, 2021
2 parents f6bdd0a + 805ca05 commit 2520c2b
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 14 deletions.
14 changes: 13 additions & 1 deletion droppdf/apps/_static/apps/js/ocr_pdf_upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,17 @@
$('#run-button')
.addClass('disabled')
.attr('disabled', true)

} else if (response.file_info.has_text) {

$('#run-button').hide();
$('#upload-has-text').show();

} else {
$('#run-button')
.removeClass('disabled')
.attr('disabled', false)
.show()
}
};
},
Expand Down Expand Up @@ -164,8 +171,13 @@
$(document).ready(function() {
upload_in_progress = false;
$('.button-box').hide();
$('#upload-has-text').hide();
$('#in-progress').hide();
$('#pdf-file').attr('disabled', false);

$('#pdf-file')
.attr('disabled', false)
.val('')

$('#progress-bar-inner').css('width', '0%');
$('#pdf-file')
.attr('disabled', false)
Expand Down
35 changes: 26 additions & 9 deletions droppdf/apps/_templates/ocr_pdf.html
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,15 @@
color: red;
}

.success-msg {
padding-top: 1em;
color: green;
}

.black-text {
color: #000;
}

.button-box {
display: flex;
flex: 1;
Expand Down Expand Up @@ -245,7 +254,7 @@
Add text to an image PDF.
</div>

<form id="param-form" action="/ocr/upload/" method="POST" enctype="multipart/form-data">
<form id="param-form" action="/ocr/upload/" method="POST" autocomplete="off" enctype="multipart/form-data">

<div class="option-box">
</div>
Expand Down Expand Up @@ -288,19 +297,27 @@ <h3 id="filename"></h3>
<i class="fa fa-upload"></i>
Run OCR
</div>

<div id="run-force" class="button" style="width: 8em" onclick="runOCR(true)">
<i class="fa fa-upload"></i>
Force OCR
</div>
<div class="help-label">
<i class="fa fa-question-circle" title="Forcing OCR will replace any existing text with OCRd text. If there is a question, it's likely better to try 'Run OCR' first."></i>
</div>
</div>

<div id="upload-error" class="small error" style="display: none;">
</div>

<div id="upload-has-text" class="small success-msg" style="display: none;">
<span style="font-size: 1.2em">
<i class="fa fa-check"></i>
</span>
This document already has selectable text and is most likely ready to use for annotations.
<br><br>
If the quality of the current OCR'd text is not acceptable you can redo the OCR process which may give better results.
<br>
(This process will take some time and in rare instances will not be successful, depending on the qualities of the uploaded document).
<br><br>
<div id="run-force" class="button black-text" style="width: 8em" onclick="runOCR(true)">
<i class="fa fa-upload"></i>
Redo OCR
</div>
</div>

</div>

</form>
Expand Down
2 changes: 1 addition & 1 deletion droppdf/apps/_templates/ocr_pdf_result.html
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
OCR in progress. Started at <span id="time-start"></span>
</p>
<p>
Large files can sometimes take several minutes, or up to five or ten if the Force OCR option is used.
Large files can sometimes take several minutes, or up to five or ten if the OCR is a redo with existing text.
</p>
<p>
A clickable download link will appear when processing is complete.
Expand Down
7 changes: 5 additions & 2 deletions droppdf/apps/apps/ocr/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,10 @@ def upload(request):

#already_has_text?
if check_pdf_has_text(new_filename):
processing_error = 'This PDF already has text. Use the "Force OCR" button to overwrite text with a fresh OCR if desired. If file was OCRd on previous upload those results will be provided'
#processing_error = 'This PDF already has text. Use the "Force OCR" button to overwrite text with a fresh OCR if desired. If file was OCRd on previous upload those results will be provided'
has_text = True
else:
has_text = False


if not existing_name:
Expand Down Expand Up @@ -114,7 +117,7 @@ def upload(request):
data = {'file_info': {'filename': filename, 'size': file_.size,
'new_filename': new_filename, 'processing_error': processing_error,
'tempfile_path': tempfile_path, 'already_exists': already_exists,
'md5_hash': md5_hash}}
'md5_hash': md5_hash, 'has_text': has_text}}

return JsonResponse(data)

Expand Down
2 changes: 1 addition & 1 deletion droppdf/droppdf/celery.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from django.conf import settings

app = Celery('financial_planning_app', broker=settings.BROKER_URL)
app = Celery('droppdf_app', broker=settings.BROKER_URL)

app.config_from_object('django.conf:settings', namespace='CELERY')
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
Expand Down

0 comments on commit 2520c2b

Please sign in to comment.