diff --git a/dev/docker-compose-gpu.yml b/dev/docker-compose-gpu.yml index 8f5ff40934..f0c302d389 100644 --- a/dev/docker-compose-gpu.yml +++ b/dev/docker-compose-gpu.yml @@ -104,3 +104,9 @@ services: - ML_PORT=3000 - UWSGI_PROCESSES=${uwsgi_processes:-1} - UWSGI_THREADS=${uwsgi_threads:-1} + healthcheck: + test: curl --fail http://localhost:3000/healthcheck || exit 1 + interval: 10s + retries: 0 + start_period: 0s + timeout: 1s diff --git a/dev/docker-compose.yml b/dev/docker-compose.yml index 38fba2fbb9..926613e11e 100644 --- a/dev/docker-compose.yml +++ b/dev/docker-compose.yml @@ -103,3 +103,9 @@ services: - ML_PORT=3000 - UWSGI_PROCESSES=${uwsgi_processes:-2} - UWSGI_THREADS=${uwsgi_threads:-1} + healthcheck: + test: curl --fail http://localhost:3000/healthcheck || exit 1 + interval: 10s + retries: 0 + start_period: 0s + timeout: 1s diff --git a/docker-compose.yml b/docker-compose.yml index 566a780e4e..ac07b0bc7f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -77,3 +77,9 @@ services: - IMG_LENGTH_LIMIT=${max_detect_size} - UWSGI_PROCESSES=${uwsgi_processes:-2} - UWSGI_THREADS=${uwsgi_threads:-1} + healthcheck: + test: curl --fail http://localhost:3000/healthcheck || exit 1 + interval: 10s + retries: 0 + start_period: 0s + timeout: 1s diff --git a/embedding-calculator/src/_endpoints.py b/embedding-calculator/src/_endpoints.py index c79777c701..a18080ae42 100644 --- a/embedding-calculator/src/_endpoints.py +++ b/embedding-calculator/src/_endpoints.py @@ -11,6 +11,7 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express # or implied. See the License for the specific language governing # permissions and limitations under the License. + from typing import List, Optional from flask import request @@ -19,12 +20,13 @@ from src.constants import ENV from src.exceptions import NoFaceFoundError -from src.services.facescan.plugins import base, managers +from src.services.facescan.plugins import managers from src.services.facescan.scanner.facescanners import scanner from src.services.flask_.constants import ARG from src.services.flask_.needs_attached_file import needs_attached_file from src.services.imgtools.read_img import read_img from src.services.utils.pyutils import Constants +from src.services.imgtools.test.files import IMG_DIR import base64 from src.constants import SKIPPED_PLUGINS @@ -41,8 +43,26 @@ def face_detection_skip_check(face_plugins): else: return face_plugins - def endpoints(app): + @app.before_first_request + def init_model() -> None: + detector = managers.plugin_manager.detector + face_plugins = managers.plugin_manager.face_plugins + face_plugins = face_detection_skip_check(face_plugins) + detector( + img=read_img(str(IMG_DIR / 'einstein.jpeg')), + det_prob_threshold=_get_det_prob_threshold(), + face_plugins=face_plugins + ) + print("Starting to load ML models") + return None + + @app.route('/healthcheck') + def healthcheck(): + return jsonify( + status='OK' + ) + @app.route('/status') def status_get(): available_plugins = {p.slug: str(p)