2022-11-08 13:11:57 +00:00
|
|
|
from flask import current_app
|
2022-10-02 21:49:14 +00:00
|
|
|
from flask_wtf import FlaskForm
|
2022-10-25 11:07:10 +00:00
|
|
|
from flask_wtf.file import FileField, FileRequired
|
2022-10-02 21:49:14 +00:00
|
|
|
from wtforms import (
|
|
|
|
BooleanField,
|
|
|
|
StringField,
|
|
|
|
SubmitField,
|
|
|
|
SelectMultipleField,
|
2022-11-03 14:38:35 +00:00
|
|
|
IntegerField,
|
|
|
|
ValidationError
|
2022-10-02 21:49:14 +00:00
|
|
|
)
|
2022-10-26 08:12:54 +00:00
|
|
|
from wtforms.validators import InputRequired, Length
|
|
|
|
from app.services import SERVICES
|
2022-10-02 21:49:14 +00:00
|
|
|
|
2022-11-15 14:11:16 +00:00
|
|
|
|
2022-11-17 09:46:16 +00:00
|
|
|
class ContributionBaseForm(FlaskForm):
|
2022-10-02 21:49:14 +00:00
|
|
|
title = StringField(
|
|
|
|
'Title',
|
|
|
|
validators=[InputRequired(), Length(max=64)]
|
|
|
|
)
|
|
|
|
description = StringField(
|
|
|
|
'Description',
|
|
|
|
validators=[InputRequired(), Length(max=255)]
|
|
|
|
)
|
|
|
|
version = StringField(
|
|
|
|
'Version',
|
|
|
|
validators=[InputRequired(), Length(max=16)]
|
|
|
|
)
|
|
|
|
publisher = StringField(
|
|
|
|
'Publisher',
|
|
|
|
validators=[InputRequired(), Length(max=128)]
|
|
|
|
)
|
|
|
|
publisher_url = StringField(
|
|
|
|
'Publisher URL',
|
|
|
|
validators=[InputRequired(), Length(max=512)]
|
|
|
|
)
|
|
|
|
publishing_url = StringField(
|
|
|
|
'Publishing URL',
|
|
|
|
validators=[InputRequired(), Length(max=512)]
|
|
|
|
)
|
|
|
|
publishing_year = IntegerField(
|
|
|
|
'Publishing year',
|
|
|
|
validators=[InputRequired()]
|
|
|
|
)
|
2022-11-17 11:48:19 +00:00
|
|
|
compatible_service_versions = SelectMultipleField(
|
|
|
|
'Compatible service versions'
|
|
|
|
)
|
2022-10-02 21:49:14 +00:00
|
|
|
submit = SubmitField()
|
|
|
|
|
2022-11-14 14:02:41 +00:00
|
|
|
|
2022-11-17 09:46:16 +00:00
|
|
|
class CreateTesseractOCRPipelineModelForm(ContributionBaseForm):
|
2022-11-03 14:38:35 +00:00
|
|
|
tesseract_model_file = FileField(
|
|
|
|
'File',
|
|
|
|
validators=[FileRequired()]
|
|
|
|
)
|
2022-11-17 11:48:19 +00:00
|
|
|
|
2022-11-08 13:11:57 +00:00
|
|
|
def validate_tesseract_model_file(self, field):
|
|
|
|
current_app.logger.warning(field.data.filename)
|
|
|
|
if not field.data.filename.lower().endswith('.traineddata'):
|
2022-11-03 14:38:35 +00:00
|
|
|
raise ValidationError('traineddata files only!')
|
2022-10-02 21:49:14 +00:00
|
|
|
|
2022-10-26 08:12:54 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
service_manifest = SERVICES['tesseract-ocr-pipeline']
|
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
self.compatible_service_versions.choices = [('', 'Choose your option')]
|
|
|
|
self.compatible_service_versions.choices += [
|
|
|
|
(x, x) for x in service_manifest['versions'].keys()
|
|
|
|
]
|
|
|
|
self.compatible_service_versions.default = ''
|
2022-11-03 14:38:35 +00:00
|
|
|
|
2022-11-15 14:11:16 +00:00
|
|
|
|
2022-11-17 09:46:16 +00:00
|
|
|
class CreateSpaCyNLPPipelineModelForm(ContributionBaseForm):
|
2022-11-07 08:15:38 +00:00
|
|
|
spacy_model_file = FileField(
|
|
|
|
'File',
|
|
|
|
validators=[FileRequired()]
|
|
|
|
)
|
2022-11-14 14:02:41 +00:00
|
|
|
pipeline_name = StringField(
|
|
|
|
'Pipeline name',
|
|
|
|
validators=[InputRequired(), Length(max=64)]
|
|
|
|
)
|
2022-11-15 14:11:16 +00:00
|
|
|
|
2022-11-08 13:11:57 +00:00
|
|
|
def validate_spacy_model_file(self, field):
|
|
|
|
current_app.logger.warning(field.data.filename)
|
|
|
|
if not field.data.filename.lower().endswith('.tar.gz'):
|
2022-11-07 08:15:38 +00:00
|
|
|
raise ValidationError('.tar.gz files only!')
|
2022-11-03 14:38:35 +00:00
|
|
|
|
2022-11-07 08:15:38 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super().__init__(*args, **kwargs)
|
2022-11-15 14:11:16 +00:00
|
|
|
service_manifest = SERVICES['spacy-nlp-pipeline']
|
2022-11-07 08:15:38 +00:00
|
|
|
self.compatible_service_versions.choices = [('', 'Choose your option')]
|
|
|
|
self.compatible_service_versions.choices += [
|
|
|
|
(x, x) for x in service_manifest['versions'].keys()
|
|
|
|
]
|
|
|
|
self.compatible_service_versions.default = ''
|
2022-11-15 14:11:16 +00:00
|
|
|
|
|
|
|
|
2022-11-17 09:46:16 +00:00
|
|
|
class EditContributionBaseForm(ContributionBaseForm):
|
|
|
|
pass
|
2022-11-15 14:11:16 +00:00
|
|
|
|
|
|
|
class EditTesseractOCRPipelineModelForm(EditContributionBaseForm):
|
2022-11-17 11:48:19 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
service_manifest = SERVICES['tesseract-ocr-pipeline']
|
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
self.compatible_service_versions.choices = [('', 'Choose your option')]
|
|
|
|
self.compatible_service_versions.choices += [
|
|
|
|
(x, x) for x in service_manifest['versions'].keys()
|
|
|
|
]
|
|
|
|
self.compatible_service_versions.default = ''
|
2022-11-15 14:11:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
class EditSpaCyNLPPipelineModelForm(EditContributionBaseForm):
|
|
|
|
pipeline_name = StringField(
|
|
|
|
'Pipeline name',
|
|
|
|
validators=[InputRequired(), Length(max=64)]
|
|
|
|
)
|
2022-11-17 11:48:19 +00:00
|
|
|
def __init__(self, *args, **kwargs):
|
|
|
|
super().__init__(*args, **kwargs)
|
|
|
|
service_manifest = SERVICES['spacy-nlp-pipeline']
|
|
|
|
self.compatible_service_versions.choices = [('', 'Choose your option')]
|
|
|
|
self.compatible_service_versions.choices += [
|
|
|
|
(x, x) for x in service_manifest['versions'].keys()
|
|
|
|
]
|
|
|
|
self.compatible_service_versions.default = ''
|