-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore(vision): migrate code from googleapis/nodejs-vision #2858
Changes from 206 commits
4498905
a034a5b
7439369
e69dc4d
fe0f757
fec6285
5f9b9c2
f99996d
d64d538
a49d825
caaaf66
49704f5
65d136d
c637d3b
ef7d36f
4e070aa
9491c47
b05f5ec
443610f
51460b9
53c5293
1354bc9
5323de2
422cc00
0eda176
4211991
43999a6
c2eb8d7
99dbd02
8ad42f5
0c319f1
8406dc7
26e5f89
b858e6a
86b3477
68105af
a44a2d0
b59965e
01fdf52
c993826
7affd50
8ee1650
d8824eb
3cebbf4
5cfa0f1
95d2e92
b5d4480
e627e33
a8fdac7
6eae9dd
44fc0f0
80378f3
dfe677e
39471a9
f48de1e
e39e054
e2ae64e
db1951c
03a1744
f80bb6f
16c0bf0
c62bdb7
c177e01
cff215d
6ca2d6c
f35a4cb
a23f525
9d4e0cc
5dceaea
901c51e
8da00cf
f5d335f
fb35ad2
1e73872
935adbd
56f1c6b
9fb27f9
a25599b
c58e0ce
d6d3cf3
c913cb2
d74b2c8
a0ab1c5
64c7f29
ae39a79
279b932
bcbd3a0
1bc7f0a
4db80be
f789569
0d12ae8
87e1d12
0bdc60a
7b4b7b8
134a0e6
d689d0c
d754fa5
d9bec66
8bbf003
ec1263f
42a7a82
2fa4b42
faa9cbc
b876b17
d1056e3
cb47bd6
4f1ec49
9107649
870f233
7baa84f
8b4218c
0332637
8390c1d
3c6be44
ea59fbc
3efee51
b6f72f6
89972ee
b809154
3092b85
1d9f424
a8b581c
b0abfe6
ff9eebc
09938aa
cea827a
6a46233
2a549ed
897ddb2
5abb8ec
917c672
29031d5
79aad31
c61bd63
dc39e61
01d78b5
d8a77a2
b39b16e
87ab2b7
6c8886d
676f580
ec2cbe4
15f2a11
92676be
f0f6dc7
23a1522
3de2ae4
938aeee
3412348
52ba5a2
7987883
38746b5
ee9b2c1
bb7124a
1131d29
d9a966f
2cc70bb
47bc245
1c1e8e2
17e17d7
4b4853b
7f3d72a
3cd8df9
6dc55a8
2b48199
c61d2ca
33fc5c7
4fc2941
39c1808
a2e86d3
2feefa4
03f23a9
1171cd7
731e3b4
4928362
0c33ea9
a7817fb
0756e4c
e328e8d
dc869a5
b4a3650
903de7a
675c8fe
0f32c3c
916678f
c4d8edd
0a61a30
874d75d
c2a79fb
c7eaa36
15cd0ad
4fc8c22
78da559
1ea9e75
3f50bd9
8a3946e
50c8a5d
9a489b7
16d5be7
6df37a6
1b728af
1d29358
fb27ec2
1e48f69
5759569
101bebd
4a106f0
5244f7c
b85e627
836d9d3
992f531
a808e6a
2195c48
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
name: vision-productSearch | ||
on: | ||
push: | ||
branches: | ||
- main | ||
paths: | ||
- 'vision/productSearch/**' | ||
pull_request: | ||
paths: | ||
- 'vision/productSearch/**' | ||
pull_request_target: | ||
types: [labeled] | ||
paths: | ||
- 'vision/productSearch/**' | ||
schedule: | ||
- cron: '0 0 * * 0' | ||
jobs: | ||
test: | ||
if: ${{ github.event.action != 'labeled' || github.event.label.name == 'actions:force-run' }} | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 60 | ||
permissions: | ||
contents: 'write' | ||
pull-requests: 'write' | ||
id-token: 'write' | ||
steps: | ||
- uses: actions/checkout@v3.1.0 | ||
with: | ||
ref: ${{github.event.pull_request.head.sha}} | ||
- uses: 'google-github-actions/auth@v1.0.0' | ||
with: | ||
workload_identity_provider: 'projects/1046198160504/locations/global/workloadIdentityPools/github-actions-pool/providers/github-actions-provider' | ||
service_account: 'kokoro-system-test@long-door-651.iam.gserviceaccount.com' | ||
create_credentials_file: 'true' | ||
access_token_lifetime: 600s | ||
- uses: actions/setup-node@v3.5.1 | ||
with: | ||
node-version: 16 | ||
- run: npm install | ||
working-directory: vision/productSearch | ||
- run: npm test | ||
working-directory: vision/productSearch | ||
env: | ||
MOCHA_REPORTER_SUITENAME: vision_productSearch | ||
MOCHA_REPORTER_OUTPUT: vision_productSearch_sponge_log.xml | ||
MOCHA_REPORTER: xunit | ||
- if: ${{ github.event.action == 'labeled' && github.event.label.name == 'actions:force-run' }} | ||
uses: actions/github-script@v6 | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
script: | | ||
try { | ||
await github.rest.issues.removeLabel({ | ||
name: 'actions:force-run', | ||
owner: 'GoogleCloudPlatform', | ||
repo: 'nodejs-docs-samples', | ||
issue_number: context.payload.pull_request.number | ||
}); | ||
} catch (e) { | ||
if (!e.message.includes('Label does not exist')) { | ||
throw e; | ||
} | ||
} | ||
- if: ${{ github.event_name == 'schedule'}} | ||
run: | | ||
curl https://github.com/googleapis/repo-automation-bots/releases/download/flakybot-1.1.0/flakybot -o flakybot -s -L | ||
chmod +x ./flakybot | ||
./flakybot --repo GoogleCloudPlatform/nodejs-docs-samples --commit_hash ${{github.sha}} --build_url https://github.com/${{github.repository}}/actions/runs/${{github.run_id}} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
name: vision | ||
on: | ||
push: | ||
branches: | ||
- main | ||
paths: | ||
- 'vision/**' | ||
pull_request: | ||
paths: | ||
- 'vision/**' | ||
pull_request_target: | ||
types: [labeled] | ||
paths: | ||
- 'vision/**' | ||
schedule: | ||
- cron: '0 0 * * 0' | ||
jobs: | ||
test: | ||
if: ${{ github.event.action != 'labeled' || github.event.label.name == 'actions:force-run' }} | ||
runs-on: ubuntu-latest | ||
timeout-minutes: 60 | ||
permissions: | ||
contents: 'write' | ||
pull-requests: 'write' | ||
id-token: 'write' | ||
steps: | ||
- uses: actions/checkout@v3.1.0 | ||
with: | ||
ref: ${{github.event.pull_request.head.sha}} | ||
- uses: 'google-github-actions/auth@v1.0.0' | ||
with: | ||
workload_identity_provider: 'projects/1046198160504/locations/global/workloadIdentityPools/github-actions-pool/providers/github-actions-provider' | ||
service_account: 'kokoro-system-test@long-door-651.iam.gserviceaccount.com' | ||
create_credentials_file: 'true' | ||
access_token_lifetime: 600s | ||
- uses: actions/setup-node@v3.5.1 | ||
with: | ||
node-version: 16 | ||
- run: npm install | ||
working-directory: vision | ||
- run: npm test | ||
working-directory: vision | ||
env: | ||
MOCHA_REPORTER_SUITENAME: vision | ||
MOCHA_REPORTER_OUTPUT: vision_sponge_log.xml | ||
MOCHA_REPORTER: xunit | ||
- if: ${{ github.event.action == 'labeled' && github.event.label.name == 'actions:force-run' }} | ||
uses: actions/github-script@v6 | ||
with: | ||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||
script: | | ||
try { | ||
await github.rest.issues.removeLabel({ | ||
name: 'actions:force-run', | ||
owner: 'GoogleCloudPlatform', | ||
repo: 'nodejs-docs-samples', | ||
issue_number: context.payload.pull_request.number | ||
}); | ||
} catch (e) { | ||
if (!e.message.includes('Label does not exist')) { | ||
throw e; | ||
} | ||
} | ||
- if: ${{ github.event_name == 'schedule'}} | ||
run: | | ||
curl https://github.com/googleapis/repo-automation-bots/releases/download/flakybot-1.1.0/flakybot -o flakybot -s -L | ||
chmod +x ./flakybot | ||
./flakybot --repo GoogleCloudPlatform/nodejs-docs-samples --commit_hash ${{github.sha}} --build_url https://github.com/${{github.repository}}/actions/runs/${{github.run_id}} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,17 +24,20 @@ | |
"cloud-tasks/tutorial-gcf/function", | ||
"composer", | ||
"composer/functions/composer-storage-trigger", | ||
"contact-center-insights", | ||
"container-analysis/snippets", | ||
"containerengine/hello-world", | ||
"container/snippets", | ||
"datacatalog/cloud-client", | ||
"datacatalog/quickstart", | ||
"datalabeling", | ||
"datastore/functions", | ||
"datacatalog/quickstart", | ||
"datastore/functions", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch! |
||
"document-ai", | ||
"endpoints/getting-started", | ||
"endpoints/getting-started-grpc", | ||
"error-reporting", | ||
"game-servers/snippets", | ||
"functions/firebase", | ||
"functions/helloworld", | ||
"functions/http", | ||
|
@@ -48,20 +51,17 @@ | |
"healthcare/fhir", | ||
"healthcare/hl7v2", | ||
"kms", | ||
"game-servers/snippets", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Praise: Thank you for alphabetizing this config file. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, fair enough. I've reverted the alphabetization. |
||
"mediatranslation", | ||
"monitoring/opencensus", | ||
"monitoring/prometheus", | ||
"monitoring/snippets", | ||
"datacatalog/cloud-client", | ||
"datacatalog/quickstart", | ||
"datastore/functions", | ||
"service-directory/snippets", | ||
"scheduler", | ||
"speech", | ||
"talent", | ||
"translate", | ||
"video-intelligence", | ||
"contact-center-insights", | ||
"vision", | ||
"vision/productSearch", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Question 1: Should There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're correct. Done. |
||
"workflows" | ||
] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Praise: Thank you for sorting this in alphabetical order, Eric. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍🏻 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
--- | ||
rules: | ||
no-console: off | ||
node/no-unsupported-features/node-builtins: off |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// Copyright 2019 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Because there is no existing vision sample for which we want to avoid collision, the target path should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
'use strict'; | ||
|
||
function main( | ||
inputImageUri = 'gs://cloud-samples-data/vision/label/wakeupcat.jpg', | ||
outputUri = 'gs://YOUR_BUCKET_ID/path/to/save/results/' | ||
) { | ||
// [START vision_async_batch_annotate_images] | ||
/** | ||
* TODO(developer): Uncomment these variables before running the sample. | ||
*/ | ||
// const inputImageUri = 'gs://cloud-samples-data/vision/label/wakeupcat.jpg'; | ||
// const outputUri = 'gs://YOUR_BUCKET_ID/path/to/save/results/'; | ||
|
||
// Imports the Google Cloud client libraries | ||
const {ImageAnnotatorClient} = require('@google-cloud/vision').v1; | ||
|
||
// Instantiates a client | ||
const client = new ImageAnnotatorClient(); | ||
|
||
// You can send multiple images to be annotated, this sample demonstrates how to do this with | ||
// one image. If you want to use multiple images, you have to create a request object for each image that you want annotated. | ||
async function asyncBatchAnnotateImages() { | ||
// Set the type of annotation you want to perform on the image | ||
// https://cloud.google.com/vision/docs/reference/rpc/google.cloud.vision.v1#google.cloud.vision.v1.Feature.Type | ||
const features = [{type: 'LABEL_DETECTION'}]; | ||
|
||
// Build the image request object for that one image. Note: for additional images you have to create | ||
// additional image request objects and store them in a list to be used below. | ||
const imageRequest = { | ||
image: { | ||
source: { | ||
imageUri: inputImageUri, | ||
}, | ||
}, | ||
features: features, | ||
}; | ||
|
||
// Set where to store the results for the images that will be annotated. | ||
const outputConfig = { | ||
gcsDestination: { | ||
uri: outputUri, | ||
}, | ||
batchSize: 2, // The max number of responses to output in each JSON file | ||
}; | ||
|
||
// Add each image request object to the batch request and add the output config. | ||
const request = { | ||
requests: [ | ||
imageRequest, // add additional request objects here | ||
], | ||
outputConfig, | ||
}; | ||
|
||
// Make the asynchronous batch request. | ||
const [operation] = await client.asyncBatchAnnotateImages(request); | ||
|
||
// Wait for the operation to complete | ||
const [filesResponse] = await operation.promise(); | ||
|
||
// The output is written to GCS with the provided output_uri as prefix | ||
const destinationUri = filesResponse.outputConfig.gcsDestination.uri; | ||
console.log(`Output written to GCS with prefix: ${destinationUri}`); | ||
} | ||
|
||
asyncBatchAnnotateImages(); | ||
// [END vision_async_batch_annotate_images] | ||
} | ||
|
||
process.on('unhandledRejection', err => { | ||
console.error(err.message); | ||
process.exitCode = 1; | ||
}); | ||
|
||
main(...process.argv.slice(2)); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
// Copyright 2019 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
'use strict'; | ||
|
||
function main( | ||
gcsSourceUri = 'gs://cloud-samples-data/vision/document_understanding/kafka.pdf' | ||
) { | ||
// [START vision_batch_annotate_files_gcs] | ||
/** | ||
* TODO(developer): Uncomment these variables before running the sample. | ||
*/ | ||
// const gcsSourceUri = 'gs://cloud-samples-data/vision/document_understanding/kafka.pdf'; | ||
|
||
// Imports the Google Cloud client libraries | ||
const {ImageAnnotatorClient} = require('@google-cloud/vision').v1; | ||
|
||
// Instantiates a client | ||
const client = new ImageAnnotatorClient(); | ||
|
||
// You can send multiple files to be annotated, this sample demonstrates how to do this with | ||
// one file. If you want to use multiple files, you have to create a request object for each file that you want annotated. | ||
async function batchAnnotateFiles() { | ||
// First Specify the input config with the file's uri and its type. | ||
// Supported mime_type: application/pdf, image/tiff, image/gif | ||
// https://cloud.google.com/vision/docs/reference/rpc/google.cloud.vision.v1#inputconfig | ||
const inputConfig = { | ||
mimeType: 'application/pdf', | ||
gcsSource: { | ||
uri: gcsSourceUri, | ||
}, | ||
}; | ||
|
||
// Set the type of annotation you want to perform on the file | ||
// https://cloud.google.com/vision/docs/reference/rpc/google.cloud.vision.v1#google.cloud.vision.v1.Feature.Type | ||
const features = [{type: 'DOCUMENT_TEXT_DETECTION'}]; | ||
|
||
// Build the request object for that one file. Note: for additional files you have to create | ||
// additional file request objects and store them in a list to be used below. | ||
// Since we are sending a file of type `application/pdf`, we can use the `pages` field to | ||
// specify which pages to process. The service can process up to 5 pages per document file. | ||
// https://cloud.google.com/vision/docs/reference/rpc/google.cloud.vision.v1#google.cloud.vision.v1.AnnotateFileRequest | ||
const fileRequest = { | ||
inputConfig: inputConfig, | ||
features: features, | ||
// Annotate the first two pages and the last one (max 5 pages) | ||
// First page starts at 1, and not 0. Last page is -1. | ||
pages: [1, 2, -1], | ||
}; | ||
|
||
// Add each `AnnotateFileRequest` object to the batch request. | ||
const request = { | ||
requests: [fileRequest], | ||
}; | ||
|
||
// Make the synchronous batch request. | ||
const [result] = await client.batchAnnotateFiles(request); | ||
|
||
// Process the results, just get the first result, since only one file was sent in this | ||
// sample. | ||
const responses = result.responses[0].responses; | ||
|
||
for (const response of responses) { | ||
console.log(`Full text: ${response.fullTextAnnotation.text}`); | ||
for (const page of response.fullTextAnnotation.pages) { | ||
for (const block of page.blocks) { | ||
console.log(`Block confidence: ${block.confidence}`); | ||
for (const paragraph of block.paragraphs) { | ||
console.log(` Paragraph confidence: ${paragraph.confidence}`); | ||
for (const word of paragraph.words) { | ||
const symbol_texts = word.symbols.map(symbol => symbol.text); | ||
const word_text = symbol_texts.join(''); | ||
console.log( | ||
` Word text: ${word_text} (confidence: ${word.confidence})` | ||
); | ||
for (const symbol of word.symbols) { | ||
console.log( | ||
` Symbol: ${symbol.text} (confidence: ${symbol.confidence})` | ||
); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
batchAnnotateFiles(); | ||
// [END vision_batch_annotate_files_gcs] | ||
} | ||
|
||
process.on('unhandledRejection', err => { | ||
console.error(err.message); | ||
process.exitCode = 1; | ||
}); | ||
|
||
main(...process.argv.slice(2)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add
vision/productSearch/**
topaths-ignore
so changes to vision-productSearch don't trigger tests of vision.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where would I find the definition for this YAML schema? I've made the change to the YAML file but I don't think it's correct ....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#onpushpull_requestpull_request_targetpathspaths-ignore