mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-11-15 01:05:42 +00:00
Adjustment Contribution Package
This commit is contained in:
parent
6f353684e7
commit
1faa98b4e8
@ -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)]
|
||||
|
@ -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,
|
||||
|
@ -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'
|
||||
|
Loading…
Reference in New Issue
Block a user