diff --git a/embedding-calculator/src/_endpoints.py b/embedding-calculator/src/_endpoints.py index 53685293d1..a75beecd15 100644 --- a/embedding-calculator/src/_endpoints.py +++ b/embedding-calculator/src/_endpoints.py @@ -19,15 +19,26 @@ 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 +def init_model() -> None: + detector = managers.plugin_manager.detector + face_plugins = managers.plugin_manager.face_plugins + detector( + img=read_img(str(IMG_DIR / 'einstein.jpeg')), + det_prob_threshold=_get_det_prob_threshold(), + face_plugins=face_plugins + ) + return None + def endpoints(app): @app.route('/status') def status_get(): diff --git a/embedding-calculator/src/app.py b/embedding-calculator/src/app.py index 5242f84bee..f2355db3f3 100644 --- a/embedding-calculator/src/app.py +++ b/embedding-calculator/src/app.py @@ -19,7 +19,7 @@ from src import constants from src._docs import add_docs -from src._endpoints import endpoints +from src._endpoints import endpoints, init_model from src.constants import ENV from src.docs import DOCS_DIR from src.init_runtime import init_runtime @@ -38,6 +38,7 @@ def init_app_runtime(): def create_app(add_endpoints_fun: Union[Callable, None] = None, do_add_docs: bool = False): app = Flask('embedding-calculator') + app.before_first_request_funcs.append(init_model) app.url_map.strict_slashes = False add_error_handling(app) app.after_request(log_http_response)