RapidCanvas Docs
  • Welcome
  • GETTING STARTED
    • Quick start guide
    • Introduction to RapidCanvas
    • RapidCanvas Concepts
    • Accessing the platform
  • BASIC
    • Projects
      • Projects Overview
        • Creating a project
        • Reviewing the Projects listing page
        • Duplicating a Project
        • Modifying the project settings
        • Deleting Project(s)
        • Configuring global variables at the project level
        • Working on a project
        • Generating the about content for the project
        • Generating AI snippets for each node on the Canvas
        • Marking & Unmarking a Project as Favorite
      • Canvas overview
        • Shortcut options on canvas
        • Queuing the Recipes
        • Bulk Deletion of Canvas Nodes
        • AI Guide
      • Recipes
        • AI-assisted recipe
        • Rapid model recipe
        • Template recipe
        • Code Recipe
        • RAG Recipes
      • Scheduler overview
        • Creating a scheduler
        • Running the scheduler manually
        • Managing schedulers in a project
        • Viewing the schedulers in a project
        • Viewing the run history of a specific scheduler
        • Publishing the updated data pipeline to selected jobs from canvas
        • Fetching the latest data pipeline to a specific scheduler
        • Comparing the canvas of the scheduler with current canvas of the project
      • Predictions
        • Manual Prediction
        • Prediction Scheduler
      • Segments and Scenarios
      • DataApps
        • Model DataApp
        • Project Canvas Datasets
        • Custom Uploaded Datasets
        • SQL Sources
        • Documents and PDFs
        • Prediction Service
        • Scheduler
        • Import DataApp
    • Connectors
      • Importing dataset(s) from the local system
      • Importing Text Files from the Local System
      • Connectors overview
      • Connect to external connectors
        • Importing data from Google Cloud Storage (GCS)
        • Importing data from Amazon S3
        • Importing data from Azure Blob
        • Importing data from Mongo DB
        • Importing data from Snowflake
        • Importing data from MySQL
        • Importing data from Amazon Redshift
        • Importing data from Fivetran connectors
    • Workspaces
      • User roles and permissions
    • Artifacts & Models
      • Adding Artifacts at the Project Level
      • Adding Models at the Project Level
      • Creating an artifact at the workspace level
      • Managing artifacts at the workspace level
      • Managing Models at the Workspace Level
      • Prediction services
    • Environments Overview
      • Creating an environment
      • Editing the environment details
      • Deleting an environment
      • Monitoring the resource utilization in an environment
  • ADVANCED
    • Starter Guide
      • Quick Start
    • Setup and Installation
      • Installing and setting up the SDK
    • Helper Functions
    • Notebook Guide
      • Introduction
      • Create a template
      • Code Snippets
      • DataApps
      • Prediction Service
      • How to
        • How to Authenticate
        • Create a new project
        • Create a Custom Environment
        • Add a dataset
        • Add a recipe to the dataset
        • Manage cloud connection
        • Code recipes
        • Display a template on the UI
        • Create Global Variables
        • Scheduler
        • Create new scenarios
        • Create Template
        • Use a template in a flow notebook
      • Reference Implementations
        • DataApps
        • Artifacts
        • Connectors
        • Feature Store
        • ML model
        • ML Pipeline
        • Multiple Files
      • Sample Projects
        • Model build and predict
  • Additional Reading
    • Release Notes
      • April 21, 2025
      • April 01, 2025
      • Mar 18, 2025
      • Feb 27, 2025
      • Jan 27, 2025
      • Dec 26, 2024
      • Nov 26, 2024
      • Oct 24, 2024
      • Sep 11, 2024
        • Aug 08, 2024
      • Aug 29, 2024
      • July 18, 2024
      • July 03, 2024
      • June 19, 2024
      • May 30, 2024
      • May 15, 2024
      • April 17, 2024
      • Mar 28, 2024
      • Mar 20, 2024
      • Feb 28, 2024
      • Feb 19, 2024
      • Jan 30, 2024
      • Jan 16, 2024
      • Dec 12, 2023
      • Nov 07, 2023
      • Oct 25, 2023
      • Oct 01, 2024
    • Glossary
Powered by GitBook
On this page
  1. ADVANCED
  2. Notebook Guide
  3. Reference Implementations

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.template import Template
from utils.rc.dtos.template import TemplateTransform
from utils.rc.dtos.template import TemplateInput
from utils.rc.dtos.artifact import Artifact

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

import pandas as pd
import logging
logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.INFO)
# Requests.setRootHost("https://test.dev.rapidcanvas.net/api/")
# Requests.setRootHost("http://localhost:8080/api/")
AuthClient.setToken()
INFO:Authentication successful
project = Project.create(
    name="Example ML Model",
    description="Testing python lib",
    createEmpty=True
)
2023-02-02 16:31:38.434 INFO    root: Found existing project by name: Example ML Model
2023-02-02 16:31:38.436 INFO    root: Deleting existing project
2023-02-02 16:31:39.598 INFO    root: Creating new project by name: Example ML Model
project.id
'3a150194-b903-4423-848a-fbc95cb9d59c'
recipe = project.addRecipe([], name="build")
2023-02-02 16:31:41.930 INFO    root: Creating new recipe
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")
2023-02-02 16:31:43.144 INFO    root: Publishing template | data=TemplateV2(name='CreateMLModel', display_name=None, id=None, version='1.0', project_id='3a150194-b903-4423-848a-fbc95cb9d59c', projectId='3a150194-b903-4423-848a-fbc95cb9d59c', is_global=False, description='CreateMLModel', tags=['Number', 'datatype-long'], baseTransforms=[TemplateTransformV2(type='python', params={'notebookName': 'CreateMLModel.ipynb'})], base_transforms=[TemplateTransformV2(type='python', params={'notebookName': 'CreateMLModel.ipynb'})], source='CUSTOM', status='ACTIVE', inputs=[])
2023-02-02 16:31:45.776 INFO    root: Template Published
2023-02-02 16:31:45.849 INFO    blib2to3.pgen2.driver: Generating grammar tables from /Users/nikunj/miniconda3/lib/python3.8/site-packages/blib2to3/Grammar.txt
2023-02-02 16:31:45.856 INFO    blib2to3.pgen2.driver: Writing grammar tables to /Users/nikunj/Library/Caches/black/22.1.0/Grammar3.8.11.final.0.pickle
2023-02-02 16:31:45.856 INFO    blib2to3.pgen2.driver: Writing failed: [Errno 2] No such file or directory: '/Users/nikunj/Library/Caches/black/22.1.0/tmpjyfx5fg1'
2023-02-02 16:31:45.857 INFO    blib2to3.pgen2.driver: Generating grammar tables from /Users/nikunj/miniconda3/lib/python3.8/site-packages/blib2to3/PatternGrammar.txt
2023-02-02 16:31:45.858 INFO    blib2to3.pgen2.driver: Writing grammar tables to /Users/nikunj/Library/Caches/black/22.1.0/PatternGrammar3.8.11.final.0.pickle
2023-02-02 16:31:45.858 INFO    blib2to3.pgen2.driver: Writing failed: [Errno 2] No such file or directory: '/Users/nikunj/Library/Caches/black/22.1.0/tmpy4hoei59'
2023-02-02 16:31:45.877 WARNING papermill: Input notebook does not contain a cell with tag 'parameters'
2023-02-02 16:31:46.673 INFO    papermill: Executing notebook with kernel: python3
INFO:User authenticated successfully
INFO:Creating template input | nb_stage=COMPILE_TIME
INFO:
**************************************
**    CREATING INPUTS: modelName    **
**************************************
2023-02-02 16:31:50.022 INFO    utils.rc.wrapper.templates: Inputs created successfully | template_id=3191a37c-ebf8-4f3c-ad96-f78004b63f2b
Inputs created successfully | template_id=3191a37c-ebf8-4f3c-ad96-f78004b63f2b
transform = Transform()
transform.templateId = template.id
transform.name = "transform_1"
transform.variables = {
    "modelName": "test-model"
}
# recipe.prepareForLocal(transform, contextId="CreateMLModel")
recipe.addTransform(transform)
WARNING:
#############################################IMPORTANT#############################################
addTransform is going to deprecate soon. Please use add_transform instead
####################################################################################################
2023-02-02 16:31:52.668 INFO    root: Adding new transform
2023-02-02 16:31:54.992 INFO    root: Transform added Successfully
recipe.run()
2023-02-02 16:31:54.999 INFO    root: Started running
2023-02-02 16:31:55.006 INFO    root: You can look at the progress on UI at https://test.dev.rapidcanvas.net/#/projects/3a150194-b903-4423-848a-fbc95cb9d59c
2023-02-02 16:32:01.852 INFO    root: No errors found
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"
)
2023-02-02 16:32:04.208 INFO    root: Creating new dataset by name:inputDataset
2023-02-02 16:32:05.418 INFO    root: Uploading file data/input.csv ....
2023-02-02 16:32:18.724 INFO    root: Uploading Done
predict_recipe = project.addRecipe([inputDataset], name="predict")
2023-02-02 16:32:19.899 INFO    root: Creating new recipe
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")
2023-02-02 16:32:21.107 INFO    root: Publishing template | data=TemplateV2(name='PredictMLModel', display_name=None, id=None, version='1.0', project_id='3a150194-b903-4423-848a-fbc95cb9d59c', projectId='3a150194-b903-4423-848a-fbc95cb9d59c', is_global=False, description='PredictMLModel', tags=['Number', 'datatype-long'], baseTransforms=[TemplateTransformV2(type='python', params={'notebookName': 'PredictMLModel.ipynb'})], base_transforms=[TemplateTransformV2(type='python', params={'notebookName': 'PredictMLModel.ipynb'})], source='CUSTOM', status='ACTIVE', inputs=[])
2023-02-02 16:32:23.746 INFO    root: Template Published
2023-02-02 16:32:23.760 WARNING papermill: Input notebook does not contain a cell with tag 'parameters'
2023-02-02 16:32:24.629 INFO    papermill: Executing notebook with kernel: python3
INFO:User authenticated successfully
INFO:Creating template input | nb_stage=COMPILE_TIME
INFO:Creating template input | nb_stage=COMPILE_TIME
INFO:
**************************************************
**    CREATING INPUTS: modelName, modelInput    **
**************************************************
2023-02-02 16:32:28.107 INFO    utils.rc.wrapper.templates: Inputs created successfully | template_id=9791050a-ddaa-4341-b59e-f06f5667a858
Inputs created successfully | template_id=9791050a-ddaa-4341-b59e-f06f5667a858
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.addTransform(transform)
predict_recipe.run()
WARNING:
#############################################IMPORTANT#############################################
addTransform is going to deprecate soon. Please use add_transform instead
####################################################################################################
2023-02-02 16:32:30.746 INFO    root: Adding new transform
2023-02-02 16:32:33.062 INFO    root: Transform added Successfully
2023-02-02 16:32:33.064 INFO    root: Started running
2023-02-02 16:32:33.065 INFO    root: You can look at the progress on UI at https://test.dev.rapidcanvas.net/#/projects/3a150194-b903-4423-848a-fbc95cb9d59c
2023-02-02 16:32:48.612 INFO    root: No errors found
output = predict_recipe.getChildrenDatasets()['output']
output.getData()
<div>
<style scoped>
    .dataframe tbody tr th:only-of-type {
        vertical-align: middle;
    }

    .dataframe tbody tr th {
        vertical-align: top;
    }

    .dataframe thead th {
        text-align: right;
    }
</style>
<table border="1" class="dataframe">
  <thead>
    <tr style="text-align: right;">
      <th></th>
      <th>output_value</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <th>0</th>
      <td>4.0</td>
    </tr>
  </tbody>
</table>
</div>
PreviousFeature StoreNextML Pipeline