From ad17ec2cc82c9b9e3435ef4a6b5ed7373e4cece6 Mon Sep 17 00:00:00 2001
From: Inga Kirschnick <inga.kirschnick@uni-bielefeld.de>
Date: Wed, 9 Nov 2022 13:51:42 +0100
Subject: [PATCH] Preliminary work for nlp model runtime integration

---
 app/contributions/routes.py |  2 --
 app/daemon/job_utils.py     | 13 ++++++++++++-
 2 files changed, 12 insertions(+), 3 deletions(-)

diff --git a/app/contributions/routes.py b/app/contributions/routes.py
index b63a43ec..c20774d7 100644
--- a/app/contributions/routes.py
+++ b/app/contributions/routes.py
@@ -25,8 +25,6 @@ def contributions():
     spacy_nlp_user_models = [
         x for x in current_user.spacy_nlp_pipeline_models
     ]
-    spacy_models = SpaCyNLPPipelineModel.query.all()
-    print(spacy_models)
     return render_template(
         'contributions/contribution_overview.html.j2',
         tesseract_ocr_user_models=tesseract_ocr_user_models,
diff --git a/app/daemon/job_utils.py b/app/daemon/job_utils.py
index 32def73d..518100f7 100644
--- a/app/daemon/job_utils.py
+++ b/app/daemon/job_utils.py
@@ -3,7 +3,8 @@ from app.models import (
     Job,
     JobResult,
     JobStatus,
-    TesseractOCRPipelineModel
+    TesseractOCRPipelineModel,
+    SpaCyNLPPipelineModel
 )
 from datetime import datetime
 from flask import current_app
@@ -103,6 +104,16 @@ def _create_job_service(job):
         models_mount_target = f'/usr/local/share/tessdata/{model.filename}'
         models_mount = f'{models_mount_source}:{models_mount_target}:ro'
         mounts.append(models_mount)
+    elif job.service == 'spacy-nlp-pipeline':
+        model_id = hashids.decode(job.service_args['model'])
+        model = SpaCyNLPPipelineModel.query.get(model_id)
+        if model is None:
+            job.status = JobStatus.FAILED
+            return
+        models_mount_source = model.path
+        models_mount_target = f'/usr/local/share/spacy/models/{model.filename}'
+        models_mount = f'{models_mount_source}:{models_mount_target}:ro'
+        mounts.append(models_mount)
     ''' ### Output mount ### '''
     output_mount_source = os.path.join(job.path, 'results')
     output_mount_target = '/output'
-- 
GitLab