Beispiel #1
0
    def deploy(self,
               deployment=None,
               start_server=True,
               scale=1,
               input_names=None,
               output_names=None,
               verbose=True):
        """Deploys the model

        # Arguments:
            deployment: `Deployment` instance.
            start_server: boolean. If `True`, the service is immedietely started.
            scale: integer. Scale-out for deployment.
            input_names: list of strings. Input variable names of the model.
            output_names: list of strings. Output variable names of the model.
            verbose: boolean. If `True`, api response will be printed.

        # Returns:
            `Service` instance.
        """
        if not deployment:
            deployment = skil.Deployment(skil=self.skil, name=self.name)

        uris = [
            "{}/model/{}/default".format(deployment.name, self.name),
            "{}/model/{}/v1".format(deployment.name, self.name)
        ]

        if not self.service:
            deploy_model_request = skil_client.ImportModelRequest(
                name=self.name,
                scale=scale,
                file_location=self.model_path,
                model_type="model",
                uri=uris,
                input_names=input_names,
                output_names=output_names)

            # TODO: why ".response"? Doesn't make sense.
            self.deployment = deployment.response

            models = self.skil.api.models(self.deployment.id)
            deployed_model = [m for m in models if m.name == self.name]
            if deployed_model:
                self.model_deployment = deployed_model[0]
            else:
                self.model_deployment = self.skil.api.deploy_model(
                    self.deployment.id, deploy_model_request)
                if verbose:
                    self.skil.printer.pprint(self.model_deployment)

            self.service = Service(self.skil, self, self.deployment,
                                   self.model_deployment)
        if start_server:
            self.service.start()
        return self.service
Beispiel #2
0
    def deploy(self,
               deployment=None,
               start_server=True,
               scale=1,
               input_names=None,
               output_names=None,
               verbose=True):

        if not deployment:
            deployment = skil.Deployment(skil=self.skil, name=self.name)

        uris = [
            "{}/model/{}/default".format(deployment.name, self.name),
            "{}/model/{}/v1".format(deployment.name, self.name)
        ]

        deploy_model_request = skil_client.ImportModelRequest(
            name=self.name,
            scale=scale,
            file_location=self.model_path,
            model_type="model",
            uri=uris,
            input_names=input_names,
            output_names=output_names)

        self.deployment = deployment.response
        self.model_deployment = self.skil.api.deploy_model(
            self.deployment.id, deploy_model_request)
        if verbose:
            self.skil.printer.pprint(self.model_deployment)

        service = Service(self.skil, self.name, self.deployment,
                          self.model_deployment)
        if start_server:
            service.start()
        return service