From f00a74a5648b122e2f946fc76c6fab0d59033f37 Mon Sep 17 00:00:00 2001 From: vladd-bit Date: Mon, 19 Feb 2024 11:00:19 +0000 Subject: [PATCH] Dockerfile update(s) + pep8 fix. --- Dockerfile | 3 ++- Dockerfile_gpu | 9 ++++++-- config.py | 2 -- .../nlp_processor/medcat_processor.py | 23 ++++++++++--------- 4 files changed, 21 insertions(+), 16 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2f4c6c3..579dbdf 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,8 +6,9 @@ ENV CRYPTOGRAPHY_DONT_BUILD_RUST=1 WORKDIR /cat COPY ./medcat_service/requirements.txt /cat RUN pip install --upgrade pip + # Install requirements for the app -RUN pip install -r requirements.txt +RUN pip3 install --no-cache-dir -r requirements.txt # Get the spacy model ARG SPACY_MODELS="en_core_web_sm en_core_web_md en_core_web_lg" diff --git a/Dockerfile_gpu b/Dockerfile_gpu index 8847cbe..3bf2f9b 100644 --- a/Dockerfile_gpu +++ b/Dockerfile_gpu @@ -14,7 +14,6 @@ RUN echo "deb-src http://deb.debian.org/debian bookworm-backports main contrib n RUN apt-get update && apt-get upgrade -y && \ apt-get install -y software-properties-common - # NVIDIA Docker RUN export distribution=$(. /etc/os-release;echo $ID$VERSION_ID) @@ -26,13 +25,19 @@ RUN apt-get update && apt-get upgrade -y RUN apt-get install -y nvidia-container-toolkit nvidia-docker2 +# clean up apt +RUN apt-get clean autoclean && apt-get autoremove --purge -y + # Set the python path and preapre the base layer WORKDIR /cat COPY ./medcat_service/requirements.txt /cat RUN pip install --upgrade pip +# clean up pip +RUN pip3 cache purge + # Install requirements for the app -RUN pip install -r requirements.txt +RUN pip install --no-cache-dir -r requirements.txt # Get the spacy model ARG SPACY_MODELS="en_core_web_sm en_core_web_md en_core_web_lg" diff --git a/config.py b/config.py index f6f8256..7c24459 100644 --- a/config.py +++ b/config.py @@ -16,5 +16,3 @@ def post_fork(server, worker): os.environ["CUDA_VISIBLE_DEVICES"] = str(cudaid) else: worker.log.info("APP_CUDA_DEVICE_COUNT device variables not set") - - diff --git a/medcat_service/nlp_processor/medcat_processor.py b/medcat_service/nlp_processor/medcat_processor.py index 4ba772f..a1c5340 100644 --- a/medcat_service/nlp_processor/medcat_processor.py +++ b/medcat_service/nlp_processor/medcat_processor.py @@ -19,6 +19,7 @@ class NlpProcessor: """ This class defines an interface for NLP Processor """ + def __init__(self): app_log_level = os.getenv("APP_LOG_LEVEL", logging.INFO) medcat_log_level = os.getenv("LOG_LEVEL", logging.INFO) @@ -114,10 +115,10 @@ def process_content(self, content): if "text" not in content: error_msg = "'text' field missing in the payload content." nlp_result = { - "success": False, - "errors": [error_msg], - "timestamp": NlpProcessor._get_timestamp(), - } + "success": False, + "errors": [error_msg], + "timestamp": NlpProcessor._get_timestamp(), + } return nlp_result @@ -138,12 +139,12 @@ def process_content(self, content): entities = self.process_entities(entities) nlp_result = { - "text": str(text), - "annotations": entities, - "success": True, - "timestamp": NlpProcessor._get_timestamp(), - "elapsed_time": elapsed_time - } + "text": str(text), + "annotations": entities, + "success": True, + "timestamp": NlpProcessor._get_timestamp(), + "elapsed_time": elapsed_time + } # append the footer if "footer" in content: @@ -187,7 +188,7 @@ def process_content_bulk(self, content): ann_res = self.cat.deid_text() else: ann_res = self.cat.multiprocessing_batch_docs_size( - MedCatProcessor._generate_input_doc(content, invalid_doc_ids), batch_size = batch_size, nproc=nproc) + MedCatProcessor._generate_input_doc(content, invalid_doc_ids), batch_size=batch_size, nproc=nproc) except Exception as e: self.log.error(repr(e))