Example #1
0
def main() -> None:
    """Main routine, executed only if running as stand-alone."""
    log.info(
        "***** Starting development server at http://%s/api/ *****",
        get_value("FLASK_SERVER_NAME"),
    )
    APP.run(
        debug=get_value("FLASK_DEBUG"),
        port=get_value("FLASK_PORT"),
        host=get_value("FLASK_HOST"),
    )
Example #2
0
def default_error_handler(exception) -> FlaskApiReturnType:
    """Default error handler that returns HTTP 500 error."""
    log.exception(exception.message)
    if get_value("FLASK_DEBUG"):
        error_msg = exception.message
    else:
        error_msg = "An unhandled exception occurred"
    return {"message": error_msg}, 500
Example #3
0
 def load_default_module(self) -> None:
     """Loads a module, chosen either by getting the name from TRAINED_MODEL_MODULE_NAME env var
     or from the settings file. If module is not found in env var or settings, find it by calling
     load_first_module()"""
     env_model_name: str = get_value("TRAINED_MODEL_MODULE_NAME")
     if not env_model_name:
         env_model_name = self.find_first_module()
     if env_model_name:
         self.load(env_model_name)
Example #4
0
def initialize_app(flask_app: Flask) -> None:
    """Initialises the app."""
    configure_app(flask_app)
    blueprint = Blueprint("api", __name__, url_prefix="/api")
    api.init_app(blueprint)
    flask_app.register_blueprint(blueprint)
    if get_value("MULTITHREADED_INIT") and not IN_UWSGI:
        trained_model_wrapper.multithreaded_init()
    else:
        trained_model_wrapper.init()
Example #5
0
def configure_app(flask_app: Flask) -> None:
    """Configures the app."""
    flask_settings_to_apply: List = [
        #'FLASK_SERVER_NAME',
        "SWAGGER_UI_DOC_EXPANSION",
        "RESTX_VALIDATE",
        "RESTX_MASK_SWAGGER",
        "SWAGGER_UI_JSONEDITOR",
        "ERROR_404_HELP",
    ]
    for key in flask_settings_to_apply:
        flask_app.config[key] = get_value(key)