Search in sources :

Example 1 with CreateInstructionMetadata

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

the class CreateInstruction method createInstruction.

// Create a instruction for a dataset.
static void createInstruction(String projectId, String pdfUri) throws IOException {
    // String projectId = "YOUR_PROJECT_ID";
    // String pdfUri = "gs://YOUR_BUCKET_ID/path_to_pdf_or_csv";
    // [END datalabeling_create_instruction_beta]
    String endpoint = System.getenv("DATALABELING_ENDPOINT");
    if (endpoint == null) {
        endpoint = DataLabelingServiceSettings.getDefaultEndpoint();
    }
    // [START datalabeling_create_instruction_beta]
    DataLabelingServiceSettings settings = DataLabelingServiceSettings.newBuilder().setEndpoint(endpoint).build();
    try (DataLabelingServiceClient dataLabelingServiceClient = DataLabelingServiceClient.create(settings)) {
        ProjectName projectName = ProjectName.of(projectId);
        // There are two types of instructions: CSV (CsvInstruction) or PDF (PdfInstruction)
        PdfInstruction pdfInstruction = PdfInstruction.newBuilder().setGcsFileUri(pdfUri).build();
        Instruction instruction = Instruction.newBuilder().setDisplayName("YOUR_INSTRUCTION_DISPLAY_NAME").setDescription("YOUR_DESCRIPTION").setDataType(// DataTypes: AUDIO, IMAGE, VIDEO, TEXT
        DataType.IMAGE).setPdfInstruction(// .setCsvInstruction() or .setPdfInstruction()
        pdfInstruction).build();
        CreateInstructionRequest createInstructionRequest = CreateInstructionRequest.newBuilder().setInstruction(instruction).setParent(projectName.toString()).build();
        OperationFuture<Instruction, CreateInstructionMetadata> operation = dataLabelingServiceClient.createInstructionAsync(createInstructionRequest);
        Instruction result = operation.get();
        System.out.format("Name: %s\n", result.getName());
        System.out.format("DisplayName: %s\n", result.getDisplayName());
        System.out.format("Description: %s\n", result.getDescription());
        System.out.format("GCS SOURCE URI: %s\n", result.getPdfInstruction().getGcsFileUri());
    } catch (IOException | InterruptedException | ExecutionException e) {
        e.printStackTrace();
    }
}
Also used : DataLabelingServiceClient(com.google.cloud.datalabeling.v1beta1.DataLabelingServiceClient) ProjectName(com.google.cloud.datalabeling.v1beta1.ProjectName) CreateInstructionRequest(com.google.cloud.datalabeling.v1beta1.CreateInstructionRequest) IOException(java.io.IOException) Instruction(com.google.cloud.datalabeling.v1beta1.Instruction) PdfInstruction(com.google.cloud.datalabeling.v1beta1.PdfInstruction) PdfInstruction(com.google.cloud.datalabeling.v1beta1.PdfInstruction) CreateInstructionMetadata(com.google.cloud.datalabeling.v1beta1.CreateInstructionMetadata) DataLabelingServiceSettings(com.google.cloud.datalabeling.v1beta1.DataLabelingServiceSettings) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

CreateInstructionMetadata (com.google.cloud.datalabeling.v1beta1.CreateInstructionMetadata)1 CreateInstructionRequest (com.google.cloud.datalabeling.v1beta1.CreateInstructionRequest)1 DataLabelingServiceClient (com.google.cloud.datalabeling.v1beta1.DataLabelingServiceClient)1 DataLabelingServiceSettings (com.google.cloud.datalabeling.v1beta1.DataLabelingServiceSettings)1 Instruction (com.google.cloud.datalabeling.v1beta1.Instruction)1 PdfInstruction (com.google.cloud.datalabeling.v1beta1.PdfInstruction)1 ProjectName (com.google.cloud.datalabeling.v1beta1.ProjectName)1 IOException (java.io.IOException)1 ExecutionException (java.util.concurrent.ExecutionException)1