Search in sources :

Example 1 with ImportDataOperationMetadata

use of com.google.cloud.datalabeling.v1beta1.ImportDataOperationMetadata in project java-datalabeling by googleapis.

the class ImportData method importData.

// Import data to an existing dataset.
static void importData(String datasetName, String gcsSourceUri) throws IOException {
    // String datasetName = DataLabelingServiceClient.formatDatasetName(
    // "YOUR_PROJECT_ID", "YOUR_DATASETS_UUID");
    // String gcsSourceUri = "gs://YOUR_BUCKET_ID/path_to_data";
    // [END datalabeling_import_data_beta]
    String endpoint = System.getenv("DATALABELING_ENDPOINT");
    if (endpoint == null) {
        endpoint = DataLabelingServiceSettings.getDefaultEndpoint();
    }
    // [START datalabeling_import_data_beta]
    DataLabelingServiceSettings settings = DataLabelingServiceSettings.newBuilder().setEndpoint(endpoint).build();
    try (DataLabelingServiceClient dataLabelingServiceClient = DataLabelingServiceClient.create(settings)) {
        GcsSource gcsSource = GcsSource.newBuilder().setInputUri(gcsSourceUri).setMimeType("text/csv").build();
        InputConfig inputConfig = InputConfig.newBuilder().setDataType(// DataTypes: AUDIO, IMAGE, VIDEO, TEXT
        DataType.IMAGE).setGcsSource(gcsSource).build();
        ImportDataRequest importDataRequest = ImportDataRequest.newBuilder().setName(datasetName).setInputConfig(inputConfig).build();
        OperationFuture<ImportDataOperationResponse, ImportDataOperationMetadata> operation = dataLabelingServiceClient.importDataAsync(importDataRequest);
        ImportDataOperationResponse response = operation.get();
        System.out.format("Imported items: %d\n", response.getImportCount());
    } catch (IOException | InterruptedException | ExecutionException e) {
        e.printStackTrace();
    }
}
Also used : DataLabelingServiceClient(com.google.cloud.datalabeling.v1beta1.DataLabelingServiceClient) GcsSource(com.google.cloud.datalabeling.v1beta1.GcsSource) IOException(java.io.IOException) InputConfig(com.google.cloud.datalabeling.v1beta1.InputConfig) ImportDataRequest(com.google.cloud.datalabeling.v1beta1.ImportDataRequest) ImportDataOperationMetadata(com.google.cloud.datalabeling.v1beta1.ImportDataOperationMetadata) DataLabelingServiceSettings(com.google.cloud.datalabeling.v1beta1.DataLabelingServiceSettings) ExecutionException(java.util.concurrent.ExecutionException) ImportDataOperationResponse(com.google.cloud.datalabeling.v1beta1.ImportDataOperationResponse)

Aggregations

DataLabelingServiceClient (com.google.cloud.datalabeling.v1beta1.DataLabelingServiceClient)1 DataLabelingServiceSettings (com.google.cloud.datalabeling.v1beta1.DataLabelingServiceSettings)1 GcsSource (com.google.cloud.datalabeling.v1beta1.GcsSource)1 ImportDataOperationMetadata (com.google.cloud.datalabeling.v1beta1.ImportDataOperationMetadata)1 ImportDataOperationResponse (com.google.cloud.datalabeling.v1beta1.ImportDataOperationResponse)1 ImportDataRequest (com.google.cloud.datalabeling.v1beta1.ImportDataRequest)1 InputConfig (com.google.cloud.datalabeling.v1beta1.InputConfig)1 IOException (java.io.IOException)1 ExecutionException (java.util.concurrent.ExecutionException)1