mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-11-15 01:05:42 +00:00
Change how job form works.
This commit is contained in:
parent
787bf4c377
commit
9d6e54e966
@ -1,28 +1,27 @@
|
|||||||
from flask import abort, 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 NewNLPJobForm, NewOCRJobForm
|
||||||
from ..models import Job
|
from ..models import Job
|
||||||
from .. import db
|
from .. import db
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
|
||||||
SERVICE_REQUIREMENTS = {'nlp': {'mem_mb': 4096, 'n_cores': 2},
|
SERVICES = {'nlp': {'name': 'Natural Language Processing',
|
||||||
'ocr': {'mem_mb': 8192, 'n_cores': 4}}
|
'resources': {'mem_mb': 4096, 'n_cores': 2},
|
||||||
|
'new_job_form': NewNLPJobForm},
|
||||||
|
'ocr': {'name': 'Optical Character Recognition',
|
||||||
|
'resources': {'mem_mb': 8192, 'n_cores': 4},
|
||||||
|
'new_job_form': NewOCRJobForm}}
|
||||||
|
|
||||||
|
|
||||||
@services.route('/<service_handle>', methods=['GET', 'POST'])
|
@services.route('/<service_handle>', methods=['GET', 'POST'])
|
||||||
@login_required
|
@login_required
|
||||||
def service(service_handle):
|
def service(service_handle):
|
||||||
if service_handle not in ['nlp', 'ocr']:
|
if service_handle not in SERVICES:
|
||||||
abort(404)
|
abort(404)
|
||||||
elif service_handle == 'nlp':
|
new_job_form = SERVICES[service_handle]['new_job_form']()
|
||||||
page_title = 'Natural Language Processing'
|
|
||||||
new_job_form = NewNLPJobForm()
|
|
||||||
elif service_handle == 'ocr':
|
|
||||||
page_title = 'Optical Character Recognition'
|
|
||||||
new_job_form = NewOCRJobForm()
|
|
||||||
if new_job_form.validate_on_submit():
|
if new_job_form.validate_on_submit():
|
||||||
_service_args = ['-l {}'.format(new_job_form.language.data)]
|
_service_args = ['-l {}'.format(new_job_form.language.data)]
|
||||||
if service_handle == 'ocr':
|
if service_handle == 'ocr':
|
||||||
@ -31,8 +30,8 @@ def service(service_handle):
|
|||||||
job = Job(
|
job = Job(
|
||||||
creator=current_user,
|
creator=current_user,
|
||||||
description=new_job_form.description.data,
|
description=new_job_form.description.data,
|
||||||
mem_mb=SERVICE_REQUIREMENTS[service_handle]['mem_mb'],
|
mem_mb=SERVICES[service_handle]['resources']['mem_mb'],
|
||||||
n_cores=SERVICE_REQUIREMENTS[service_handle]['n_cores'],
|
n_cores=SERVICES[service_handle]['resources']['n_cores'],
|
||||||
service=service_handle,
|
service=service_handle,
|
||||||
service_args=json.dumps(_service_args),
|
service_args=json.dumps(_service_args),
|
||||||
service_version=new_job_form.version.data,
|
service_version=new_job_form.version.data,
|
||||||
@ -53,11 +52,14 @@ def service(service_handle):
|
|||||||
db.session.commit()
|
db.session.commit()
|
||||||
else:
|
else:
|
||||||
for file in new_job_form.files.data:
|
for file in new_job_form.files.data:
|
||||||
|
''' TODO: Use secure filename '''
|
||||||
file.save(os.path.join(dir, file.filename))
|
file.save(os.path.join(dir, file.filename))
|
||||||
job.status = 'submitted'
|
job.status = 'submitted'
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
flash('Job created!')
|
flash('Job created!')
|
||||||
return redirect(url_for('services.{}'.format(service_handle)))
|
return redirect(
|
||||||
|
url_for('services.service', service_handle=service_handle)
|
||||||
|
)
|
||||||
return render_template('services/{}.html.j2'.format(service_handle),
|
return render_template('services/{}.html.j2'.format(service_handle),
|
||||||
title=page_title,
|
title=SERVICES[service_handle]['name'],
|
||||||
new_job_form=new_job_form)
|
new_job_form=new_job_form)
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
{% block page_content %}
|
{% block page_content %}
|
||||||
<div class="col s12 m4">
|
<div class="col s12 m4">
|
||||||
<h3>Corpora</h3>
|
<h3>My Corpora</h3>
|
||||||
<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren,</p>
|
<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren,</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -46,7 +46,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="col s12 m4">
|
<div class="col s12 m4">
|
||||||
<h3>Jobs</h3>
|
<h3>My Jobs</h3>
|
||||||
<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren,</p>
|
<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren,</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -117,7 +117,6 @@
|
|||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="col s12 m4">
|
<div class="col s12 m4">
|
||||||
<h2>Status:</h2>
|
|
||||||
<h3 id="title"></h3>
|
<h3 id="title"></h3>
|
||||||
<p id="description"></p>
|
<p id="description"></p>
|
||||||
<a class="waves-effect waves-light btn" id="status"></a>
|
<a class="waves-effect waves-light btn" id="status"></a>
|
||||||
@ -125,6 +124,7 @@
|
|||||||
<!-- Confirm deletion of job with modal dialogue
|
<!-- Confirm deletion of job with modal dialogue
|
||||||
Modal Trigger-->
|
Modal Trigger-->
|
||||||
<a href="#modal-confirm-delete" class="waves-effect waves-light btn red modal-trigger"><i class="material-icons left">delete</i>Delete Job</a>
|
<a href="#modal-confirm-delete" class="waves-effect waves-light btn red modal-trigger"><i class="material-icons left">delete</i>Delete Job</a>
|
||||||
|
<a href="#" class="waves-effect waves-light btn"><i class="material-icons left">settings</i>Export Parameters</a>
|
||||||
<!-- Modal Strucutre -->
|
<!-- Modal Strucutre -->
|
||||||
<div id="modal-confirm-delete" class="modal">
|
<div id="modal-confirm-delete" class="modal">
|
||||||
<div class="modal-content">
|
<div class="modal-content">
|
||||||
|
Loading…
Reference in New Issue
Block a user