UiPath Orchestrator

Building ML Packages

The Data Scientist builds pre-trained, static models Python IDE or using an AutoML platform such as H20 Driverless AI. Those models are consumed by RPA Developers within an RPA Workflow.

Building Your Own zip File

  1. Create a folder containing your trained model and all the local resources and python code that you need to run your predictions.
  2. Add a file named main.py at the root of this folder.
  3. In this file, define a class called Main that implements at least two functions:
    • _init_(self): takes no argument and preloads your model and/or local data
    • predict(self, input): must be called with the input from the client (e.g. UiPath Robot through MLSkill Activity), and must return a string (could be json string or otherwise).
  4. Add a file named requirements.txt with dependencies needed to run the model.

Example

  1. Initial project tree (without main.py and requirements.txt):
SentimentAnalysis
  - models
     -- preprocessor.joblib
     -- sentiment_analyzer.joblib
  - resources
     -- data_used_during_runtime.json
  -- dataprocessing.py
  -- __init__.py
  1. Sample main.py to be added to the root folder:
import joblib
import json
from dataprocessing import MyCustomPreprocessor
 
class Main(object):
    # 3a) Implement init
    def __init__(self):
        # Load models
        self.preprocesser = MyCustomPreprocessor(joblib.load('./models/preprocessor.joblib'))
        self.predictor = joblib.load('./resources/sentiment_analyzer.joblib')
 
    # 3b) Implement predict   
    def predict(self, json_text):
        text = json.loads(json_text)
        # Preprocess
        processed_data = self.preprocesser.process(text)
        # Predict
        sentiment, confidence = self.predictor(processed_data)
        # Return
        payload = {'sentiment': sentiment, 'confidence': confidence}
        return json.dumps(payload)
  1. Add requirements.txt:
numpy==1.15.4
nltk==3.3.0
joblib
pandas>=0.23.1
  1. Final folder structure:
SentimentAnalysis
  - models
     -- preprocessor.joblib
     -- sentiment_analyzer.joblib
  - resources
     -- data_used_during_runtime.json
  -- dataprocessing.py
  -- main.py
  -- requirements.txt
  -- __init__.py

Input Types

The input of the predict function has to be one of the following types:

  • string - select json as input type
  • byte string representation of your files - select file as input type
  • list of byte string representation of your files - select files as input type.

String

Any data that can be serialized can be used with an ML Skill. Within the RPA workflow, the data can be serialized by the Robot (perhaps using a custom Activity) and sent as a string in the input of the ML Skill Activity.
When uploading a package, the Data Scientist would have selected json as input type. The Data Scientist then has the responsibility to deserialize the sent string in the predict function.

Below are a handful of examples for deserializing data in Python:

# Robot sends raw string to ML Skill Activity
# E.g. skill_input='a customer complaint'`
def predict(self, skill_input):
  example = skill_input  # No extra processing
    
# Robot sends json formatted string to ML Skill Activity
# E.g skill_input='{'email': a customer complaint', 'date': 'mm:dd:yy'}'
def predict(self, skill_input):
  import json
  example = json.loads(skill_input)
  
# Robot sends json formatted string with number array to ML Skill Activity
# E.g. skill_input='[10, 15, 20]'
def predict(self, skill_input):
  import json
  import numpy as np
  example = np.array(json.loads(skill_input))
  
# Robot sends json formmatted pandas dataframe
# E.g. skill_input='{"row 1":{"col 1":"a","col 2":"b"},"row 2":{"col 1":"c","col 2":"d"}}'
def predict(self, skill_input):
  import pandas as pd
  example = pd.read_json(skill_input)

File

An entire file can be sent directly to an ML Skill. Within the RPA workflow, the input to the ML Skill Activity is just the path to the file. The platform reads the file, serializes it, and sends the file bytes to the predict function.
When uploading a package, the Data Scientist would have selected file as input type. The Data Scientist then has the responsibility to deserialize the sent file bytes in the predict function.

Below is an example of deserializing an image file:

# Robot has sent a jpg (or png) file path to ML Skill Activity
# Data Scientist wants to open it as an image.
def predict(self, skill_input):
  from PIL import Image
  import io
  image = Image.open(io.BytesIO(input_image_bytes))

List of Files Input

A list of files can be sent to an ML Skill. Within the RPA workflow, the input to the ML Skill Activity is a string with paths to the files, separated by a comma.
When uploading a package, the Data Scientist would have selected list of files as input type. The Data Scientist then has the responsibility to deserialize each of the sent files (as explained above). The input to the predict function will be a list of bytes where each element in the list is the byte representation of the file.

Using TensorFlow

During model development, the TensorFlow graph must be loaded on the same thread as the one used for serving. To do so, the default graph must be used.

Below is an example with the necessary modifications:

import tensorflow as tf

class Main(object):
  def __init__(self):
    self.graph = tf.get_default_graph() # Add this line
    ...
    
  def predict(self, skill_input):
    with self.graph.as_default():
      ...

Building Your Own Mojo Pipeline

If using driverless AI from UiPath's partner, H2O.ai, download the model as a MOJO pipeline file and place the file in a folder (e.g. SentimentAnalysis/).

Within this folder, add a file with the license for that MOJO pipeline. The folder may look something like this:

SentimentAnalysis/
    - pipeline.mojo
    - license.sig

Now zip the folder and upload it it to Orchestrator selecting Mojo Pipeline within the Language drop-down.

Information on GPU Usage

When GPU is enabled at ML Skill creation time, it is deployed on an image with NVIDIA GPU driver 418, CUDA Toolkit 10.0 and CUDA Deep Neural Network Library (cuDNN) 7.6.5 runtime library.

Updated about a month ago


See Also

ML Packages

Building ML Packages


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.