mirror of
https://gitlab.ub.uni-bielefeld.de/sfb1288inf/nopaque.git
synced 2024-11-14 16:55:42 +00:00
Implement force download parameter in model insert_defaults methods
This commit is contained in:
parent
bdcc80a66f
commit
9c22370eea
@ -953,7 +953,7 @@ class TesseractOCRPipelineModel(FileMixin, HashidMixin, db.Model):
|
|||||||
return self.user.hashid
|
return self.user.hashid
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def insert_defaults():
|
def insert_defaults(force_download=False):
|
||||||
nopaque_user = User.query.filter_by(username='nopaque').first()
|
nopaque_user = User.query.filter_by(username='nopaque').first()
|
||||||
defaults_file = os.path.join(
|
defaults_file = os.path.join(
|
||||||
os.path.dirname(os.path.abspath(__file__)),
|
os.path.dirname(os.path.abspath(__file__)),
|
||||||
@ -966,6 +966,7 @@ class TesseractOCRPipelineModel(FileMixin, HashidMixin, db.Model):
|
|||||||
if model is not None:
|
if model is not None:
|
||||||
model.compatible_service_versions = m['compatible_service_versions']
|
model.compatible_service_versions = m['compatible_service_versions']
|
||||||
model.description = m['description']
|
model.description = m['description']
|
||||||
|
model.filename = f'{model.id}.traineddata'
|
||||||
model.publisher = m['publisher']
|
model.publisher = m['publisher']
|
||||||
model.publisher_url = m['publisher_url']
|
model.publisher_url = m['publisher_url']
|
||||||
model.publishing_url = m['publishing_url']
|
model.publishing_url = m['publishing_url']
|
||||||
@ -973,7 +974,7 @@ class TesseractOCRPipelineModel(FileMixin, HashidMixin, db.Model):
|
|||||||
model.is_public = True
|
model.is_public = True
|
||||||
model.title = m['title']
|
model.title = m['title']
|
||||||
model.version = m['version']
|
model.version = m['version']
|
||||||
continue
|
else:
|
||||||
model = TesseractOCRPipelineModel(
|
model = TesseractOCRPipelineModel(
|
||||||
compatible_service_versions=m['compatible_service_versions'],
|
compatible_service_versions=m['compatible_service_versions'],
|
||||||
description=m['description'],
|
description=m['description'],
|
||||||
@ -990,6 +991,7 @@ class TesseractOCRPipelineModel(FileMixin, HashidMixin, db.Model):
|
|||||||
db.session.flush(objects=[model])
|
db.session.flush(objects=[model])
|
||||||
db.session.refresh(model)
|
db.session.refresh(model)
|
||||||
model.filename = f'{model.id}.traineddata'
|
model.filename = f'{model.id}.traineddata'
|
||||||
|
if not os.path.exists(model.path) or force_download:
|
||||||
r = requests.get(m['url'], stream=True)
|
r = requests.get(m['url'], stream=True)
|
||||||
pbar = tqdm(
|
pbar = tqdm(
|
||||||
desc=f'{model.title} ({model.filename})',
|
desc=f'{model.title} ({model.filename})',
|
||||||
@ -1080,7 +1082,7 @@ class SpaCyNLPPipelineModel(FileMixin, HashidMixin, db.Model):
|
|||||||
return self.user.hashid
|
return self.user.hashid
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def insert_defaults():
|
def insert_defaults(force_download=False):
|
||||||
nopaque_user = User.query.filter_by(username='nopaque').first()
|
nopaque_user = User.query.filter_by(username='nopaque').first()
|
||||||
defaults_file = os.path.join(
|
defaults_file = os.path.join(
|
||||||
os.path.dirname(os.path.abspath(__file__)),
|
os.path.dirname(os.path.abspath(__file__)),
|
||||||
@ -1093,6 +1095,7 @@ class SpaCyNLPPipelineModel(FileMixin, HashidMixin, db.Model):
|
|||||||
if model is not None:
|
if model is not None:
|
||||||
model.compatible_service_versions = m['compatible_service_versions']
|
model.compatible_service_versions = m['compatible_service_versions']
|
||||||
model.description = m['description']
|
model.description = m['description']
|
||||||
|
model.filename = m['url'].split('/')[-1]
|
||||||
model.publisher = m['publisher']
|
model.publisher = m['publisher']
|
||||||
model.publisher_url = m['publisher_url']
|
model.publisher_url = m['publisher_url']
|
||||||
model.publishing_url = m['publishing_url']
|
model.publishing_url = m['publishing_url']
|
||||||
@ -1101,10 +1104,11 @@ class SpaCyNLPPipelineModel(FileMixin, HashidMixin, db.Model):
|
|||||||
model.title = m['title']
|
model.title = m['title']
|
||||||
model.version = m['version']
|
model.version = m['version']
|
||||||
model.pipeline_name = m['pipeline_name']
|
model.pipeline_name = m['pipeline_name']
|
||||||
continue
|
else:
|
||||||
model = SpaCyNLPPipelineModel(
|
model = SpaCyNLPPipelineModel(
|
||||||
compatible_service_versions=m['compatible_service_versions'],
|
compatible_service_versions=m['compatible_service_versions'],
|
||||||
description=m['description'],
|
description=m['description'],
|
||||||
|
filename=m['url'].split('/')[-1],
|
||||||
publisher=m['publisher'],
|
publisher=m['publisher'],
|
||||||
publisher_url=m['publisher_url'],
|
publisher_url=m['publisher_url'],
|
||||||
publishing_url=m['publishing_url'],
|
publishing_url=m['publishing_url'],
|
||||||
@ -1118,7 +1122,7 @@ class SpaCyNLPPipelineModel(FileMixin, HashidMixin, db.Model):
|
|||||||
db.session.add(model)
|
db.session.add(model)
|
||||||
db.session.flush(objects=[model])
|
db.session.flush(objects=[model])
|
||||||
db.session.refresh(model)
|
db.session.refresh(model)
|
||||||
model.filename = m['url'].split('/')[-1]
|
if not os.path.exists(model.path) or force_download:
|
||||||
r = requests.get(m['url'], stream=True)
|
r = requests.get(m['url'], stream=True)
|
||||||
pbar = tqdm(
|
pbar = tqdm(
|
||||||
desc=f'{model.title} ({model.filename})',
|
desc=f'{model.title} ({model.filename})',
|
||||||
|
Loading…
Reference in New Issue
Block a user