mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-11-15 01:05:42 +00:00
Unify service pages.
This commit is contained in:
parent
a267de0867
commit
787bf4c377
@ -1,4 +1,4 @@
|
|||||||
from flask import current_app, flash, redirect, render_template, url_for
|
from flask import abort, current_app, flash, redirect, render_template, url_for
|
||||||
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 NewOCRJobForm, NewNLPJobForm
|
from .forms import NewOCRJobForm, NewNLPJobForm
|
||||||
@ -8,93 +8,56 @@ import json
|
|||||||
import os
|
import os
|
||||||
|
|
||||||
|
|
||||||
@services.route('/nlp', methods=['GET', 'POST'])
|
SERVICE_REQUIREMENTS = {'nlp': {'mem_mb': 4096, 'n_cores': 2},
|
||||||
|
'ocr': {'mem_mb': 8192, 'n_cores': 4}}
|
||||||
|
|
||||||
|
|
||||||
|
@services.route('/<service_handle>', methods=['GET', 'POST'])
|
||||||
@login_required
|
@login_required
|
||||||
def nlp():
|
def service(service_handle):
|
||||||
new_nlp_job_form = NewNLPJobForm()
|
if service_handle not in ['nlp', 'ocr']:
|
||||||
if new_nlp_job_form.validate_on_submit():
|
abort(404)
|
||||||
nlp_job = Job(creator=current_user,
|
elif service_handle == 'nlp':
|
||||||
description=new_nlp_job_form.description.data,
|
page_title = 'Natural Language Processing'
|
||||||
mem_mb=4096,
|
new_job_form = NewNLPJobForm()
|
||||||
n_cores=2,
|
elif service_handle == 'ocr':
|
||||||
service='nlp',
|
page_title = 'Optical Character Recognition'
|
||||||
service_args=json.dumps(
|
new_job_form = NewOCRJobForm()
|
||||||
['-l {}'.format(new_nlp_job_form.language.data)]
|
if new_job_form.validate_on_submit():
|
||||||
),
|
_service_args = ['-l {}'.format(new_job_form.language.data)]
|
||||||
service_version=new_nlp_job_form.version.data,
|
if service_handle == 'ocr':
|
||||||
|
if not new_job_form.binarization.data:
|
||||||
|
_service_args.append('--skip-binarisation')
|
||||||
|
job = Job(
|
||||||
|
creator=current_user,
|
||||||
|
description=new_job_form.description.data,
|
||||||
|
mem_mb=SERVICE_REQUIREMENTS[service_handle]['mem_mb'],
|
||||||
|
n_cores=SERVICE_REQUIREMENTS[service_handle]['n_cores'],
|
||||||
|
service=service_handle,
|
||||||
|
service_args=json.dumps(_service_args),
|
||||||
|
service_version=new_job_form.version.data,
|
||||||
status='preparing',
|
status='preparing',
|
||||||
title=new_nlp_job_form.title.data)
|
title=new_job_form.title.data
|
||||||
|
)
|
||||||
db.session.add(nlp_job)
|
db.session.add(job)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
dir = os.path.join(current_app.config['OPAQUE_STORAGE_DIRECTORY'],
|
dir = os.path.join(current_app.config['OPAQUE_STORAGE_DIRECTORY'],
|
||||||
str(nlp_job.user_id),
|
str(job.user_id),
|
||||||
'jobs',
|
'jobs',
|
||||||
str(nlp_job.id))
|
str(job.id))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
os.makedirs(dir)
|
os.makedirs(dir)
|
||||||
except OSError:
|
except OSError:
|
||||||
flash('OSError!')
|
flash('OSError!')
|
||||||
db.session.remove(nlp_job)
|
db.session.remove(job)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
else:
|
else:
|
||||||
for file in new_nlp_job_form.files.data:
|
for file in new_job_form.files.data:
|
||||||
file.save(os.path.join(dir, file.filename))
|
file.save(os.path.join(dir, file.filename))
|
||||||
nlp_job.status = 'submitted'
|
job.status = 'submitted'
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
flash('Job created!')
|
flash('Job created!')
|
||||||
return redirect(url_for('services.nlp'))
|
return redirect(url_for('services.{}'.format(service_handle)))
|
||||||
|
return render_template('services/{}.html.j2'.format(service_handle),
|
||||||
return render_template('services/nlp.html.j2',
|
title=page_title,
|
||||||
title='Natrual Language Processing',
|
new_job_form=new_job_form)
|
||||||
new_nlp_job_form=new_nlp_job_form)
|
|
||||||
|
|
||||||
|
|
||||||
@services.route('/ocr', methods=['GET', 'POST'])
|
|
||||||
@login_required
|
|
||||||
def ocr():
|
|
||||||
new_ocr_job_form = NewOCRJobForm()
|
|
||||||
if new_ocr_job_form.validate_on_submit():
|
|
||||||
ocr_job = Job(creator=current_user,
|
|
||||||
description=new_ocr_job_form.description.data,
|
|
||||||
mem_mb=8192,
|
|
||||||
n_cores=4,
|
|
||||||
service='ocr',
|
|
||||||
service_args=json.dumps(
|
|
||||||
[
|
|
||||||
'-l {}'.format(new_ocr_job_form.language.data),
|
|
||||||
'' if new_ocr_job_form.binarization.data
|
|
||||||
else '--skip-binarisation'
|
|
||||||
]
|
|
||||||
),
|
|
||||||
service_version=new_ocr_job_form.version.data,
|
|
||||||
status='preparing',
|
|
||||||
title=new_ocr_job_form.title.data)
|
|
||||||
|
|
||||||
db.session.add(ocr_job)
|
|
||||||
db.session.commit()
|
|
||||||
|
|
||||||
dir = os.path.join(current_app.config['OPAQUE_STORAGE_DIRECTORY'],
|
|
||||||
str(ocr_job.user_id),
|
|
||||||
'jobs',
|
|
||||||
str(ocr_job.id))
|
|
||||||
|
|
||||||
try:
|
|
||||||
os.makedirs(dir)
|
|
||||||
except OSError:
|
|
||||||
flash('OSError!')
|
|
||||||
db.session.remove(ocr_job)
|
|
||||||
db.session.commit()
|
|
||||||
else:
|
|
||||||
for file in new_ocr_job_form.files.data:
|
|
||||||
file.save(os.path.join(dir, file.filename))
|
|
||||||
ocr_job.status = 'submitted'
|
|
||||||
db.session.commit()
|
|
||||||
flash('Job created!')
|
|
||||||
return redirect(url_for('services.ocr'))
|
|
||||||
|
|
||||||
return render_template('services/ocr.html.j2',
|
|
||||||
title='Optical Character Recognition',
|
|
||||||
new_ocr_job_form=new_ocr_job_form)
|
|
||||||
|
@ -148,8 +148,8 @@
|
|||||||
<li><a href="{{ url_for('main.dashboard') }}"><i class="material-icons">dashboard</i>Dashboard</a></li>
|
<li><a href="{{ url_for('main.dashboard') }}"><i class="material-icons">dashboard</i>Dashboard</a></li>
|
||||||
<li><div class="divider"></div></li>
|
<li><div class="divider"></div></li>
|
||||||
<li><a class="subheader">Services</a></li>
|
<li><a class="subheader">Services</a></li>
|
||||||
<li><a href="{{ url_for('services.nlp') }}"><i class="material-icons">format_textdirection_l_to_r</i>NLP</a></li>
|
<li><a href="{{ url_for('services.service', service_handle='nlp') }}"><i class="material-icons">format_textdirection_l_to_r</i>NLP</a></li>
|
||||||
<li><a href="{{ url_for('services.ocr') }}"><i class="material-icons">find_in_page</i>OCR</a></li>
|
<li><a href="{{ url_for('services.service', service_handle='ocr') }}"><i class="material-icons">find_in_page</i>OCR</a></li>
|
||||||
{% if current_user.is_administrator() %}
|
{% if current_user.is_administrator() %}
|
||||||
<li><div class="divider"></div></li>
|
<li><div class="divider"></div></li>
|
||||||
<li><a class="subheader">Administration</a></li>
|
<li><a class="subheader">Administration</a></li>
|
||||||
|
@ -134,7 +134,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<ul id='new-job-dropdown' class='dropdown-content'>
|
<ul id='new-job-dropdown' class='dropdown-content'>
|
||||||
<li><a href="{{ url_for('services.nlp') }}"><i class="material-icons">format_textdirection_l_to_r</i>NLP</a></li>
|
<li><a href="{{ url_for('services.service', service_handle='nlp') }}"><i class="material-icons">format_textdirection_l_to_r</i>NLP</a></li>
|
||||||
<li><a href="{{ url_for('services.ocr') }}"><i class="material-icons">find_in_page</i>OCR</a></li>
|
<li><a href="{{ url_for('services.service', service_handle='ocr') }}"><i class="material-icons">find_in_page</i>OCR</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
@ -55,14 +55,14 @@
|
|||||||
<div class="card">
|
<div class="card">
|
||||||
<form method="POST" enctype="multipart/form-data" id="new-nlp-job-form">
|
<form method="POST" enctype="multipart/form-data" id="new-nlp-job-form">
|
||||||
<div class="card-content">
|
<div class="card-content">
|
||||||
{{ new_nlp_job_form.hidden_tag() }}
|
{{ new_job_form.hidden_tag() }}
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col s12 m4">
|
<div class="col s12 m4">
|
||||||
<div class="input-field">
|
<div class="input-field">
|
||||||
<i class="material-icons prefix">title</i>
|
<i class="material-icons prefix">title</i>
|
||||||
{{ new_nlp_job_form.title(data_length='32') }}
|
{{ new_job_form.title(data_length='32') }}
|
||||||
{{ new_nlp_job_form.title.label }}
|
{{ new_job_form.title.label }}
|
||||||
{% for error in new_nlp_job_form.title.errors %}
|
{% for error in new_job_form.title.errors %}
|
||||||
<span class="helper-text red-text">{{ error }}</span>
|
<span class="helper-text red-text">{{ error }}</span>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
@ -70,9 +70,9 @@
|
|||||||
<div class="col s12 m4">
|
<div class="col s12 m4">
|
||||||
<div class="input-field">
|
<div class="input-field">
|
||||||
<i class="material-icons prefix">language</i>
|
<i class="material-icons prefix">language</i>
|
||||||
{{ new_nlp_job_form.language() }}
|
{{ new_job_form.language() }}
|
||||||
{{ new_nlp_job_form.language.label }}
|
{{ new_job_form.language.label }}
|
||||||
{% for error in new_nlp_job_form.language.errors %}
|
{% for error in new_job_form.language.errors %}
|
||||||
<span class="helper-text red-text">{{ error }}</span>
|
<span class="helper-text red-text">{{ error }}</span>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
@ -80,9 +80,9 @@
|
|||||||
<div class="col s12 m4">
|
<div class="col s12 m4">
|
||||||
<div class="input-field">
|
<div class="input-field">
|
||||||
<i class="material-icons prefix">language</i>
|
<i class="material-icons prefix">language</i>
|
||||||
{{ new_nlp_job_form.version() }}
|
{{ new_job_form.version() }}
|
||||||
{{ new_nlp_job_form.version.label }}
|
{{ new_job_form.version.label }}
|
||||||
{% for error in new_nlp_job_form.version.errors %}
|
{% for error in new_job_form.version.errors %}
|
||||||
<span class="helper-text red-text">{{ error }}</span>
|
<span class="helper-text red-text">{{ error }}</span>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
@ -92,13 +92,13 @@
|
|||||||
<div class="col s12 m6">
|
<div class="col s12 m6">
|
||||||
<div class="file-field input-field">
|
<div class="file-field input-field">
|
||||||
<div class="btn">
|
<div class="btn">
|
||||||
<span>{{ new_nlp_job_form.files.label.text }}</span>
|
<span>{{ new_job_form.files.label.text }}</span>
|
||||||
{{ new_nlp_job_form.files(accept='text/plain') }}
|
{{ new_job_form.files(accept='text/plain') }}
|
||||||
</div>
|
</div>
|
||||||
<div class="file-path-wrapper">
|
<div class="file-path-wrapper">
|
||||||
<input class="file-path validate" type="text">
|
<input class="file-path validate" type="text">
|
||||||
</div>
|
</div>
|
||||||
{% for error in new_nlp_job_form.files.errors %}
|
{% for error in new_job_form.files.errors %}
|
||||||
<span class="helper-text red-text">{{ error }}</span>
|
<span class="helper-text red-text">{{ error }}</span>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
@ -106,9 +106,9 @@
|
|||||||
<div class="col s12 m6">
|
<div class="col s12 m6">
|
||||||
<div class="input-field">
|
<div class="input-field">
|
||||||
<i class="material-icons prefix">description</i>
|
<i class="material-icons prefix">description</i>
|
||||||
{{ new_nlp_job_form.description(data_length='255') }}
|
{{ new_job_form.description(data_length='255') }}
|
||||||
{{ new_nlp_job_form.description.label }}
|
{{ new_job_form.description.label }}
|
||||||
{% for error in new_nlp_job_form.description.errors %}
|
{% for error in new_job_form.description.errors %}
|
||||||
<span class="helper-text red-text">{{ error }}</span>
|
<span class="helper-text red-text">{{ error }}</span>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
@ -116,7 +116,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-action right-align">
|
<div class="card-action right-align">
|
||||||
{{ new_nlp_job_form.submit(class='btn') }}
|
{{ new_job_form.submit(class='btn') }}
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
@ -56,14 +56,14 @@
|
|||||||
<div class="card">
|
<div class="card">
|
||||||
<form method="POST" enctype="multipart/form-data" id="new-ocr-job-form">
|
<form method="POST" enctype="multipart/form-data" id="new-ocr-job-form">
|
||||||
<div class="card-content">
|
<div class="card-content">
|
||||||
{{ new_ocr_job_form.hidden_tag() }}
|
{{ new_job_form.hidden_tag() }}
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col s12 m4">
|
<div class="col s12 m4">
|
||||||
<div class="input-field">
|
<div class="input-field">
|
||||||
<i class="material-icons prefix">title</i>
|
<i class="material-icons prefix">title</i>
|
||||||
{{ new_ocr_job_form.title(data_length='32') }}
|
{{ new_job_form.title(data_length='32') }}
|
||||||
{{ new_ocr_job_form.title.label }}
|
{{ new_job_form.title.label }}
|
||||||
{% for error in new_ocr_job_form.title.errors %}
|
{% for error in new_job_form.title.errors %}
|
||||||
<span class="helper-text red-text">{{ error }}</span>
|
<span class="helper-text red-text">{{ error }}</span>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
@ -71,9 +71,9 @@
|
|||||||
<div class="col s12 m8">
|
<div class="col s12 m8">
|
||||||
<div class="input-field">
|
<div class="input-field">
|
||||||
<i class="material-icons prefix">description</i>
|
<i class="material-icons prefix">description</i>
|
||||||
{{ new_ocr_job_form.description(data_length='255') }}
|
{{ new_job_form.description(data_length='255') }}
|
||||||
{{ new_ocr_job_form.description.label }}
|
{{ new_job_form.description.label }}
|
||||||
{% for error in new_ocr_job_form.description.errors %}
|
{% for error in new_job_form.description.errors %}
|
||||||
<span class="helper-text red-text">{{ error }}</span>
|
<span class="helper-text red-text">{{ error }}</span>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
@ -81,13 +81,13 @@
|
|||||||
<div class="col s12 m5">
|
<div class="col s12 m5">
|
||||||
<div class="file-field input-field">
|
<div class="file-field input-field">
|
||||||
<div class="btn">
|
<div class="btn">
|
||||||
<span>{{ new_ocr_job_form.files.label.text }}</span>
|
<span>{{ new_job_form.files.label.text }}</span>
|
||||||
{{ new_ocr_job_form.files(accept='application/pdf, image/tiff') }}
|
{{ new_job_form.files(accept='application/pdf, image/tiff') }}
|
||||||
</div>
|
</div>
|
||||||
<div class="file-path-wrapper">
|
<div class="file-path-wrapper">
|
||||||
<input class="file-path validate" type="text">
|
<input class="file-path validate" type="text">
|
||||||
</div>
|
</div>
|
||||||
{% for error in new_ocr_job_form.files.errors %}
|
{% for error in new_job_form.files.errors %}
|
||||||
<span class="helper-text red-text">{{ error }}</span>
|
<span class="helper-text red-text">{{ error }}</span>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
@ -95,9 +95,9 @@
|
|||||||
<div class="col s12 m4">
|
<div class="col s12 m4">
|
||||||
<div class="input-field">
|
<div class="input-field">
|
||||||
<i class="material-icons prefix">language</i>
|
<i class="material-icons prefix">language</i>
|
||||||
{{ new_ocr_job_form.language() }}
|
{{ new_job_form.language() }}
|
||||||
{{ new_ocr_job_form.language.label }}
|
{{ new_job_form.language.label }}
|
||||||
{% for error in new_ocr_job_form.language.errors %}
|
{% for error in new_job_form.language.errors %}
|
||||||
<span class="helper-text red-text">{{ error }}</span>
|
<span class="helper-text red-text">{{ error }}</span>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
@ -105,9 +105,9 @@
|
|||||||
<div class="col s12 m3">
|
<div class="col s12 m3">
|
||||||
<div class="input-field">
|
<div class="input-field">
|
||||||
<i class="material-icons prefix">apps</i>
|
<i class="material-icons prefix">apps</i>
|
||||||
{{ new_ocr_job_form.version() }}
|
{{ new_job_form.version() }}
|
||||||
{{ new_ocr_job_form.version.label }}
|
{{ new_job_form.version.label }}
|
||||||
{% for error in new_ocr_job_form.version.errors %}
|
{% for error in new_job_form.version.errors %}
|
||||||
<span class="helper-text red-text">{{ error }}</span>
|
<span class="helper-text red-text">{{ error }}</span>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
@ -194,7 +194,7 @@
|
|||||||
<div class="col s3">
|
<div class="col s3">
|
||||||
<div class="switch">
|
<div class="switch">
|
||||||
<label>
|
<label>
|
||||||
{{ new_ocr_job_form.binarization() }}
|
{{ new_job_form.binarization() }}
|
||||||
<span class="lever"></span>
|
<span class="lever"></span>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
@ -204,7 +204,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="card-action right-align">
|
<div class="card-action right-align">
|
||||||
{{ new_ocr_job_form.submit(class='btn') }}
|
{{ new_job_form.submit(class='btn') }}
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
Reference in New Issue
Block a user