Adjustment Contribution Package

This commit is contained in:
Inga Kirschnick 2022-10-26 12:02:53 +02:00
parent 6f353684e7
commit 1faa98b4e8
3 changed files with 5 additions and 54 deletions

View File

@ -11,7 +11,7 @@ from wtforms.validators import InputRequired, Length
from app.services import SERVICES from app.services import SERVICES
class ContributionForm(FlaskForm): class TesseractOCRModelContributionForm(FlaskForm):
title = StringField( title = StringField(
'Title', 'Title',
validators=[InputRequired(), Length(max=64)] validators=[InputRequired(), Length(max=64)]

View File

@ -2,9 +2,9 @@ from flask import abort, flash, Markup, render_template, url_for
from flask_login import login_required from flask_login import login_required
from app import db from app import db
from app.decorators import permission_required from app.decorators import permission_required
from app.models import TesseractOCRModel, Permission from app.models import TesseractOCRPipelineModel, Permission
from . import bp from . import bp
from .forms import ContributionForm from .forms import TesseractOCRModelContributionForm
@bp.before_request @bp.before_request
@ -21,7 +21,7 @@ def contributions():
@bp.route('/tesseract-ocr-pipeline-models', methods=['GET', 'POST']) @bp.route('/tesseract-ocr-pipeline-models', methods=['GET', 'POST'])
def tesseract_ocr_pipeline_models(): def tesseract_ocr_pipeline_models():
form = ContributionForm( form = TesseractOCRModelContributionForm(
prefix='contribute-tesseract-ocr-pipeline-model-form' prefix='contribute-tesseract-ocr-pipeline-model-form'
) )
if form.is_submitted(): if form.is_submitted():
@ -29,7 +29,7 @@ def tesseract_ocr_pipeline_models():
response = {'errors': form.errors} response = {'errors': form.errors}
return response, 400 return response, 400
try: try:
tesseract_ocr_model = TesseractOCRModel.create( tesseract_ocr_model = TesseractOCRPipelineModel.create(
form.file.data, form.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,

View File

@ -620,55 +620,6 @@ class TesseractOCRPipelineModel(FileMixin, HashidMixin, db.Model):
_json['user'] = self.user.to_json(backrefs=True) _json['user'] = self.user.to_json(backrefs=True)
return _json 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): class SpaCyNLPPipelineModel(FileMixin, HashidMixin, db.Model):
__tablename__ = 'spacy_nlp_pipeline_models' __tablename__ = 'spacy_nlp_pipeline_models'