Addition pipeline_name in Contribution Package

This commit is contained in:
Inga Kirschnick 2022-11-14 15:02:41 +01:00
parent 6164c3e7d9
commit df5ae19e68
4 changed files with 31 additions and 5 deletions

View File

@ -58,6 +58,18 @@ class EditForm(CreateContributionBaseForm):
self.version.data = model_file.version self.version.data = model_file.version
self.shared.data = model_file.shared self.shared.data = model_file.shared
class EditTesseractOCRModelForm(EditForm):
pass
class EditSpaCyNLPPipelineModelForm(EditForm):
pipeline_name = StringField(
'Pipeline name',
validators=[InputRequired(), Length(max=64)]
)
def prefill(self, model_file):
super().prefill(model_file)
self.pipeline_name.data = model_file.pipeline_name
class TesseractOCRModelContributionForm(CreateContributionBaseForm): class TesseractOCRModelContributionForm(CreateContributionBaseForm):
tesseract_model_file = FileField( tesseract_model_file = FileField(
'File', 'File',
@ -88,6 +100,10 @@ class SpacyNLPModelContributionForm(CreateContributionBaseForm):
compatible_service_versions = SelectMultipleField( compatible_service_versions = SelectMultipleField(
'Compatible service versions' 'Compatible service versions'
) )
pipeline_name = StringField(
'Pipeline name',
validators=[InputRequired(), Length(max=64)]
)
def validate_spacy_model_file(self, field): def validate_spacy_model_file(self, field):
current_app.logger.warning(field.data.filename) current_app.logger.warning(field.data.filename)
if not field.data.filename.lower().endswith('.tar.gz'): if not field.data.filename.lower().endswith('.tar.gz'):

View File

@ -5,7 +5,7 @@ from app import db
from app.decorators import admin_required, permission_required from app.decorators import admin_required, permission_required
from app.models import Permission, SpaCyNLPPipelineModel, TesseractOCRPipelineModel from app.models import Permission, SpaCyNLPPipelineModel, TesseractOCRPipelineModel
from . import bp from . import bp
from .forms import TesseractOCRModelContributionForm, EditForm, SpacyNLPModelContributionForm from .forms import TesseractOCRModelContributionForm, EditSpaCyNLPPipelineModelForm, EditTesseractOCRModelForm, SpacyNLPModelContributionForm
@bp.before_request @bp.before_request
@ -39,7 +39,7 @@ def tesseract_ocr_pipeline_model(tesseract_ocr_pipeline_model_id):
tesseract_ocr_pipeline_model = TesseractOCRPipelineModel.query.get_or_404( tesseract_ocr_pipeline_model = TesseractOCRPipelineModel.query.get_or_404(
tesseract_ocr_pipeline_model_id tesseract_ocr_pipeline_model_id
) )
form = EditForm(prefix='tesseract-ocr-model-edit-form') form = EditTesseractOCRModelForm(prefix='tesseract-ocr-model-edit-form')
if form.validate_on_submit(): if form.validate_on_submit():
if tesseract_ocr_pipeline_model.title != form.title.data: if tesseract_ocr_pipeline_model.title != form.title.data:
tesseract_ocr_pipeline_model.title = form.title.data tesseract_ocr_pipeline_model.title = form.title.data
@ -134,12 +134,14 @@ def spacy_nlp_pipeline_model(spacy_nlp_pipeline_model_id):
spacy_nlp_pipeline_model = SpaCyNLPPipelineModel.query.get_or_404( spacy_nlp_pipeline_model = SpaCyNLPPipelineModel.query.get_or_404(
spacy_nlp_pipeline_model_id spacy_nlp_pipeline_model_id
) )
form = EditForm(prefix='spacy-nlp-model-edit-form') form = EditSpaCyNLPPipelineModelForm(prefix='spacy-nlp-model-edit-form')
if form.validate_on_submit(): if form.validate_on_submit():
if spacy_nlp_pipeline_model.title != form.title.data: if spacy_nlp_pipeline_model.title != form.title.data:
spacy_nlp_pipeline_model.title = form.title.data spacy_nlp_pipeline_model.title = form.title.data
if spacy_nlp_pipeline_model.description != form.description.data: if spacy_nlp_pipeline_model.description != form.description.data:
spacy_nlp_pipeline_model.description = form.description.data spacy_nlp_pipeline_model.description = form.description.data
if spacy_nlp_pipeline_model.pipeline_name != form.pipeline_name.data:
spacy_nlp_pipeline_model.pipeline_name = form.pipeline_name.data
if spacy_nlp_pipeline_model.publisher != form.publisher.data: if spacy_nlp_pipeline_model.publisher != form.publisher.data:
spacy_nlp_pipeline_model.publisher = form.publisher.data spacy_nlp_pipeline_model.publisher = form.publisher.data
if spacy_nlp_pipeline_model.publishing_year != form.publishing_year.data: if spacy_nlp_pipeline_model.publishing_year != form.publishing_year.data:
@ -156,6 +158,7 @@ def spacy_nlp_pipeline_model(spacy_nlp_pipeline_model_id):
message = Markup(f'Model "<a href="contribute/{spacy_nlp_pipeline_model.hashid}">{spacy_nlp_pipeline_model.title}</a>" updated') message = Markup(f'Model "<a href="contribute/{spacy_nlp_pipeline_model.hashid}">{spacy_nlp_pipeline_model.title}</a>" updated')
flash(message, category='corpus') flash(message, category='corpus')
return {}, 201, {'Location': url_for('contributions.contributions')} return {}, 201, {'Location': url_for('contributions.contributions')}
print(spacy_nlp_pipeline_model.to_json())
form.prefill(spacy_nlp_pipeline_model) form.prefill(spacy_nlp_pipeline_model)
return render_template( return render_template(
'contributions/spacy_nlp_pipeline_model.html.j2', 'contributions/spacy_nlp_pipeline_model.html.j2',
@ -195,6 +198,7 @@ def add_spacy_nlp_pipeline_model():
form.spacy_model_file.data, form.spacy_model_file.data,
compatible_service_versions=form.compatible_service_versions.data, compatible_service_versions=form.compatible_service_versions.data,
description=form.description.data, description=form.description.data,
pipeline_name=form.pipeline_name.data,
publisher=form.publisher.data, publisher=form.publisher.data,
publisher_url=form.publisher_url.data, publisher_url=form.publisher_url.data,
publishing_url=form.publishing_url.data, publishing_url=form.publishing_url.data,

View File

@ -2,7 +2,7 @@
{% import "materialize/wtf.html.j2" as wtf %} {% import "materialize/wtf.html.j2" as wtf %}
{% from "contributions/_breadcrumbs.html.j2" import breadcrumbs with context %} {% from "contributions/_breadcrumbs.html.j2" import breadcrumbs with context %}
{% block main_attribs %} class="service-scheme" data-service="tesseract-ocr-pipeline"{% endblock main_attribs %} {% block main_attribs %} class="service-scheme" data-service="spacy-nlp-pipeline"{% endblock main_attribs %}
{% block page_content %} {% block page_content %}
<div class="container"> <div class="container">
@ -28,7 +28,7 @@
<div class="col s12"> <div class="col s12">
<div class="card-panel z-depth-0"> <div class="card-panel z-depth-0">
<span class="card-title"><i class="left material-icons">layers</i>spaCy NLP Models</span> <span class="card-title"><i class="left material-icons">layers</i>spaCy NLP Models</span>
<p>You can add more Tesseract OCR models using the form below. They will automatically appear in the list of usable models.</p> <p>You can add more spaCy NLP models using the form below. They will automatically appear in the list of usable models.</p>
<p><a href="">Edit already uploaded models</a></p> <p><a href="">Edit already uploaded models</a></p>
<p><a class="modal-trigger" href="#models-modal">Information about the already existing models.</a></p> <p><a class="modal-trigger" href="#models-modal">Information about the already existing models.</a></p>
</div> </div>
@ -54,6 +54,9 @@
<div class="col s12"> <div class="col s12">
{{ wtf.render_field(form.description, material_icon='description') }} {{ wtf.render_field(form.description, material_icon='description') }}
</div> </div>
<div class="col s12">
{{ wtf.render_field(form.pipeline_name, material_icon='emoji_objects') }}
</div>
<div class="col s12 l6"> <div class="col s12 l6">
{{ wtf.render_field(form.publisher, material_icon='account_balance') }} {{ wtf.render_field(form.publisher, material_icon='account_balance') }}
</div> </div>

View File

@ -23,6 +23,9 @@
<div class="col s12"> <div class="col s12">
{{ wtf.render_field(form.description, material_icon='description') }} {{ wtf.render_field(form.description, material_icon='description') }}
</div> </div>
<div class="col s12">
{{ wtf.render_field(form.pipeline_name, material_icon='emoji_objects') }}
</div>
<div class="col s12 l6"> <div class="col s12 l6">
{{ wtf.render_field(form.publisher, material_icon='account_balance') }} {{ wtf.render_field(form.publisher, material_icon='account_balance') }}
</div> </div>