# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# # Deploy model with SKIL

from skil import Skil, WorkSpace, Experiment, Model, Deployment
from keras.datasets import mnist

# ## SKIL server
#
# Central class for managing connections with the SKIL server.
#
# **Arguments**:
# * **workspace_server_id**: None by default, only specify if you want to connect to a non-default SKIL workspace server.
# * **host**: string, Host on which the SKIL server runs.
# * **port**: integer, Port on which the SKIL host runs.
# * **debug**: boolean, set to false for more verbose logging.
# * **user_id**: user name for your SKIL server connection.
# * **password**: password of the provided SKIL user.

skil_server = Skil(
    host='localhost',
    port=9008,
    user_id='admin',
    password='<PASSWORD>'
)

# ## WorkSpace
#
# Workspaces are a collection of features that enable different tasks such as conducting experiments, training models, and test different dataset transforms.
#
# Workspaces are distinct from Deployments by operating as a space for non-production work.
#     
# **Arguments**:
# * **skil**: Skil server instance
# * **name**: string. Name for the workspace.
# * **labels**: string. Labels associated with the workspace, useful for searching (comma seperated).
# * **verbose**: boolean. If True, api response will be printed.
# * **create**: boolean. Internal. Do not use.
#

work_space = WorkSpace(
    skil   =skil_server, 
    name   ='mnist-workspace', 
    labels ='keras,mnist'
)

# ## Experiments  
#
# Experiments in SKIL are useful for defining different model configurations, 
# encapsulating training of models, and carrying out different data cleaning tasks.
#
# Experiments have a one-to-one relationship with Notebooks and have their own 
# storage mechanism for saving different model configurations when seeking a best 
# candidate.
#
# **Arguments**:
# * **work_space**: `WorkSpace` instance. If `None` a workspace will be created.
# * **experiment_id**: string. Unique id for workspace. If `None`, a unique id will be generated.
# * **name**: string. Name for the experiment.
# * **description**: string. Description for the experiment.
# * **verbose**: boolean. If `True`, api response will be printed.

experiment = Experiment(
    work_space=work_space,
    experiment_id='mnist-experiment-01',
    name='mnist-experiment',
    description='keras mnist experiment',
    verbose=False
)

# ## Model    
# SKIL wrapper for DL4J, Keras, TensorFlow and other models
#
# SKIL has a robust model storage, serving, and import system for supporting major 
# deep learning libraries.
#
# SKIL can be used for end-to-end training, configuration, and deployment of models 
# or alternatively you can import models into SKIL.
#
# **Arguments**
# * **model**: Model file path or  model instance
# * **model_id**: string. Unique id for model. If `None`, a unique id will be generated.
# * **name**: string. Name for the model.
# * **version**: integer. Version of the model. Defaults to 1.
# * **experiment**: `Experiment` instance. If `None`, an `Experiment` object will be created internally.
# * **labels**: string. Labels for this model
# * **verbose**: boolean. If `True`, prints api response.
# * **create**: boolean. Internal. Do not use.

model = Model(
    model='model.h5', 
    model_id='mnist-model-01', 
    name='mnist-model',
    experiment=experiment
)

# ## Deployment
#
# Deployments operate independently of workspaces to ensure that there are
# no accidental interruptions or mistakes in a production environment.
#
# **Arguments:**
# * **skil**: `Skil` server instance.
# * **name**: string. Name for the deployment.

deployment = Deployment(
    skil=skil_server,
    name='mnist-deployment'
)

# ### 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.

model.deploy(
    deployment=deployment,
    start_server=True,
    scale=1,
    input_names=None,
    output_names=None
)



StarcoderdataJupyterScriptsDedupFiltered