Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
nopaque
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Admin message
Looking for advice? Join the
Matrix channel for GitLab users in Bielefeld
!
Show more breadcrumbs
SFB 1288 - INF
nopaque
Commits
78040536
Commit
78040536
authored
5 years ago
by
Patrick Jentsch
Browse files
Options
Downloads
Patches
Plain Diff
Add input options for ocr job creation.
parent
009e1889
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
app/services/forms.py
+30
-1
30 additions, 1 deletion
app/services/forms.py
app/services/views.py
+42
-24
42 additions, 24 deletions
app/services/views.py
app/templates/services/ocr.html.j2
+38
-2
38 additions, 2 deletions
app/templates/services/ocr.html.j2
with
110 additions
and
27 deletions
app/services/forms.py
+
30
−
1
View file @
78040536
from
flask_wtf
import
FlaskForm
from
flask_wtf
import
FlaskForm
from
wtforms
import
SubmitField
from
flask_wtf.file
import
FileAllowed
,
FileRequired
from
wtforms
import
FileField
,
SelectField
,
StringField
,
SubmitField
from
wtforms.validators
import
DataRequired
,
Length
class
OCRJobForm
(
FlaskForm
):
class
OCRJobForm
(
FlaskForm
):
description
=
StringField
(
'
Description
'
,
validators
=
[
DataRequired
(),
Length
(
1
,
64
)]
)
file
=
FileField
(
'
File
'
,
validators
=
[
FileAllowed
([
'
pdf
'
,
'
tif
'
,
'
tiff
'
]),
FileRequired
()
]
)
language
=
SelectField
(
'
Language
'
,
choices
=
[
(
''
,
'
Choose your option
'
),
(
'
eng
'
,
'
English
'
),
(
'
enm
'
,
'
English, Middle (1100-1500)
'
),
(
'
fra
'
,
'
French
'
),
(
'
frm
'
,
'
French, Middle (ca. 1400-1600)
'
),
(
'
deu
'
,
'
German
'
),
(
'
frk
'
,
'
German Fraktur
'
),
(
'
ita
'
,
'
Italian
'
),
(
'
por
'
,
'
Portuguese
'
),
(
'
spa
'
,
'
Spanish; Castilian
'
)
],
validators
=
[
DataRequired
()]
)
submit
=
SubmitField
(
'
Submit
'
)
submit
=
SubmitField
(
'
Submit
'
)
This diff is collapsed.
Click to expand it.
app/services/views.py
+
42
−
24
View file @
78040536
from
flask
import
redirect
,
render_template
,
url_for
from
datetime
import
datetime
from
flask
import
current_app
,
flash
,
redirect
,
render_template
,
url_for
,
request
from
.
import
services
from
.
import
services
from
flask_login
import
current_user
,
login_required
from
flask_login
import
current_user
,
login_required
from
.forms
import
OCRJobForm
from
.forms
import
OCRJobForm
from
..
import
swarm
from
..
import
swarm
from
threading
import
Thread
from
threading
import
Thread
import
hashlib
import
os
@services.route
(
'
/ocr
'
,
methods
=
[
'
GET
'
,
'
POST
'
])
@services.route
(
'
/ocr
'
,
methods
=
[
'
GET
'
,
'
POST
'
])
...
@@ -11,29 +14,44 @@ from threading import Thread
...
@@ -11,29 +14,44 @@ from threading import Thread
def
ocr
():
def
ocr
():
ocr_job_form
=
OCRJobForm
()
ocr_job_form
=
OCRJobForm
()
if
ocr_job_form
.
validate_on_submit
():
if
ocr_job_form
.
validate_on_submit
():
'''
app
=
current_app
.
_get_current_object
()
'
TODO: Implement a Job class. For now a dictionary representation is
id
=
hashlib
.
md5
(
'
enough.
(
current_user
.
username
+
'
_
'
+
datetime
.
now
().
isoformat
()).
encode
()
'''
).
hexdigest
()
job
=
{
'
worker
'
:
None
,
dir
=
os
.
path
.
join
(
app
.
config
[
'
OPAQUE_UPLOAD_DIRECTORY
'
],
id
)
'
creator
'
:
current_user
.
id
,
'
id
'
:
'
5fd40cb0cadef3ab5676c4968fc3d748
'
,
try
:
'
requested_cpus
'
:
2
,
os
.
mkdir
(
dir
)
'
requested_memory
'
:
2048
,
except
FileExistsError
:
'
service
'
:
'
ocr
'
,
# Possible MD5 hash collision occurred.
'
service_args
'
:
{
'
lang
'
:
'
eng
'
,
flash
(
'
Internal error occurred, please try again!
'
)
'
version
'
:
'
latest
'
else
:
},
file
=
ocr_job_form
.
file
.
data
'
status
'
:
'
queued
'
file
.
save
(
os
.
path
.
join
(
dir
,
file
.
filename
))
}
'''
'''
'
TODO: Let the scheduler run this job in the background.
'
TODO: Implement a Job class. For now a dictionary representation
'
'
is enough.
'
NOTE: Using self created threads is just for testing purpose as there
'''
'
is no scheduler available.
job
=
{
'
worker
'
:
None
,
'''
'
creator
'
:
current_user
.
id
,
thread
=
Thread
(
target
=
swarm
.
run
,
args
=
(
job
,))
'
id
'
:
id
,
thread
.
start
()
'
requested_cpus
'
:
2
,
'
requested_memory
'
:
2048
,
'
service
'
:
'
ocr
'
,
'
service_args
'
:
{
'
lang
'
:
ocr_job_form
.
language
.
data
,
'
version
'
:
'
latest
'
},
'
status
'
:
'
queued
'
}
'''
'
TODO: Let the scheduler run this job in the background.
'
'
NOTE: Using self created threads is just for testing purpose as
'
there is no scheduler available.
'''
thread
=
Thread
(
target
=
swarm
.
run
,
args
=
(
job
,))
thread
.
start
()
return
redirect
(
url_for
(
'
services.ocr
'
))
return
redirect
(
url_for
(
'
services.ocr
'
))
return
render_template
(
return
render_template
(
...
...
This diff is collapsed.
Click to expand it.
app/templates/services/ocr.html.j2
+
38
−
2
View file @
78040536
...
@@ -76,10 +76,46 @@
...
@@ -76,10 +76,46 @@
</div>
</div>
<div class="col s12">
<div class="col s12">
<div class="card
large
">
<div class="card">
<div class="card-content">
<div class="card-content">
<form method="POST">
<form method="POST"
enctype="multipart/form-data"
>
{{ ocr_job_form.hidden_tag() }}
{{ ocr_job_form.hidden_tag() }}
<div class="row">
<div class="col s8">
<div class="input-field">
<i class="material-icons prefix">description</i>
{{ ocr_job_form.description(placeholder='Job description') }}
{{ ocr_job_form.description.label }}
{% for error in ocr_job_form.description.errors %}
<span class="helper-text red-text">{{ error }}</span>
{% endfor %}
</div>
</div>
<div class="col s4">
<div class="input-field">
<i class="material-icons prefix">language</i>
{{ ocr_job_form.language() }}
{{ ocr_job_form.language.label }}
{% for error in ocr_job_form.language.errors %}
<span class="helper-text red-text">{{ error }}</span>
{% endfor %}
</div>
</div>
<div class="col s8">
<div class="file-field input-field">
<div class="btn">
<span>{{ ocr_job_form.file.label.text }}</span>
{{ ocr_job_form.file() }}
</div>
<div class="file-path-wrapper">
<input class="file-path validate" type="text">
</div>
{% for error in ocr_job_form.file.errors %}
<span class="helper-text red-text">{{ error }}</span>
{% endfor %}
</div>
</div>
</div>
{{ ocr_job_form.submit(class='btn') }}
{{ ocr_job_form.submit(class='btn') }}
</form>
</form>
</div>
</div>
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment