Exemple #1
0
def run_model_server(model: Model, server: Server = None):
    """
    :func:`.start_runtime` wrapper helper which starts Ebonite runtime for given model and (optional) server

    :param model: model to start Ebonite runtime for
    :param server: server to use for Ebonite runtime, default is a flask-based server
    :return: nothing
    """

    if server is None:
        if module_importable('aiohttp') and module_importable(
                'aiohttp_swagger'):
            from ebonite.ext.aiohttp import AIOHTTPServer
            server = AIOHTTPServer()
        elif module_importable('flask') and module_importable('flasgger'):
            from ebonite.ext.flask import FlaskServer
            server = FlaskServer()
        else:
            raise RuntimeError(
                'You need to install flask and flasgger to use test flask server'
            )

    class MockLoader(ModelLoader):
        def load(self) -> Interface:
            model.ensure_loaded()
            return model_interface(model)

    start_runtime(MockLoader(), server)
Exemple #2
0
def build_model_docker(image_name: str, model: 'core.Model', server: Server = None,
                       image_tag='latest', force_overwrite=False, **kwargs):
    """
    Builds docker image from Model instance

    :param image_name: docker image name to create
    :param model: model to create image
    :param server: server instance to wrap model
    :param image_tag: docker image tag
    :param force_overwrite: force overwrite image if it exists
    :param kwargs: same as in DockerBuilder.__init__
    """
    if server is None:
        from ebonite.ext.flask import FlaskServer
        server = FlaskServer()

    if not module_importable('docker'):
        raise RuntimeError("Can't build docker container: docker module is not installed. Install it "
                           "with 'pip install docker'")

    from ebonite.build.builder.docker_builder import DockerBuilder, is_docker_running

    if not is_docker_running():
        raise RuntimeError("Docker is unavailable")

    provider = MLModelProvider(model, server)
    builder = DockerBuilder(provider, image_name, image_tag, force_overwrite, **kwargs)
    builder.build()
Exemple #3
0
    def get_default_environment(self):
        """
        Creates (if needed) and returns default runtime environment

        :return: saved instance of :class:`.RuntimeEnvironment`
        """
        if self.default_env is not None:
            return self.default_env
        env_name = 'docker_localhost'
        self.default_env = self.get_environment(env_name)
        if self.default_env is None:
            if not module_importable('docker'):
                raise RuntimeError("Can't build docker container: docker module is not installed. Install it "
                                   "with 'pip install docker'")

            from ebonite.ext.docker import DockerEnv
            self.default_env = RuntimeEnvironment(env_name, params=DockerEnv())
            self.default_env = self.push_environment(self.default_env)
        return self.default_env
Exemple #4
0
    def load_all(cls, try_lazy=True):
        """
        Load all (builtin and additional) extensions

        :param try_lazy: if `False`, use force load for all builtin extensions
        """
        for_hook = []
        for ext in cls.builtin_extensions.values():
            if not try_lazy or hasattr(sys, 'frozen') or ext.force:
                if all(module_importable(r) for r in ext.reqs):
                    cls.load(ext)
            else:
                if all(module_imported(r) for r in ext.reqs):
                    cls.load(ext)
                else:
                    for_hook.append(ext)

        cls._setup_import_hook(for_hook)

        for mod in Core.ADDITIONAL_EXTENSIONS:
            cls.load(mod)