use of com.google.cloud.datalabeling.v1beta1.PdfInstruction 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();
}
}
Aggregations