diff --git a/app/services/forms.py b/app/services/forms.py index 174bdb71..7c244f48 100644 --- a/app/services/forms.py +++ b/app/services/forms.py @@ -84,12 +84,18 @@ class CreateTesseractOCRPipelineJobForm(CreateJobBaseForm): del self.binarization.render_kw['disabled'] if 'ocropus_nlbin_threshold' in service_info['methods']: del self.ocropus_nlbin_threshold.render_kw['disabled'] + user_models = [ + x for x in current_user.tesseract_ocr_pipeline_models.order_by(TesseractOCRPipelineModel.title).all() + ] models = [ x for x in TesseractOCRPipelineModel.query.order_by(TesseractOCRPipelineModel.title).all() if version in x.compatible_service_versions and (x.is_public == True or x.user == current_user) ] - self.model.choices = [('', 'Choose your option')] - self.model.choices += [(x.hashid, f'{x.title} [{x.version}]') for x in models] + self.model.choices = { + '': [('', 'Choose your option')], + 'Your models': [(x.hashid, f'{x.title} [{x.version}]') for x in user_models] if user_models else [(0, 'Nothing here yet...')], + 'Public models': [(x.hashid, f'{x.title} [{x.version}]') for x in models] + } self.model.default = '' self.version.choices = [(x, x) for x in service_manifest['versions']] self.version.data = version @@ -177,7 +183,7 @@ class CreateSpacyNLPPipelineJobForm(CreateJobBaseForm): ] self.model.choices = { '': [('', 'Choose your option')], - 'Your models': [(x.hashid, f'{x.title} [{x.version}]') for x in user_models], + 'Your models': [(x.hashid, f'{x.title} [{x.version}]') for x in user_models] if user_models else [(0, 'Nothing here yet...')], 'Public models': [(x.hashid, f'{x.title} [{x.version}]') for x in models] } self.model.default = '' diff --git a/app/services/routes.py b/app/services/routes.py index 0a8c2811..9f4cfdc0 100644 --- a/app/services/routes.py +++ b/app/services/routes.py @@ -107,11 +107,13 @@ def tesseract_ocr_pipeline(): x for x in TesseractOCRPipelineModel.query.all() if version in x.compatible_service_versions and (x.is_public == True or x.user == current_user) ] + user_tesseract_ocr_pipeline_models_count = len(current_user.tesseract_ocr_pipeline_models.all()) return render_template( 'services/tesseract_ocr_pipeline.html.j2', title=service_manifest['name'], form=form, - tesseract_ocr_pipeline_models=tesseract_ocr_pipeline_models + tesseract_ocr_pipeline_models=tesseract_ocr_pipeline_models, + user_tesseract_ocr_pipeline_models_count=user_tesseract_ocr_pipeline_models_count ) @@ -183,6 +185,7 @@ def spacy_nlp_pipeline(): abort(404) form = CreateSpacyNLPPipelineJobForm(prefix='create-job-form', version=version) spacy_nlp_pipeline_models = SpaCyNLPPipelineModel.query.all() + user_spacy_nlp_pipeline_models_count = len(current_user.spacy_nlp_pipeline_models.all()) if form.is_submitted(): if not form.validate(): response = {'errors': form.errors} @@ -214,7 +217,8 @@ def spacy_nlp_pipeline(): 'services/spacy_nlp_pipeline.html.j2', title=service_manifest['name'], form=form, - spacy_nlp_pipeline_models=spacy_nlp_pipeline_models + spacy_nlp_pipeline_models=spacy_nlp_pipeline_models, + user_spacy_nlp_pipeline_models_count=user_spacy_nlp_pipeline_models_count ) diff --git a/app/templates/services/spacy_nlp_pipeline.html.j2 b/app/templates/services/spacy_nlp_pipeline.html.j2 index 2ebba838..a7bf214c 100644 --- a/app/templates/services/spacy_nlp_pipeline.html.j2 +++ b/app/templates/services/spacy_nlp_pipeline.html.j2 @@ -163,3 +163,14 @@ {% endblock modals %} + +{% block scripts %} +{{ super() }} + +{% endblock scripts %} diff --git a/app/templates/services/tesseract_ocr_pipeline.html.j2 b/app/templates/services/tesseract_ocr_pipeline.html.j2 index 9b1d6187..69be6889 100644 --- a/app/templates/services/tesseract_ocr_pipeline.html.j2 +++ b/app/templates/services/tesseract_ocr_pipeline.html.j2 @@ -147,6 +147,13 @@ {% block scripts %} {{ super() }}