use of com.google.cloud.automl.v1.AutoMlClient in project java-automl by googleapis.
the class DatasetApi method importData.
// [START automl_translate_import_data]
/**
* Import sentence pairs to the dataset.
*
* @param projectId the Google Cloud Project ID.
* @param computeRegion the Region name. (e.g., "us-central1").
* @param datasetId the Id of the dataset.
* @param path the remote Path of the training data csv file.
*/
public static void importData(String projectId, String computeRegion, String datasetId, String path) throws IOException, InterruptedException, ExecutionException {
// Instantiates a client
try (AutoMlClient client = AutoMlClient.create()) {
// Get the complete path of the dataset.
DatasetName datasetFullId = DatasetName.of(projectId, computeRegion, datasetId);
GcsSource.Builder gcsSource = GcsSource.newBuilder();
// Get multiple Google Cloud Storage URIs to import data from
String[] inputUris = path.split(",");
for (String inputUri : inputUris) {
gcsSource.addInputUris(inputUri);
}
// Import data from the input URI
InputConfig inputConfig = InputConfig.newBuilder().setGcsSource(gcsSource).build();
System.out.println("Processing import...");
Empty response = client.importDataAsync(datasetFullId, inputConfig).get();
System.out.println(String.format("Dataset imported. %s", response));
}
}
use of com.google.cloud.automl.v1.AutoMlClient in project java-automl by googleapis.
the class ModelApi method getOperationStatus.
// [END automl_translate_list_models]
// [START automl_translate_get_operation_status]
/**
* Demonstrates using the AutoML client to get operation status.
*
* @param operationFullId Full name of a operation. For example, the name of your operation is
* projects/[projectId]/locations/us-central1/operations/[operationId].
* @throws IOException on Input/Output errors.
*/
private static void getOperationStatus(String operationFullId) throws IOException {
// Instantiates a client
try (AutoMlClient client = AutoMlClient.create()) {
// Get the latest state of a long-running operation.
Operation response = client.getOperationsClient().getOperation(operationFullId);
System.out.println(String.format("Operation status: %s", response));
}
}
use of com.google.cloud.automl.v1.AutoMlClient in project java-automl by googleapis.
the class ClassificationUndeployModel method classificationUndeployModel.
// Deploy a model
static void classificationUndeployModel(String projectId, String modelId) throws IOException, ExecutionException, InterruptedException {
// the "close" method on the client to safely clean up any remaining background resources.
try (AutoMlClient client = AutoMlClient.create()) {
// Get the full path of the model.
ModelName modelFullId = ModelName.of(projectId, "us-central1", modelId);
// Build deploy model request.
UndeployModelRequest undeployModelRequest = UndeployModelRequest.newBuilder().setName(modelFullId.toString()).build();
// Deploy a model with the deploy model request.
OperationFuture<Empty, OperationMetadata> future = client.undeployModelAsync(undeployModelRequest);
future.get();
// Display the deployment details of model.
System.out.println("Model undeploy finished");
}
}
use of com.google.cloud.automl.v1.AutoMlClient in project java-automl by googleapis.
the class ClassificationDeployModel method classificationDeployModel.
// Deploy a model
static void classificationDeployModel(String projectId, String modelId) throws IOException, ExecutionException, InterruptedException {
// the "close" method on the client to safely clean up any remaining background resources.
try (AutoMlClient client = AutoMlClient.create()) {
// Get the full path of the model.
ModelName modelFullId = ModelName.of(projectId, "us-central1", modelId);
// Build deploy model request.
DeployModelRequest deployModelRequest = DeployModelRequest.newBuilder().setName(modelFullId.toString()).build();
// Deploy a model with the deploy model request.
OperationFuture<Empty, OperationMetadata> future = client.deployModelAsync(deployModelRequest);
future.get();
// Display the deployment details of model.
System.out.println("Model deployment finished");
}
}
use of com.google.cloud.automl.v1.AutoMlClient in project java-automl by googleapis.
the class ClassificationDeployModelNodeCount method classificationDeployModelNodeCount.
// Deploy a model with a specified node count
static void classificationDeployModelNodeCount(String projectId, String modelId) throws IOException, ExecutionException, InterruptedException {
// the "close" method on the client to safely clean up any remaining background resources.
try (AutoMlClient client = AutoMlClient.create()) {
// Get the full path of the model.
ModelName modelFullId = ModelName.of(projectId, "us-central1", modelId);
// Set how many nodes the model is deployed on
ImageClassificationModelDeploymentMetadata deploymentMetadata = ImageClassificationModelDeploymentMetadata.newBuilder().setNodeCount(2).build();
DeployModelRequest request = DeployModelRequest.newBuilder().setName(modelFullId.toString()).setImageClassificationModelDeploymentMetadata(deploymentMetadata).build();
// Deploy the model
OperationFuture<Empty, OperationMetadata> future = client.deployModelAsync(request);
future.get();
System.out.println("Model deployment on 2 nodes finished");
}
}
Aggregations