Skip to content

Commit cb3d7c5

Browse files
authored
bug(medcat-demo-app): CU-869azbdfh Fail without model (#197)
* CU-869azbdfh: Avoid running the container without a loaded model * CU-869azbdfh: Remove unused env variables * CU-869azbdfh: Avoid loading model pack at module import
1 parent 1161447 commit cb3d7c5

File tree

2 files changed

+6
-13
lines changed

2 files changed

+6
-13
lines changed

medcat-demo-app/webapp/Dockerfile

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,6 @@ COPY --from=build /webapp /webapp
5555
# Copy Python site-packages (installed by pip) from build stage
5656
COPY --from=build /usr/local/lib/python3.12/site-packages /usr/local/lib/python3.12/site-packages
5757

58-
# Set environment variables
59-
ENV VOCAB_URL=https://medcat.rosalind.kcl.ac.uk/media/vocab.dat
60-
ENV CDB_URL=https://medcat.rosalind.kcl.ac.uk/media/cdb-medmen-v1.dat
61-
62-
ENV CDB_PATH=/webapp/models/cdb.dat
63-
ENV VOCAB_PATH=/webapp/models/vocab.dat
64-
6558
# Set the pythonpath
6659
WORKDIR /webapp
6760

medcat-demo-app/webapp/demo/views.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,12 @@
1010
from wsgiref.util import FileWrapper
1111
from medcat import __version__ as medcat_version
1212
from medcat.cat import CAT
13-
from medcat.cdb import CDB
14-
from medcat.vocab import Vocab
1513
from urllib.request import urlretrieve, urlopen
1614
from urllib.error import HTTPError
1715
#from medcat.meta_cat import MetaCAT
1816
from .models import *
1917
from .forms import DownloaderForm, UMLSApiKeyForm
18+
from functools import lru_cache
2019

2120
AUTH_CALLBACK_SERVICE = 'https://medcat.rosalind.kcl.ac.uk/auth-callback'
2221
VALIDATION_BASE_URL = 'https://uts-ws.nlm.nih.gov/rest/isValidServiceValidate'
@@ -29,10 +28,10 @@
2928

3029
model_pack_path = os.getenv('MODEL_PACK_PATH', 'models/medmen_wstatus_2021_oct.zip')
3130

32-
try:
33-
cat = CAT.load_model_pack(model_pack_path)
34-
except Exception as e:
35-
print(str(e))
31+
32+
@lru_cache
33+
def get_model_pack():
34+
return CAT.load_model_pack(model_pack_path)
3635

3736

3837
TPL_ENT = """<mark class="entity" v-on:click="show_info({id})" style="background: {bg}; padding: 0.12em 0.6em; margin: 0 0.25em; line-height: 1; border-radius: 0.35em; box-decoration-break: clone; -webkit-box-decoration-break: clone"> {text} <span style="font-size: 0.8em; font-weight: bold; line-height: 1; border-radius: 0.35em; text-transform: uppercase; vertical-align: middle; margin-left: 0.1rem">{label}</span></mark>"""
@@ -80,6 +79,7 @@ def fix_floats(in_dict: dict) -> dict:
8079

8180

8281
def get_html_and_json(text):
82+
cat = get_model_pack()
8383
doc = cat(text)
8484

8585
a = {

0 commit comments

Comments
 (0)