ML model

# Get the latest lib from Rapidcanvas
# !pip install --extra-index-url=https://us-central1-python.pkg.dev/rapidcanvas-361003/pypi/simple utils==0.12dev0

from utils.rc.client.requests import Requests
from utils.rc.client.auth import AuthClient

from utils.rc.dtos.project import Project
from utils.rc.dtos.dataset import Dataset
from utils.rc.dtos.recipe import Recipe
from utils.rc.dtos.transform import Transform
from utils.rc.dtos.artifact import Artifact
from utils.rc.dtos.prediction_service import PredictionService

from utils.rc.dtos.template_v2 import TemplateV2, TemplateTransformV2

import pandas as pd
import logging
from utils.utils.log_util import LogUtil
LogUtil.set_basic_config(format='%(levelname)s:%(message)s', level=logging.INFO)
# Requests.setRootHost("https://test.dev.rapidcanvas.net/api/")
# Requests.setRootHost("http://localhost:8080/api/")
AuthClient.setToken()
project = Project.create(
    name="Example ML Model",
    description="Testing python lib",
    createEmpty=True
)
project.id
recipe = project.addRecipe([], name="build")
template = TemplateV2(
    name="CreateMLModel", description="CreateMLModel", project_id=project.id, source="CUSTOM", status="ACTIVE", tags=["Number", "datatype-long"]
)
template_transform = TemplateTransformV2(type = "python", params=dict(notebookName="CreateMLModel.ipynb"))
template.base_transforms = [template_transform]
template.publish("transforms/CreateMLModel.ipynb")
transform = Transform()
transform.templateId = template.id
transform.name = "transform_1"
transform.variables = {
    "modelName": "test-model"
}
# recipe.prepareForLocal(transform, contextId="CreateMLModel")
recipe.add_transform(transform)
recipe.run()
PredictionService.get_all_models()
PredictionService.get_model_details('test-model')
import pandas as pd
inputDf = pd.DataFrame({'x': [1]})
inputDf.to_csv('data/input.csv', index=None)
inputDataset = project.addDataset(
    dataset_name="inputDataset",
    dataset_description="inputDataset",
    dataset_file_path="data/input.csv"
)
predict_recipe = project.addRecipe([inputDataset], name="predict", models=['test-model'])
template = TemplateV2(
    name="PredictMLModel", description="PredictMLModel", project_id=project.id, source="CUSTOM", status="ACTIVE", tags=["Number", "datatype-long"]
)
template_transform = TemplateTransformV2(type = "python", params=dict(notebookName="PredictMLModel.ipynb"))
template.base_transforms = [template_transform]
template.publish("transforms/PredictMLModel.ipynb")
transform = Transform()
transform.templateId = template.id
transform.name = "transform"
transform.variables = {
    "modelInput": inputDataset.name,
    "modelName": "test-model"
}
predict_recipe.prepareForLocal(transform, contextId="PredictMLModel")
predict_recipe.add_transform(transform)
predict_recipe.run()
output = predict_recipe.getChildrenDatasets()['output']
output.getData()