App
This section shows how to create, modify and list apps in AI & Analytics Engine using the Python SDK
Creating an app
The following example code shows you how to create a binary classification app using the SDK.
Refer Building AI Applications guide to know more about creating other application types.
from aiaengine import Org, FileSource, Column, DataType, ClassificationConfig, ClassificationSubType
# create a new demo project in the org
org = Org(id='b6240512-cd17-43a0-8297-84c51c1bc5a0') # replace with your org ID
project = org.create_project(name="Demo project using Python SDK", description="Your demo project")
# or you can get an existing project that you want to work on
# project = Project(id='ID_of_your_project') # replace with your own project ID
# import the `Penguin Regression` dataset
data_file = 'examples/datasets/penguins_classification.csv'
# You can use the `print_schema` utility function to print the auto-inferred schema
# print_schema(pd.read_csv(data_file, header=0))
dataset = project.create_dataset(
name=f"Penguin Species",
data_source=FileSource(
file_urls=[data_file],
schema=[
Column('Culmen Length (mm)', DataType.Numeric),
Column('Culmen Depth (mm)', DataType.Numeric),
Column('Species', DataType.Text)
]
)
)
# set the ID of the input dataset that used for creating the application
dataset_id = dataset.id
# use the ClassificationConfg class with MULTI_CLASS sub_type
app = project.create_app(
name=f"Predict Penguin Species - Multi-class Classification",
dataset_id=dataset_id,
config=ClassificationConfig(
sub_type=ClassificationSubType.MULTI_CLASS,
target_column="Species",
)
)
package com.aiaengine.examples.app;
import com.aiaengine.*;
import com.aiaengine.app.ClassificationConfig;
import com.aiaengine.datasource.DataSource;
import com.aiaengine.datasource.Schema;
import com.aiaengine.datasource.file.CSVFileSettings;
import com.aiaengine.datasource.file.FileSourceRequest;
import com.aiaengine.datasource.file.FileType;
import com.aiaengine.org.request.CreateProjectRequest;
import com.aiaengine.project.request.CreateAppRequest;
import com.aiaengine.project.request.CreateDatasetRequest;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
public class CreateMultiClassClassificationApp {
public static void main(String[] args) throws FileNotFoundException {
Engine engine = new Engine();
// create a new demo project in the org
Org org = engine.getOrg("cae24b10-e6b0-4d61-8cef-a9f4b8f6133d"); // replace with your org ID
Project project = org.createProject(CreateProjectRequest.builder()
.name("Demo project using Java SDK")
.description("Your demo project")
.build());
// or you can get an existing project that you want to work on
// Project project = engine.getProject("ID_of_your_project") // replace with your own project ID
// import the `Penguin Regression` dataset
String dataFilePath = "examples/datasets/penguins_classification.csv";
List<Schema.Column> columns = new ArrayList<>();
columns.add(new Schema.Column("Culmen Length (mm)", Schema.SemanticType.NUMERIC));
columns.add(new Schema.Column("Culmen Depth (mm)", Schema.SemanticType.NUMERIC));
columns.add(new Schema.Column("Species", Schema.SemanticType.TEXT));
DataSource localDataSource = engine.buildFileSource(FileSourceRequest.builder()
.fileType(FileType.CSV)
.url(dataFilePath)
.fileSettings(new CSVFileSettings())
.schema(new Schema(columns))
.build());
Dataset dataset = project.createDataset(CreateDatasetRequest.builder()
.name("Penguin Species")
.dataSource(localDataSource)
.timeout(900)
.build());
// Create App: use the ClassificationConfig class with MULTI_CLASS sub_type
App app = project.createApp(CreateAppRequest.builder()
.name("Predict Penguin Species - Multi-class Classification")
.datasetId(dataset.getId())
.config(new ClassificationConfig("Species",
ClassificationConfig.ClassificationSubType.MULTI_CLASS))
.build());
System.out.println(app.getId());
}
}
Retrieving information of an app
You can get information about an app by providing the app id.
package com.aiaengine.examples.app;
import com.aiaengine.App;
import com.aiaengine.Engine;
import java.io.FileNotFoundException;
public class GetApp {
public static void main(String[] args) throws FileNotFoundException {
Engine engine = new Engine();
App app = engine.getApp("f55717be-14dd-40ea-8cad-f71370d5b961");
System.out.println(app.getName());
}
}
Updating an app
You can modify the name and description of an existing app by specifying the app ID.
package com.aiaengine.examples.app;
import com.aiaengine.App;
import com.aiaengine.Engine;
import com.aiaengine.app.request.UpdateAppRequest;
import java.io.FileNotFoundException;
public class UpdateApp {
public static void main(String[] args) throws FileNotFoundException {
Engine engine = new Engine();
App app = engine.getApp("f55717be-14dd-40ea-8cad-f71370d5b961");
app.update(UpdateAppRequest.builder()
.name("Updated App")
.description("This app has been updated")
.build());
}
}
Listing apps in a project
You can list all the apps within a project with the following code
package com.aiaengine.examples.app;
import com.aiaengine.App;
import com.aiaengine.Engine;
import com.aiaengine.Project;
import java.io.FileNotFoundException;
import java.util.List;
public class ListApps {
public static void main(String[] args) throws FileNotFoundException {
Engine engine = new Engine();
Project project = engine.getProject("c6e4589e-9cf4-4191-a85b-6eaf5fa80bf5");
List<App> apps = project.listApps();
apps.forEach(app -> System.out.println(app.getName()));
}
}
Deleting an app
You can also remove an app which is no longer needed by giving the app ID.
package com.aiaengine.examples.app;
import com.aiaengine.App;
import com.aiaengine.Engine;
import java.io.FileNotFoundException;
public class DeleteApp {
public static void main(String[] args) throws FileNotFoundException {
Engine engine = new Engine();
App app = engine.getApp("f55717be-14dd-40ea-8cad-f71370d5b961");
app.delete();
}
}