mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-12-24 10:34:17 +00:00
Move ocr job to extra package.
This commit is contained in:
parent
724d2a47cd
commit
7b185d929e
@ -23,13 +23,16 @@ def create_app(config_name):
|
||||
db.init_app(app)
|
||||
login_manager.init_app(app)
|
||||
mail.init_app(app)
|
||||
if not hasattr(app, 'extensions'):
|
||||
app.extensions = {}
|
||||
|
||||
from .auth import auth as auth_blueprint
|
||||
app.register_blueprint(auth_blueprint, url_prefix='/auth')
|
||||
|
||||
from .services import services as services_blueprint
|
||||
app.register_blueprint(services_blueprint, url_prefix='/services')
|
||||
|
||||
from .main import main as main_blueprint
|
||||
app.register_blueprint(main_blueprint)
|
||||
|
||||
print(app.url_map)
|
||||
|
||||
return app
|
||||
|
@ -1,6 +0,0 @@
|
||||
from flask_wtf import FlaskForm
|
||||
from wtforms import SubmitField
|
||||
|
||||
|
||||
class SwarmForm(FlaskForm):
|
||||
submit = SubmitField('Submit')
|
@ -1,12 +1,9 @@
|
||||
from flask import redirect, render_template, url_for
|
||||
from flask import render_template
|
||||
from ..models import User
|
||||
from ..tables import AdminUserTable, AdminUserItem
|
||||
from . import main
|
||||
from ..decorators import admin_required
|
||||
from flask_login import current_user, login_required
|
||||
from .forms import SwarmForm
|
||||
from ..import swarm
|
||||
from threading import Thread
|
||||
from flask_login import login_required
|
||||
|
||||
|
||||
@main.route('/')
|
||||
@ -29,32 +26,5 @@ def for_admins_only():
|
||||
users = User.query.order_by(User.username).all()
|
||||
items = [AdminUserItem(u.username, u.email, u.role_id, u.confirmed) for u in users]
|
||||
table = AdminUserTable(items)
|
||||
|
||||
swarm_form = SwarmForm()
|
||||
if swarm_form.validate_on_submit():
|
||||
'''
|
||||
' TODO: Implement a Job class. For now a dictionary representation is
|
||||
' enough.
|
||||
'''
|
||||
job = {
|
||||
'creator': current_user.id,
|
||||
'id': '5fd40cb0cadef3ab5676c4968fc3d748',
|
||||
'requested_cpus': 2,
|
||||
'requested_memory': 2048,
|
||||
'service': 'ocr',
|
||||
'service_args': {
|
||||
'lang': 'eng'
|
||||
},
|
||||
'status': 'queued'
|
||||
}
|
||||
'''
|
||||
' TODO: Let the scheduler run this job in the background. 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('main.for_admins_only'))
|
||||
|
||||
return render_template('main/admin.html.j2', title='Administration tools',
|
||||
swarm_form=swarm_form, table=table.__html__())
|
||||
table=table.__html__())
|
||||
|
5
app/services/__init__.py
Normal file
5
app/services/__init__.py
Normal file
@ -0,0 +1,5 @@
|
||||
from flask import Blueprint
|
||||
|
||||
services = Blueprint('services', __name__)
|
||||
|
||||
from . import views
|
6
app/services/forms.py
Normal file
6
app/services/forms.py
Normal file
@ -0,0 +1,6 @@
|
||||
from flask_wtf import FlaskForm
|
||||
from wtforms import SubmitField
|
||||
|
||||
|
||||
class OCRJobForm(FlaskForm):
|
||||
submit = SubmitField('Submit')
|
43
app/services/views.py
Normal file
43
app/services/views.py
Normal file
@ -0,0 +1,43 @@
|
||||
from flask import redirect, render_template, url_for
|
||||
from . import services
|
||||
from flask_login import current_user, login_required
|
||||
from .forms import OCRJobForm
|
||||
from ..import swarm
|
||||
from threading import Thread
|
||||
|
||||
|
||||
@services.route('/ocr', methods=['GET', 'POST'])
|
||||
@login_required
|
||||
def ocr():
|
||||
ocr_job_form = OCRJobForm()
|
||||
if ocr_job_form.validate_on_submit():
|
||||
'''
|
||||
' TODO: Implement a Job class. For now a dictionary representation is
|
||||
' enough.
|
||||
'''
|
||||
job = {'worker': None,
|
||||
'creator': current_user.id,
|
||||
'id': '5fd40cb0cadef3ab5676c4968fc3d748',
|
||||
'requested_cpus': 2,
|
||||
'requested_memory': 2048,
|
||||
'service': 'ocr',
|
||||
'service_args': {'lang': 'eng',
|
||||
'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 render_template(
|
||||
'services/ocr.html.j2',
|
||||
title='Optical Character Recognition',
|
||||
ocr_job_form=ocr_job_form
|
||||
)
|
@ -9,16 +9,4 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col s12">
|
||||
<div class="card large">
|
||||
<div class="card-content">
|
||||
<span class="card-title">Swarm</span>
|
||||
<form method="POST">
|
||||
{{ swarm_form.hidden_tag() }}
|
||||
{{ swarm_form.submit(class='btn') }}
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
15
app/templates/services/ocr.html.j2
Normal file
15
app/templates/services/ocr.html.j2
Normal file
@ -0,0 +1,15 @@
|
||||
{% extends "base.html.j2" %}
|
||||
|
||||
{% block page_content %}
|
||||
<div class="col s12">
|
||||
<div class="card large">
|
||||
<div class="card-content">
|
||||
<span class="card-title">OCR</span>
|
||||
<form method="POST">
|
||||
{{ ocr_job_form.hidden_tag() }}
|
||||
{{ ocr_job_form.submit(class='btn') }}
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{% endblock %}
|
Loading…
Reference in New Issue
Block a user