mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-11-15 01:05:42 +00:00
Add NLP view.
This commit is contained in:
parent
ab688e290a
commit
1092312e6d
@ -24,7 +24,7 @@ class NewOCRJobForm(FlaskForm):
|
|||||||
],
|
],
|
||||||
validators=[DataRequired()]
|
validators=[DataRequired()]
|
||||||
)
|
)
|
||||||
submit = SubmitField('Create OCR job')
|
submit = SubmitField('Submit')
|
||||||
title = StringField(
|
title = StringField(
|
||||||
'Title',
|
'Title',
|
||||||
validators=[DataRequired(), Length(1, 32)]
|
validators=[DataRequired(), Length(1, 32)]
|
||||||
@ -64,7 +64,7 @@ class NewNLPJobForm(FlaskForm):
|
|||||||
],
|
],
|
||||||
validators=[DataRequired()]
|
validators=[DataRequired()]
|
||||||
)
|
)
|
||||||
submit = SubmitField('Create OCR job')
|
submit = SubmitField('Submit')
|
||||||
title = StringField(
|
title = StringField(
|
||||||
'Title',
|
'Title',
|
||||||
validators=[DataRequired(), Length(1, 32)]
|
validators=[DataRequired(), Length(1, 32)]
|
||||||
|
@ -2,7 +2,7 @@ from datetime import datetime
|
|||||||
from flask import current_app, flash, redirect, render_template, url_for
|
from flask import 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
|
from .forms import NewOCRJobForm, NewNLPJobForm
|
||||||
from ..import swarm
|
from ..import swarm
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
import hashlib
|
import hashlib
|
||||||
@ -57,3 +57,53 @@ def ocr():
|
|||||||
title='Optical Character Recognition',
|
title='Optical Character Recognition',
|
||||||
new_ocr_job_form=new_ocr_job_form
|
new_ocr_job_form=new_ocr_job_form
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@services.route('/nlp', methods=['GET', 'POST'])
|
||||||
|
@login_required
|
||||||
|
def nlp():
|
||||||
|
new_nlp_job_form = NewNLPJobForm()
|
||||||
|
if new_nlp_job_form.validate_on_submit():
|
||||||
|
app = current_app._get_current_object()
|
||||||
|
id = hashlib.md5(
|
||||||
|
(current_user.username + '_' + datetime.now().isoformat()).encode()
|
||||||
|
).hexdigest()
|
||||||
|
'''
|
||||||
|
' TODO: Implement a Job class. For now a dictionary representation
|
||||||
|
' is enough.
|
||||||
|
'''
|
||||||
|
job = {'creator': current_user.id,
|
||||||
|
'id': id,
|
||||||
|
'requested_cpus': 2,
|
||||||
|
'requested_memory': 2048,
|
||||||
|
'service': 'nlp',
|
||||||
|
'service_args': {'lang': new_nlp_job_form.language.data,
|
||||||
|
'version': new_nlp_job_form.version.data
|
||||||
|
},
|
||||||
|
'status': 'queued'
|
||||||
|
}
|
||||||
|
dir = os.path.join(app.config['OPAQUE_STORAGE'], 'jobs', id)
|
||||||
|
|
||||||
|
try:
|
||||||
|
os.makedirs(dir)
|
||||||
|
except OSError:
|
||||||
|
flash('OSError!')
|
||||||
|
else:
|
||||||
|
for file in new_nlp_job_form.files.data:
|
||||||
|
file.save(os.path.join(dir, file.filename))
|
||||||
|
'''
|
||||||
|
' 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()
|
||||||
|
flash('Job created!')
|
||||||
|
return redirect(url_for('services.nlp'))
|
||||||
|
|
||||||
|
return render_template(
|
||||||
|
'services/nlp.html.j2',
|
||||||
|
title='Natrual Language Processing',
|
||||||
|
new_nlp_job_form=new_nlp_job_form
|
||||||
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user