Skip to content

Commit a3cbb72

Browse files
nnegreyAce Nassri
authored and
Ace Nassri
committed
docs: move and update beta list samples for video (#344)
1 parent db8256a commit a3cbb72

File tree

4 files changed

+209
-0
lines changed

4 files changed

+209
-0
lines changed

automl/beta/list-datasets.js

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// Copyright 2020 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
'use strict';
16+
17+
function main(projectId = 'YOUR_PROJECT_ID', location = 'us-central1') {
18+
// [START automl_video_classification_list_datasets_beta]
19+
// [START automl_video_object_tracking_list_datasets_beta]
20+
/**
21+
* TODO(developer): Uncomment these variables before running the sample.
22+
*/
23+
// const projectId = 'YOUR_PROJECT_ID';
24+
// const location = 'us-central1';
25+
26+
// Imports the Google Cloud AutoML library
27+
const {AutoMlClient} = require(`@google-cloud/automl`).v1beta1;
28+
29+
// Instantiates a client
30+
const client = new AutoMlClient();
31+
32+
async function listDatasets() {
33+
// Construct request
34+
const request = {
35+
parent: client.locationPath(projectId, location),
36+
filter: 'translation_dataset_metadata:*',
37+
};
38+
39+
const [response] = await client.listDatasets(request);
40+
41+
console.log(`List of datasets:`);
42+
for (const dataset of response) {
43+
console.log(`Dataset name: ${dataset.name}`);
44+
console.log(
45+
`Dataset id: ${
46+
dataset.name.split('/')[dataset.name.split('/').length - 1]
47+
}`
48+
);
49+
console.log(`Dataset display name: ${dataset.displayName}`);
50+
console.log(`Dataset create time`);
51+
console.log(`\tseconds ${dataset.createTime.seconds}`);
52+
console.log(`\tnanos ${dataset.createTime.nanos / 1e9}`);
53+
54+
// [END automl_video_object_tracking_list_datasets_beta]
55+
console.log(
56+
`Video classification dataset metadata: ${dataset.videoClassificationDatasetMetadata}`
57+
);
58+
// [END automl_video_classification_list_datasets_beta]
59+
60+
// [START automl_video_object_tracking_list_datasets_beta]
61+
console.log(
62+
`Video object tracking dataset metadata: ${dataset.videoObjectTrackingDatasetMetadata}`
63+
);
64+
// [START automl_video_classification_list_datasets_beta]
65+
}
66+
}
67+
68+
listDatasets();
69+
// [END automl_video_classification_list_datasets_beta]
70+
// [END automl_video_object_tracking_list_datasets_beta]
71+
}
72+
73+
main(...process.argv.slice(2));

automl/beta/list-models.js

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// Copyright 2020 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
'use strict';
16+
17+
function main(projectId = 'YOUR_PROJECT_ID', location = 'us-central1') {
18+
// [START automl_list_models_beta]
19+
/**
20+
* TODO(developer): Uncomment these variables before running the sample.
21+
*/
22+
// const projectId = 'YOUR_PROJECT_ID';
23+
// const location = 'us-central1';
24+
25+
// Imports the Google Cloud AutoML library
26+
const {AutoMlClient} = require(`@google-cloud/automl`).v1beta1;
27+
28+
// Instantiates a client
29+
const client = new AutoMlClient();
30+
31+
async function listModels() {
32+
// Construct request
33+
const request = {
34+
parent: client.locationPath(projectId, location),
35+
filter: 'translation_model_metadata:*',
36+
};
37+
38+
const [response] = await client.listModels(request);
39+
40+
console.log(`List of models:`);
41+
for (const model of response) {
42+
console.log(`Model name: ${model.name}`);
43+
console.log(`
44+
Model id: ${model.name.split('/')[model.name.split('/').length - 1]}`);
45+
console.log(`Model display name: ${model.displayName}`);
46+
console.log(`Model create time`);
47+
console.log(`\tseconds ${model.createTime.seconds}`);
48+
console.log(`\tnanos ${model.createTime.nanos / 1e9}`);
49+
console.log(`Model deployment state: ${model.deploymentState}`);
50+
}
51+
}
52+
53+
listModels();
54+
// [END automl_list_models_beta]
55+
}
56+
57+
main(...process.argv.slice(2));
+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright 2020 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
'use strict';
16+
17+
const {assert} = require('chai');
18+
const {describe, it} = require('mocha');
19+
const {AutoMlClient} = require('@google-cloud/automl').v1beta1;
20+
21+
const cp = require('child_process');
22+
23+
const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
24+
25+
const LIST_DATASET_REGION_TAG = 'beta/list-datasets';
26+
const LOCATION = 'us-central1';
27+
28+
describe('Automl List Dataset Tests', () => {
29+
const client = new AutoMlClient();
30+
31+
it('should list datasets', async () => {
32+
const projectId = await client.getProjectId();
33+
const list_output = execSync(
34+
`node ${LIST_DATASET_REGION_TAG}.js ${projectId} ${LOCATION}`
35+
);
36+
37+
assert.match(list_output, /Dataset id/);
38+
});
39+
});

automl/test/list-models.beta.test.js

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright 2020 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
'use strict';
16+
17+
const {assert} = require('chai');
18+
const {describe, it} = require('mocha');
19+
const {AutoMlClient} = require('@google-cloud/automl').v1beta1;
20+
21+
const cp = require('child_process');
22+
23+
const execSync = cmd => cp.execSync(cmd, {encoding: 'utf-8'});
24+
25+
const LIST_MODEL_REGION_TAG = 'beta/list-models';
26+
const LOCATION = 'us-central1';
27+
28+
describe('Automl List Model Tests', () => {
29+
const client = new AutoMlClient();
30+
31+
it('should list models', async () => {
32+
const projectId = await client.getProjectId();
33+
34+
// list models
35+
const list_model_output = execSync(
36+
`node ${LIST_MODEL_REGION_TAG}.js ${projectId} ${LOCATION}`
37+
);
38+
assert.match(list_model_output, /Model id:/);
39+
});
40+
});

0 commit comments

Comments
 (0)