Search in sources :

Example 11 with OperationMetadata

use of com.google.cloud.documentai.v1beta2.OperationMetadata in project java-automl by googleapis.

the class LanguageTextClassificationCreateModel method createModel.

// Create a model
static void createModel(String projectId, String datasetId, String displayName) throws IOException, ExecutionException, InterruptedException {
    // the "close" method on the client to safely clean up any remaining background resources.
    try (AutoMlClient client = AutoMlClient.create()) {
        // A resource that represents Google Cloud Platform location.
        LocationName projectLocation = LocationName.of(projectId, "us-central1");
        // Set model metadata.
        TextClassificationModelMetadata metadata = TextClassificationModelMetadata.newBuilder().build();
        Model model = Model.newBuilder().setDisplayName(displayName).setDatasetId(datasetId).setTextClassificationModelMetadata(metadata).build();
        // Create a model with the model metadata in the region.
        OperationFuture<Model, OperationMetadata> future = client.createModelAsync(projectLocation, model);
        // OperationFuture.get() will block until the model is created, which may take several hours.
        // You can use OperationFuture.getInitialFuture to get a future representing the initial
        // response to the request, which contains information while the operation is in progress.
        System.out.format("Training operation name: %s\n", future.getInitialFuture().get().getName());
        System.out.println("Training started...");
    }
}
Also used : TextClassificationModelMetadata(com.google.cloud.automl.v1.TextClassificationModelMetadata) Model(com.google.cloud.automl.v1.Model) OperationMetadata(com.google.cloud.automl.v1.OperationMetadata) AutoMlClient(com.google.cloud.automl.v1.AutoMlClient) LocationName(com.google.cloud.automl.v1.LocationName)

Example 12 with OperationMetadata

use of com.google.cloud.documentai.v1beta2.OperationMetadata in project java-automl by googleapis.

the class TranslateCreateDataset method createDataset.

// Create a dataset
static void createDataset(String projectId, String displayName) throws IOException, ExecutionException, InterruptedException {
    // the "close" method on the client to safely clean up any remaining background resources.
    try (AutoMlClient client = AutoMlClient.create()) {
        // A resource that represents Google Cloud Platform location.
        LocationName projectLocation = LocationName.of(projectId, "us-central1");
        // Specify the source and target language.
        TranslationDatasetMetadata translationDatasetMetadata = TranslationDatasetMetadata.newBuilder().setSourceLanguageCode("en").setTargetLanguageCode("ja").build();
        Dataset dataset = Dataset.newBuilder().setDisplayName(displayName).setTranslationDatasetMetadata(translationDatasetMetadata).build();
        OperationFuture<Dataset, OperationMetadata> future = client.createDatasetAsync(projectLocation, dataset);
        Dataset createdDataset = future.get();
        // Display the dataset information.
        System.out.format("Dataset name: %s\n", createdDataset.getName());
        // To get the dataset id, you have to parse it out of the `name` field. As dataset Ids are
        // required for other methods.
        // Name Form: `projects/{project_id}/locations/{location_id}/datasets/{dataset_id}`
        String[] names = createdDataset.getName().split("/");
        String datasetId = names[names.length - 1];
        System.out.format("Dataset id: %s\n", datasetId);
    }
}
Also used : TranslationDatasetMetadata(com.google.cloud.automl.v1.TranslationDatasetMetadata) Dataset(com.google.cloud.automl.v1.Dataset) OperationMetadata(com.google.cloud.automl.v1.OperationMetadata) AutoMlClient(com.google.cloud.automl.v1.AutoMlClient) LocationName(com.google.cloud.automl.v1.LocationName)

Example 13 with OperationMetadata

use of com.google.cloud.documentai.v1beta2.OperationMetadata in project java-automl by googleapis.

the class BatchPredict method batchPredict.

static void batchPredict(String projectId, String modelId, String inputUri, String outputUri) throws IOException, ExecutionException, InterruptedException {
    // the "close" method on the client to safely clean up any remaining background resources.
    try (PredictionServiceClient client = PredictionServiceClient.create()) {
        // Get the full path of the model.
        ModelName name = ModelName.of(projectId, "us-central1", modelId);
        GcsSource gcsSource = GcsSource.newBuilder().addInputUris(inputUri).build();
        BatchPredictInputConfig inputConfig = BatchPredictInputConfig.newBuilder().setGcsSource(gcsSource).build();
        GcsDestination gcsDestination = GcsDestination.newBuilder().setOutputUriPrefix(outputUri).build();
        BatchPredictOutputConfig outputConfig = BatchPredictOutputConfig.newBuilder().setGcsDestination(gcsDestination).build();
        BatchPredictRequest request = BatchPredictRequest.newBuilder().setName(name.toString()).setInputConfig(inputConfig).setOutputConfig(outputConfig).build();
        OperationFuture<BatchPredictResult, OperationMetadata> future = client.batchPredictAsync(request);
        System.out.println("Waiting for operation to complete...");
        BatchPredictResult response = future.get();
        System.out.println("Batch Prediction results saved to specified Cloud Storage bucket.");
    }
}
Also used : BatchPredictRequest(com.google.cloud.automl.v1.BatchPredictRequest) ModelName(com.google.cloud.automl.v1.ModelName) GcsSource(com.google.cloud.automl.v1.GcsSource) BatchPredictInputConfig(com.google.cloud.automl.v1.BatchPredictInputConfig) BatchPredictOutputConfig(com.google.cloud.automl.v1.BatchPredictOutputConfig) BatchPredictResult(com.google.cloud.automl.v1.BatchPredictResult) GcsDestination(com.google.cloud.automl.v1.GcsDestination) OperationMetadata(com.google.cloud.automl.v1.OperationMetadata) PredictionServiceClient(com.google.cloud.automl.v1.PredictionServiceClient)

Example 14 with OperationMetadata

use of com.google.cloud.documentai.v1beta2.OperationMetadata in project java-automl by googleapis.

the class LanguageEntityExtractionCreateDataset method createDataset.

// Create a dataset
static void createDataset(String projectId, String displayName) throws IOException, ExecutionException, InterruptedException {
    // the "close" method on the client to safely clean up any remaining background resources.
    try (AutoMlClient client = AutoMlClient.create()) {
        // A resource that represents Google Cloud Platform location.
        LocationName projectLocation = LocationName.of(projectId, "us-central1");
        TextExtractionDatasetMetadata metadata = TextExtractionDatasetMetadata.newBuilder().build();
        Dataset dataset = Dataset.newBuilder().setDisplayName(displayName).setTextExtractionDatasetMetadata(metadata).build();
        OperationFuture<Dataset, OperationMetadata> future = client.createDatasetAsync(projectLocation, dataset);
        Dataset createdDataset = future.get();
        // Display the dataset information.
        System.out.format("Dataset name: %s\n", createdDataset.getName());
        // To get the dataset id, you have to parse it out of the `name` field. As dataset Ids are
        // required for other methods.
        // Name Form: `projects/{project_id}/locations/{location_id}/datasets/{dataset_id}`
        String[] names = createdDataset.getName().split("/");
        String datasetId = names[names.length - 1];
        System.out.format("Dataset id: %s\n", datasetId);
    }
}
Also used : Dataset(com.google.cloud.automl.v1.Dataset) TextExtractionDatasetMetadata(com.google.cloud.automl.v1.TextExtractionDatasetMetadata) OperationMetadata(com.google.cloud.automl.v1.OperationMetadata) AutoMlClient(com.google.cloud.automl.v1.AutoMlClient) LocationName(com.google.cloud.automl.v1.LocationName)

Example 15 with OperationMetadata

use of com.google.cloud.documentai.v1beta2.OperationMetadata 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");
    }
}
Also used : Empty(com.google.protobuf.Empty) ModelName(com.google.cloud.automl.v1beta1.ModelName) UndeployModelRequest(com.google.cloud.automl.v1beta1.UndeployModelRequest) OperationMetadata(com.google.cloud.automl.v1beta1.OperationMetadata) AutoMlClient(com.google.cloud.automl.v1beta1.AutoMlClient)

Aggregations

OperationMetadata (com.google.cloud.automl.v1.OperationMetadata)19 AutoMlClient (com.google.cloud.automl.v1.AutoMlClient)18 OperationMetadata (com.google.cloud.automl.v1beta1.OperationMetadata)13 Empty (com.google.protobuf.Empty)13 LocationName (com.google.cloud.automl.v1.LocationName)12 AutoMlClient (com.google.cloud.automl.v1beta1.AutoMlClient)11 ModelName (com.google.cloud.automl.v1beta1.ModelName)8 Dataset (com.google.cloud.automl.v1.Dataset)6 Model (com.google.cloud.automl.v1.Model)6 ModelName (com.google.cloud.automl.v1.ModelName)6 DeployModelRequest (com.google.cloud.automl.v1beta1.DeployModelRequest)4 DeployModelRequest (com.google.cloud.automl.v1.DeployModelRequest)3 LocationName (com.google.cloud.automl.v1beta1.LocationName)3 Model (com.google.cloud.automl.v1beta1.Model)3 Blob (com.google.cloud.storage.Blob)3 Bucket (com.google.cloud.storage.Bucket)3 Storage (com.google.cloud.storage.Storage)3 Page (com.google.api.gax.paging.Page)2 ClassificationType (com.google.cloud.automl.v1.ClassificationType)2 GcsSource (com.google.cloud.automl.v1.GcsSource)2