Skip to content

Deploying & running online prediction

This section shows how to deploy a trained model using the AI & Analytics Engine

Deploy a model

Now you can deploy the trained model once the evaluation meets your expection. Simply input the id of model and follow

from aiaengine import Model, FileSource, Deployment

model = Model(id='c8dbd4fd-4a33-4923-ab17-75e0a5139eb7')
# deploy the model to a new endpoint
deployment = model.deploy()

# or use your existing deployment for online prediction
# deployment = Deployment(id='4eb2a91b-8f81-4976-9209-13404c56b928', app_id='f004a8e9-3507-4b89-b038-aeebbe3d1242')

# run online prediction with the deployment
result = deployment.predict(FileSource(
        file_urls=['examples/datasets/german-credit-predict.csv']
    )
)
print(result)
package com.aiaengine.examples.model;

import com.aiaengine.Deployment;
import com.aiaengine.Engine;
import com.aiaengine.Model;
import com.aiaengine.datasource.file.FileSourceRequest;
import com.aiaengine.datasource.file.FileType;
import com.aiaengine.model.request.DeployRequest;

import java.io.FileNotFoundException;

public class DeployModelApp {
    public static void main(String[] args) throws FileNotFoundException {
        Engine engine = new Engine();
        //replace with your model id
        Model model = engine.getModel("9310c78a-3970-457f-afea-6e2e2545eb7b");
        Deployment deployment = model.deploy(DeployRequest.builder().build());

        // run online prediction with the deployment
        String predictionDataFile = "examples/datasets/german-credit-predict.csv";
        String result = deployment.predict(engine.buildFileSource(FileSourceRequest.builder()
                .url(predictionDataFile)
                .fileType(FileType.CSV)
                .build()));
        System.out.println(result);
    }
}