Skip to content

Commit

Permalink
init model before requests
Browse files Browse the repository at this point in the history
  • Loading branch information
aianko committed Dec 12, 2022
1 parent 2806b55 commit 63c7870
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
13 changes: 12 additions & 1 deletion embedding-calculator/src/_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down
3 changes: 2 additions & 1 deletion embedding-calculator/src/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 63c7870

Please sign in to comment.