From 1faa98b4e8cd8ecfa1aa7ae3dbc5f8feef0cb80f Mon Sep 17 00:00:00 2001 From: Inga Kirschnick Date: Wed, 26 Oct 2022 12:02:53 +0200 Subject: [PATCH] Adjustment Contribution Package --- app/contributions/forms.py | 2 +- app/contributions/routes.py | 8 +++--- app/models.py | 49 ------------------------------------- 3 files changed, 5 insertions(+), 54 deletions(-) diff --git a/app/contributions/forms.py b/app/contributions/forms.py index d123e6d1..44279a1d 100644 --- a/app/contributions/forms.py +++ b/app/contributions/forms.py @@ -11,7 +11,7 @@ from wtforms.validators import InputRequired, Length from app.services import SERVICES -class ContributionForm(FlaskForm): +class TesseractOCRModelContributionForm(FlaskForm): title = StringField( 'Title', validators=[InputRequired(), Length(max=64)] diff --git a/app/contributions/routes.py b/app/contributions/routes.py index d82bf511..287eda18 100644 --- a/app/contributions/routes.py +++ b/app/contributions/routes.py @@ -2,9 +2,9 @@ from flask import abort, flash, Markup, render_template, url_for from flask_login import login_required from app import db from app.decorators import permission_required -from app.models import TesseractOCRModel, Permission +from app.models import TesseractOCRPipelineModel, Permission from . import bp -from .forms import ContributionForm +from .forms import TesseractOCRModelContributionForm @bp.before_request @@ -21,7 +21,7 @@ def contributions(): @bp.route('/tesseract-ocr-pipeline-models', methods=['GET', 'POST']) def tesseract_ocr_pipeline_models(): - form = ContributionForm( + form = TesseractOCRModelContributionForm( prefix='contribute-tesseract-ocr-pipeline-model-form' ) if form.is_submitted(): @@ -29,7 +29,7 @@ def tesseract_ocr_pipeline_models(): response = {'errors': form.errors} return response, 400 try: - tesseract_ocr_model = TesseractOCRModel.create( + tesseract_ocr_model = TesseractOCRPipelineModel.create( form.file.data, compatible_service_versions=form.compatible_service_versions.data, description=form.description.data, diff --git a/app/models.py b/app/models.py index c0cedf21..cc5d60ce 100644 --- a/app/models.py +++ b/app/models.py @@ -620,55 +620,6 @@ class TesseractOCRPipelineModel(FileMixin, HashidMixin, db.Model): _json['user'] = self.user.to_json(backrefs=True) return _json - @staticmethod - def create(model_file, **kwargs): # ??? Ist das so richtig? übergeben wir das form? Im anderen Fall ist das nicht so .. aber was soll hier überhaupt rein? - filename = kwargs.get('filename', model_file.filename) - mimetype = kwargs.get('mimetype', model_file.mimetype) - tesseract_ocr_model = TesseractOCRModel( - filename=secure_filename(filename), - mimetype=mimetype, - **kwargs - ) - - db.session.add(tesseract_ocr_model) - db.session.flush(objects=[tesseract_ocr_model]) - db.session.refresh(tesseract_ocr_model) - try: - # ??? Woher soll file kommen? Wir haben der methode das ganze form übergeben. - # filename = form.file.data.filename - model_file.save(tesseract_ocr_model.path) - except OSError as e: - current_app.logger.error(e) - db.session.rollback() - raise e - return tesseract_ocr_model - - - # Kann man das so committen? - # db.session.add(model) - # db.session.flush(objects=[model]) - # db.session.refresh(model) - # model.filename = f'{model.id}.traineddata' - # r = requests.get(m['url'], stream=True) - # pbar = tqdm( - # desc=f'{model.title} ({model.filename})', - # unit="B", - # unit_scale=True, - # unit_divisor=1024, - # total=int(r.headers['Content-Length']) - # ) - # pbar.clear() - # with open(model.path, 'wb') as f: - # for chunk in r.iter_content(chunk_size=1024): - # if chunk: # filter out keep-alive new chunks - # pbar.update(len(chunk)) - # f.write(chunk) - # pbar.close() - # - # db.session.commit() - - - class SpaCyNLPPipelineModel(FileMixin, HashidMixin, db.Model): __tablename__ = 'spacy_nlp_pipeline_models'