Search in sources :

Example 41 with JobServiceClient

use of com.google.cloud.aiplatform.v1beta1.JobServiceClient in project java-aiplatform by googleapis.

the class CreateDataLabelingJobVideoSample method createDataLabelingJobVideo.

static void createDataLabelingJobVideo(String project, String displayName, String datasetId, String instructionUri, String annotationSpec) throws IOException {
    JobServiceSettings jobServiceSettings = JobServiceSettings.newBuilder().setEndpoint("us-central1-aiplatform.googleapis.com:443").build();
    // the "close" method on the client to safely clean up any remaining background resources.
    try (JobServiceClient jobServiceClient = JobServiceClient.create(jobServiceSettings)) {
        String location = "us-central1";
        LocationName locationName = LocationName.of(project, location);
        String jsonString = "{\"annotation_specs\": [ " + annotationSpec + "]}";
        Value.Builder annotationSpecValue = Value.newBuilder();
        JsonFormat.parser().merge(jsonString, annotationSpecValue);
        DatasetName datasetName = DatasetName.of(project, location, datasetId);
        DataLabelingJob dataLabelingJob = DataLabelingJob.newBuilder().setDisplayName(displayName).setLabelerCount(1).setInstructionUri(instructionUri).setInputsSchemaUri("gs://google-cloud-aiplatform/schema/datalabelingjob/inputs/" + "video_classification.yaml").addDatasets(datasetName.toString()).setInputs(annotationSpecValue).putAnnotationLabels("aiplatform.googleapis.com/annotation_set_name", "my_test_saved_query").build();
        DataLabelingJob dataLabelingJobResponse = jobServiceClient.createDataLabelingJob(locationName, dataLabelingJob);
        System.out.println("Create Data Labeling Job Video Response");
        System.out.format("\tName: %s\n", dataLabelingJobResponse.getName());
        System.out.format("\tDisplay Name: %s\n", dataLabelingJobResponse.getDisplayName());
        System.out.format("\tDatasets: %s\n", dataLabelingJobResponse.getDatasetsList());
        System.out.format("\tLabeler Count: %s\n", dataLabelingJobResponse.getLabelerCount());
        System.out.format("\tInstruction Uri: %s\n", dataLabelingJobResponse.getInstructionUri());
        System.out.format("\tInputs Schema Uri: %s\n", dataLabelingJobResponse.getInputsSchemaUri());
        System.out.format("\tInputs: %s\n", dataLabelingJobResponse.getInputs());
        System.out.format("\tState: %s\n", dataLabelingJobResponse.getState());
        System.out.format("\tLabeling Progress: %s\n", dataLabelingJobResponse.getLabelingProgress());
        System.out.format("\tCreate Time: %s\n", dataLabelingJobResponse.getCreateTime());
        System.out.format("\tUpdate Time: %s\n", dataLabelingJobResponse.getUpdateTime());
        System.out.format("\tLabels: %s\n", dataLabelingJobResponse.getLabelsMap());
        System.out.format("\tSpecialist Pools: %s\n", dataLabelingJobResponse.getSpecialistPoolsList());
        for (Map.Entry<String, String> annotationLabelMap : dataLabelingJobResponse.getAnnotationLabelsMap().entrySet()) {
            System.out.println("\tAnnotation Level");
            System.out.format("\t\tkey: %s\n", annotationLabelMap.getKey());
            System.out.format("\t\tvalue: %s\n", annotationLabelMap.getValue());
        }
        Money money = dataLabelingJobResponse.getCurrentSpend();
        System.out.println("\tCurrent Spend");
        System.out.format("\t\tCurrency Code: %s\n", money.getCurrencyCode());
        System.out.format("\t\tUnits: %s\n", money.getUnits());
        System.out.format("\t\tNanos: %s\n", money.getNanos());
    }
}
Also used : Money(com.google.type.Money) JobServiceSettings(com.google.cloud.aiplatform.v1.JobServiceSettings) DatasetName(com.google.cloud.aiplatform.v1.DatasetName) Value(com.google.protobuf.Value) JobServiceClient(com.google.cloud.aiplatform.v1.JobServiceClient) DataLabelingJob(com.google.cloud.aiplatform.v1.DataLabelingJob) Map(java.util.Map) LocationName(com.google.cloud.aiplatform.v1.LocationName)

Example 42 with JobServiceClient

use of com.google.cloud.aiplatform.v1beta1.JobServiceClient in project java-aiplatform by googleapis.

the class CancelBatchPredictionJobSample method cancelBatchPredictionJobSample.

static void cancelBatchPredictionJobSample(String project, String batchPredictionJobId) throws IOException {
    JobServiceSettings jobServiceSettings = JobServiceSettings.newBuilder().setEndpoint("us-central1-aiplatform.googleapis.com:443").build();
    // the "close" method on the client to safely clean up any remaining background resources.
    try (JobServiceClient jobServiceClient = JobServiceClient.create(jobServiceSettings)) {
        String location = "us-central1";
        BatchPredictionJobName batchPredictionJobName = BatchPredictionJobName.of(project, location, batchPredictionJobId);
        jobServiceClient.cancelBatchPredictionJob(batchPredictionJobName);
        System.out.println("Cancelled the Batch Prediction Job");
    }
}
Also used : JobServiceSettings(com.google.cloud.aiplatform.v1.JobServiceSettings) BatchPredictionJobName(com.google.cloud.aiplatform.v1.BatchPredictionJobName) JobServiceClient(com.google.cloud.aiplatform.v1.JobServiceClient)

Example 43 with JobServiceClient

use of com.google.cloud.aiplatform.v1beta1.JobServiceClient in project java-aiplatform by googleapis.

the class CancelDataLabelingJobSample method cancelDataLabelingJob.

static void cancelDataLabelingJob(String project, String dataLabelingJobId) throws IOException {
    JobServiceSettings jobServiceSettings = JobServiceSettings.newBuilder().setEndpoint("us-central1-aiplatform.googleapis.com:443").build();
    // the "close" method on the client to safely clean up any remaining background resources.
    try (JobServiceClient jobServiceClient = JobServiceClient.create(jobServiceSettings)) {
        String location = "us-central1";
        DataLabelingJobName dataLabelingJobName = DataLabelingJobName.of(project, location, dataLabelingJobId);
        jobServiceClient.cancelDataLabelingJob(dataLabelingJobName);
        System.out.println("Cancelled Data labeling job");
    }
}
Also used : JobServiceSettings(com.google.cloud.aiplatform.v1.JobServiceSettings) JobServiceClient(com.google.cloud.aiplatform.v1.JobServiceClient) DataLabelingJobName(com.google.cloud.aiplatform.v1.DataLabelingJobName)

Example 44 with JobServiceClient

use of com.google.cloud.aiplatform.v1beta1.JobServiceClient in project java-talent by googleapis.

the class JobSearchCustomRankingSearch method sampleSearchJobs.

/**
 * Search Jobs using custom rankings
 *
 * @param projectId Your Google Cloud Project ID
 * @param tenantId Identifier of the Tenantd
 */
public static void sampleSearchJobs(String projectId, String tenantId) {
    try (JobServiceClient jobServiceClient = JobServiceClient.create()) {
        TenantOrProjectName parent = TenantName.of(projectId, tenantId);
        String domain = "www.example.com";
        String sessionId = "Hashed session identifier";
        String userId = "Hashed user identifier";
        RequestMetadata requestMetadata = RequestMetadata.newBuilder().setDomain(domain).setSessionId(sessionId).setUserId(userId).build();
        SearchJobsRequest.CustomRankingInfo.ImportanceLevel importanceLevel = SearchJobsRequest.CustomRankingInfo.ImportanceLevel.EXTREME;
        String rankingExpression = "(someFieldLong + 25) * 0.25";
        SearchJobsRequest.CustomRankingInfo customRankingInfo = SearchJobsRequest.CustomRankingInfo.newBuilder().setImportanceLevel(importanceLevel).setRankingExpression(rankingExpression).build();
        String orderBy = "custom_ranking desc";
        SearchJobsRequest request = SearchJobsRequest.newBuilder().setParent(parent.toString()).setRequestMetadata(requestMetadata).setCustomRankingInfo(customRankingInfo).setOrderBy(orderBy).build();
        for (SearchJobsResponse.MatchingJob responseItem : jobServiceClient.searchJobs(request).iterateAll()) {
            System.out.printf("Job summary: %s\n", responseItem.getJobSummary());
            System.out.printf("Job title snippet: %s\n", responseItem.getJobTitleSnippet());
            Job job = responseItem.getJob();
            System.out.printf("Job name: %s\n", job.getName());
            System.out.printf("Job title: %s\n", job.getTitle());
        }
    } catch (Exception exception) {
        System.err.println("Failed to create the client due to: " + exception);
    }
}
Also used : SearchJobsRequest(com.google.cloud.talent.v4beta1.SearchJobsRequest) JobServiceClient(com.google.cloud.talent.v4beta1.JobServiceClient) TenantOrProjectName(com.google.cloud.talent.v4beta1.TenantOrProjectName) Job(com.google.cloud.talent.v4beta1.Job) RequestMetadata(com.google.cloud.talent.v4beta1.RequestMetadata)

Example 45 with JobServiceClient

use of com.google.cloud.aiplatform.v1beta1.JobServiceClient in project java-talent by googleapis.

the class JobSearchHistogramSearch method sampleSearchJobs.

/**
 * Search Jobs with histogram queries
 *
 * @param query Histogram query More info on histogram facets, constants, and built-in functions:
 *     https://godoc.org/google.golang.org/genproto/googleapis/cloud/talent/v4beta1#SearchJobsRequest
 */
public static void sampleSearchJobs(String projectId, String tenantId, String query) {
    try (JobServiceClient jobServiceClient = JobServiceClient.create()) {
        TenantOrProjectName parent = TenantName.of(projectId, tenantId);
        String domain = "www.example.com";
        String sessionId = "Hashed session identifier";
        String userId = "Hashed user identifier";
        RequestMetadata requestMetadata = RequestMetadata.newBuilder().setDomain(domain).setSessionId(sessionId).setUserId(userId).build();
        HistogramQuery histogramQueriesElement = HistogramQuery.newBuilder().setHistogramQuery(query).build();
        List<HistogramQuery> histogramQueries = Arrays.asList(histogramQueriesElement);
        SearchJobsRequest request = SearchJobsRequest.newBuilder().setParent(parent.toString()).setRequestMetadata(requestMetadata).addAllHistogramQueries(histogramQueries).build();
        for (SearchJobsResponse.MatchingJob responseItem : jobServiceClient.searchJobs(request).iterateAll()) {
            System.out.printf("Job summary: %s\n", responseItem.getJobSummary());
            System.out.printf("Job title snippet: %s\n", responseItem.getJobTitleSnippet());
            Job job = responseItem.getJob();
            System.out.printf("Job name: %s\n", job.getName());
            System.out.printf("Job title: %s\n", job.getTitle());
        }
    } catch (Exception exception) {
        System.err.println("Failed to create the client due to: " + exception);
    }
}
Also used : SearchJobsRequest(com.google.cloud.talent.v4beta1.SearchJobsRequest) HistogramQuery(com.google.cloud.talent.v4beta1.HistogramQuery) JobServiceClient(com.google.cloud.talent.v4beta1.JobServiceClient) TenantOrProjectName(com.google.cloud.talent.v4beta1.TenantOrProjectName) Job(com.google.cloud.talent.v4beta1.Job) RequestMetadata(com.google.cloud.talent.v4beta1.RequestMetadata)

Aggregations

JobServiceClient (com.google.cloud.aiplatform.v1.JobServiceClient)21 JobServiceSettings (com.google.cloud.aiplatform.v1.JobServiceSettings)21 JobServiceClient (com.google.cloud.talent.v4beta1.JobServiceClient)19 Job (com.google.cloud.talent.v4beta1.Job)16 LocationName (com.google.cloud.aiplatform.v1.LocationName)15 Value (com.google.protobuf.Value)10 BatchPredictionJob (com.google.cloud.aiplatform.v1.BatchPredictionJob)9 GcsDestination (com.google.cloud.aiplatform.v1.GcsDestination)8 GcsSource (com.google.cloud.aiplatform.v1.GcsSource)8 JobServiceClient (com.google.cloud.talent.v4.JobServiceClient)8 Job (com.google.cloud.talent.v4.Job)7 TenantOrProjectName (com.google.cloud.talent.v4beta1.TenantOrProjectName)7 TenantName (com.google.cloud.talent.v4.TenantName)6 RequestMetadata (com.google.cloud.talent.v4beta1.RequestMetadata)6 SearchJobsRequest (com.google.cloud.talent.v4beta1.SearchJobsRequest)6 DataLabelingJob (com.google.cloud.aiplatform.v1.DataLabelingJob)5 MachineSpec (com.google.cloud.aiplatform.v1.MachineSpec)5 BigQueryDestination (com.google.cloud.aiplatform.v1.BigQueryDestination)4 BigQuerySource (com.google.cloud.aiplatform.v1.BigQuerySource)4 CreateJobRequest (com.google.cloud.talent.v4beta1.CreateJobRequest)4