feat: Add new gcloud commands, API clients, and third-party libraries across various services.

This commit is contained in:
2026-01-01 20:26:35 +01:00
parent 5e23cbece0
commit a19e592eb7
25221 changed files with 8324611 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
# -*- coding: utf-8 -*- #
# Copyright 2017 Google LLC. All Rights Reserved.
#
# 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.
"""Command group for Machine Learning."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
@base.ReleaseTracks(
base.ReleaseTrack.ALPHA,
base.ReleaseTrack.BETA,
base.ReleaseTrack.GA,
)
class Ml(base.Group):
"""Use Google Cloud machine learning capabilities."""
category = base.AI_AND_MACHINE_LEARNING_CATEGORY
def Filter(self, context, args):
# TODO(b/190537641): Determine if command group works with project number
base.RequireProjectID(args)
del context, args

View File

@@ -0,0 +1,30 @@
# -*- coding: utf-8 -*- #
# Copyright 2017 Google LLC. All Rights Reserved.
#
# 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.
"""Command group for ml language."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
class Language(base.Group):
"""Use the Google Cloud Natural Language API to analyze text.
For more information, please see
https://cloud.google.com/natural-language/.
"""

View File

@@ -0,0 +1,123 @@
help_text:
language_help: |
Currently English, Spanish, Japanese, Chinese (Simplified and Traditional),
French, German, Italian, Korean, and Portuguese are supported.
language_help_ga: |
Currently English, Spanish, and Japanese are supported.
language_examples:
AE: |
To analyze entites in raw content 'puppies':
$ {command} --content='puppies'
To analyze entites in file 'myfile.txt':
$ {command} --content-file='myfile.txt'
To analyze entites in a remote file 'gs://bucket_name/mycontent.html' for Japanese language using
UTF-8 encoding:
$ {command} --content-file='gs://bucket_name/mycontent.html' --content-type=HTML --encoding-type=utf8 --language=ja-JP
AES: |
To analyze entity sentiment in raw content 'puppies':
$ {command} --content='puppies'
To analyze entity sentiment in file 'myfile.txt':
$ {command} --content-file='myfile.txt'
To analyze entity sentiment in a remote file 'gs://bucket_name/mycontent.html' for Japanese language using
UTF-8 encoding:
$ {command} --content-file='gs://bucket_name/mycontent.html' --content-type=HTML --encoding-type=utf8 --language=ja-JP
AS: |
To analyze sentiment in raw content 'I love puppies.':
$ {command} --content='I love puppies.'
To analyze sentiment in file 'myfile.txt':
$ {command} --content-file='myfile.txt'
To analyze sentiment in a remote file 'gs://bucket_name/mycontent.html' for Japanese language using
UTF-8 encoding:
$ {command} --content-file='gs://bucket_name/mycontent.html' --content-type=HTML --encoding-type=utf8 --language=ja-JP
ASX: |
To analyze syntax in raw content 'They drink.':
$ {command} --content='They drink'
To analyze syntax in file 'myfile.txt':
$ {command} --content-file='myfile.txt'
To analyze syntax in a remote file 'gs://bucket_name/mycontent.html' for Japanese language using
UTF-8 encoding:
$ {command} --content-file='gs://bucket_name/mycontent.html' --content-type=HTML --encoding-type=utf8 --language=ja-JP
CT: |
To classify text in raw content 'Long Political Text.':
$ {command} --content='Long Political Text.'
To classify text in file 'myfile.txt':
$ {command} --content-file='myfile.txt'
To classify text in a remote file 'gs://bucket_name/mycontent.html' for Japanese language:
$ {command} --content-file='gs://bucket_name/mycontent.html' --content-type=HTML --language=ja-JP
request:
collection: language.documents
api_version: v1
modify_request_hooks:
- googlecloudsdk.command_lib.ml.language.util:UpdateRequestWithInput
args:
content:
api_field: document.type
arg_name: content-type
default: plain-text
choices:
- arg_value: plain-text
enum_value: PLAIN_TEXT
- arg_value: html
enum_value: HTML
help_text: Specify the format of the input text.
language:
api_field: document.language
arg_name: language
help_text: |
Specify the language of the input text. If omitted, the server will
attempt to auto-detect. Both ISO (such as `en` or `es`) and BCP-47 (such
as `en-US` or `ja-JP`) language codes are accepted.
encoding:
api_field: encodingType
arg_name: encoding-type
default: utf8
help_text: |
The encoding type used by the API to calculate offsets. If set to `none`,
encoding-dependent offsets will be set at -1. This is an optional flag
only used for the entity mentions in results, and does not affect how the
input is read or analyzed.
content_group:
group:
mutex: true
required: true
params:
- arg_name: content
help_text: |
Specify input text on the command line. Useful for experiments, or
for extremely short text.
- arg_name: content-file
help_text: |
Specify a local file or Google Cloud Storage (format
`gs://bucket/object`) file path containing the text to be analyzed.
More useful for longer text or data output from another system.

View File

@@ -0,0 +1,55 @@
- release_tracks: [GA]
help_text:
brief: Use Google Cloud Natural Language API to identify entities in text.
description: |
Entity Analysis inspects the given text for common names or known entities
(proper nouns such as public figures, landmarks, etc.), and returns
information about those entities.
{language_help}
language_help: !COMMON help_text.language_help_ga
examples: !COMMON help_text.language_examples.AE
request:
_COMMON_: request
method: analyzeEntities
arguments:
params:
- _COMMON_: args.content_group
- _COMMON_: args.content
- _COMMON_: args.language
- _COMMON_: args.encoding
output:
format: json
- release_tracks: [ALPHA, BETA]
help_text:
brief: Use Google Cloud Natural Language API to identify entities in text.
description: |
Entity Analysis inspects the given text for common names or known entities
(proper nouns such as public figures, landmarks, etc.), and returns
information about those entities.
{language_help}
language_help: !COMMON help_text.language_help
examples: !COMMON help_text.language_examples.AE
request:
_COMMON_: request
api_version: v1beta2
method: analyzeEntities
arguments:
params:
- _COMMON_: args.content_group
- _COMMON_: args.content
- _COMMON_: args.language
- _COMMON_: args.encoding
output:
format: json

View File

@@ -0,0 +1,53 @@
- release_tracks: [GA]
help_text:
brief: Use Google Cloud Natural Language API to identify entity-level sentiment.
description: |
Entity level sentiment combines both entity analysis and sentiment analysis
and attempts to determine the sentiment (positive or negative) expressed
about entities within the text.
Currently only English is supported for this feature.
examples: !COMMON help_text.language_examples.AES
request:
_COMMON_: request
method: analyzeEntitySentiment
arguments:
params:
- _COMMON_: args.content_group
- _COMMON_: args.content
- _COMMON_: args.language
- _COMMON_: args.encoding
output:
format: json
- release_tracks: [ALPHA, BETA]
help_text:
brief: Use Google Cloud Natural Language API to identify entity-level sentiment.
description: |
Entity level sentiment combines both entity analysis and sentiment analysis
and attempts to determine the sentiment (positive or negative) expressed
about entities within the text.
Currently only English is supported for this feature.
examples: !COMMON help_text.language_examples.AES
request:
_COMMON_: request
api_version: v1beta2
method: analyzeEntitySentiment
arguments:
params:
- _COMMON_: args.content_group
- _COMMON_: args.content
- _COMMON_: args.language
- _COMMON_: args.encoding
output:
format: json

View File

@@ -0,0 +1,55 @@
- release_tracks: [GA]
help_text:
brief: Use Google Cloud Natural Language API to identify sentiments in a text.
description: |
Sentiment Analysis inspects the given text and identifies the prevailing
emotional opinion within the text, especially to determine a writer's
attitude as positive, negative, or neutral.
{language_help}
language_help: !COMMON help_text.language_help_ga
examples: !COMMON help_text.language_examples.AS
request:
_COMMON_: request
method: analyzeSentiment
arguments:
params:
- _COMMON_: args.content_group
- _COMMON_: args.content
- _COMMON_: args.language
- _COMMON_: args.encoding
output:
format: json
- release_tracks: [ALPHA, BETA]
help_text:
brief: Use Google Cloud Natural Language API to identify sentiments in a text.
description: |
Sentiment Analysis inspects the given text and identifies the prevailing
emotional opinion within the text, especially to determine a writer's
attitude as positive, negative, or neutral.
{language_help}
language_help: !COMMON help_text.language_help
examples: !COMMON help_text.language_examples.AS
request:
_COMMON_: request
api_version: v1beta2
method: analyzeSentiment
arguments:
params:
- _COMMON_: args.content_group
- _COMMON_: args.content
- _COMMON_: args.language
- _COMMON_: args.encoding
output:
format: json

View File

@@ -0,0 +1,55 @@
- release_tracks: [GA]
help_text:
brief: Use Google Cloud Natural Language API to identify linguistic information.
description: |
Syntactic Analysis extracts linguistic information, breaking up the given
text into a series of sentences and tokens (generally, word boundaries),
providing further analysis on those tokens.
{language_help}
language_help: !COMMON help_text.language_help_ga
examples: !COMMON help_text.language_examples.ASX
request:
_COMMON_: request
method: analyzeSyntax
arguments:
params:
- _COMMON_: args.content_group
- _COMMON_: args.content
- _COMMON_: args.language
- _COMMON_: args.encoding
output:
format: json
- release_tracks: [ALPHA, BETA]
help_text:
brief: Use Google Cloud Natural Language API to identify linguistic information.
description: |
Syntactic Analysis extracts linguistic information, breaking up the given
text into a series of sentences and tokens (generally, word boundaries),
providing further analysis on those tokens.
{language_help}
language_help: !COMMON help_text.language_help
examples: !COMMON help_text.language_examples.ASX
request:
_COMMON_: request
api_version: v1beta2
method: analyzeSyntax
arguments:
params:
- _COMMON_: args.content_group
- _COMMON_: args.content
- _COMMON_: args.language
- _COMMON_: args.encoding
output:
format: json

View File

@@ -0,0 +1,55 @@
- release_tracks: [GA]
help_text:
brief: Classifies input document into categories.
description: |
Classifies input document into categories. Returns a list of categories
representing the document. Only the most relevant categories a document
are returned e.g. if `/Science` and `/Science/Astronomy` both apply to a
document, then only the `/Science/Astronomy` category is returned, as it
is the more specific result.
Currently only English is supported for this feature.
examples: !COMMON help_text.language_examples.CT
request:
_COMMON_: request
api_version: v1
method: classifyText
arguments:
params:
- _COMMON_: args.content_group
- _COMMON_: args.content
- _COMMON_: args.language
output:
format: json
- release_tracks: [ALPHA, BETA]
help_text:
brief: Classifies input document into categories.
description: |
Classifies input document into categories. Returns a list of categories
representing the document. Only the most relevant categories a document
are returned e.g. if `/Science` and `/Science/Astronomy` both apply to a
document, then only the `/Science/Astronomy` category is returned, as it
is the more specific result.
Currently only English is supported for this feature.
examples: !COMMON help_text.language_examples.CT
request:
_COMMON_: request
api_version: v1beta2
method: classifyText
arguments:
params:
- _COMMON_: args.content_group
- _COMMON_: args.content
- _COMMON_: args.language
output:
format: json

View File

@@ -0,0 +1,43 @@
# -*- coding: utf-8 -*- #
# Copyright 2017 Google LLC. All Rights Reserved.
#
# 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.
"""Command group for ml speech."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
@base.ReleaseTracks(base.ReleaseTrack.GA,
base.ReleaseTrack.BETA,
base.ReleaseTrack.ALPHA)
class Speech(base.Group):
"""Use Google Cloud Speech to get transcripts of audio.
Use Google Cloud Speech to get transcripts of recorded audio, and to
get information about long-running speech recognition operations. For
audio under 60 seconds, use:
$ {command} recognize
For audio 60 seconds or longer, use:
$ {command} recognize-long-running
For more information about the Google Cloud Speech API, refer to this
guide: https://cloud.google.com/speech/docs/
"""

View File

@@ -0,0 +1,253 @@
examples:
recognize: |
To get a transcript of an audio file 'my-recording.wav':
$ {command} 'my-recording.wav' --language-code=en-US
To get a transcript of an audio file in bucket 'gs://bucket/myaudio' with a
custom sampling rate and encoding that uses hints and filters profanity:
$ {command} 'gs://bucket/myaudio' --language-code=es-ES --sample-rate=2200 --hints=Bueno --encoding=OGG_OPUS --filter-profanity
args_v1:
- api_field: audio
arg_name: audio
help_text: |
The location of the audio file to transcribe. Must be a local path or a
Google Cloud Storage URL (in the format gs://bucket/object).
is_positional: true
processor: googlecloudsdk.command_lib.ml.speech.util:GetAudioHook:version=v1
args_v1p1beta1:
- api_field: audio
arg_name: audio
help_text: |
The location of the audio file to transcribe. Must be a local path or a
Google Cloud Storage URL (in the format gs://bucket/object).
is_positional: true
processor: googlecloudsdk.command_lib.ml.speech.util:GetAudioHook:version=v1p1beta1
- api_field: config.enableWordConfidence
arg_name: include-word-confidence
help_text: |
Include a list of words and the confidence for those words in the top
result.
- group:
params:
- api_field: config.diarizationSpeakerCount
arg_name: diarization-speaker-count
type: int
help_text: |
Estimated number of speakers in the conversation being recognized.
- api_field: config.enableSpeakerDiarization
arg_name: enable-speaker-diarization
help_text: |
Enable speaker detection for each recognized word in the top
alternative of the recognition result using an integer speaker_tag
provided in the WordInfo.
type: bool
required: true
- api_field: config.alternativeLanguageCodes
arg_name: additional-language-codes
metavar: language_code
repeated: true
help_text: |
The BCP-47 language tags of other languages that the speech may be
in. Up to 3 can be provided.
If alternative languages are listed, recognition result will contain
recognition in the most likely language detected including the main
language-code.
args_v1p1beta1_alpha_track: # available only in 'gcloud alpha'
- arg_name: enable-automatic-punctuation
api_field: config.enableAutomaticPunctuation
help_text: |
Adds punctuation to recognition result hypotheses.
- group:
help_text: Description of audio data to be recognized.
params:
- arg_name: interaction-type
api_field: config.metadata.interactionType
help_text: |
Determining the interaction type in the conversation.
choices:
- arg_value: discussion
enum_value: DISCUSSION
help_text: Multiple people in a conversation or discussion.
- arg_value: phone-call
enum_value: PHONE_CALL
help_text: A phone-call or video-conference in which two or more people, who are not in the same room, are actively participating.
- arg_value: voicemail
enum_value: VOICEMAIL
help_text: A recorded message intended for another person to listen to.
- arg_value: professionally-produced
enum_value: PROFESSIONALLY_PRODUCED
help_text: Professionally produced audio (eg. TV Show, Podcast).
- arg_value: voice-search
enum_value: VOICE_SEARCH
help_text: Transcribe spoken questions and queries into text.
- arg_value: voice-command
enum_value: VOICE_COMMAND
help_text: Transcribe voice commands, such as for controlling a device.
- arg_value: dictation
enum_value: DICTATION
help_text: Transcribe speech to text to create a written document, such as a text-message, email or report.
- arg_name: naics-code
api_field: config.metadata.industryNaicsCodeOfAudio
type: int
help_text: |
The industry vertical to which this speech recognition request most closely applies.
- arg_name: microphone-distance
api_field: config.metadata.microphoneDistance
help_text: |
The distance at which the audio device is placed to record the conversation.
choices:
- arg_value: nearfield
enum_value: NEARFIELD
help_text: The speaker is within 1 meter of the microphone.
- arg_value: midfield
enum_value: MIDFIELD
help_text: The speaker is within 3 meters of the microphone.
- arg_value: farfield
enum_value: FARFIELD
help_text: The speaker is more than 3 meters away from the microphone.
- arg_name: original-media-type
api_field: config.metadata.originalMediaType
help_text: |
The media type of the original audio conversation.
choices:
- arg_value: audio
enum_value: AUDIO
help_text: The speech data is an audio recording.
- arg_value: video
enum_value: VIDEO
help_text: The speech data originally recorded on a video.
- arg_name: recording-device-type
api_field: config.metadata.recordingDeviceType
help_text: |
The device type through which the original audio was recorded on.
choices:
- arg_value: smartphone
enum_value: SMARTPHONE
help_text: Speech was recorded on a smartphone.
- arg_value: pc
enum_value: PC
help_text: Speech was recorded using a personal computer or tablet.
- arg_value: phone-line
enum_value: PHONE_LINE
help_text: Speech was recorded over a phone line.
- arg_value: vehicle
enum_value: VEHICLE
help_text: Speech was recorded in a vehicle.
- arg_value: outdoor
enum_value: OTHER_OUTDOOR_DEVICE
help_text: Speech was recorded outdoors.
- arg_value: indoor
enum_value: OTHER_INDOOR_DEVICE
help_text: Speech was recorded indoors.
- arg_name: recording-device-name
api_field: config.metadata.recordingDeviceName
help_text: |
The device used to make the recording. Examples: `Nexus 5X`, `Polycom SoundStation IP 6000`
- arg_name: original-mime-type
api_field: config.metadata.originalMimeType
help_text: |
Mime type of the original audio file. Examples: `audio/m4a`, `audio/mp3`.
- arg_name: audio-topic
api_field: config.metadata.audioTopic
help_text: |
Description of the content, e.g. "Recordings of federal supreme court hearings from 2012".
args:
- group:
help_text: Audio channel settings.
params:
- arg_name: separate-channel-recognition
api_field: config.enableSeparateRecognitionPerChannel
required: true
default: false
help_text: |
Recognition result will contain a `channel_tag` field to state which channel that
result belongs to. If this is not true, only the first channel will be recognized.
- arg_name: audio-channel-count
api_field: config.audioChannelCount
required: true
type: int
help_text: |
The number of channels in the input audio data. Set this for
separate-channel-recognition. Valid values are:
1)LINEAR16 and FLAC are `1`-`8`
2)OGG_OPUS are `1`-`254`
3) MULAW, AMR, AMR_WB and SPEEX_WITH_HEADER_BYTE is only `1`.
- group:
mutex: true
required: true
params:
- api_field: config.languageCode
arg_name: language-code
help_text: |
The language of the supplied audio as a BCP-47
(https://www.rfc-editor.org/rfc/bcp/bcp47.txt) language tag. Example:
"en-US". See https://cloud.google.com/speech/docs/languages for a list
of the currently supported language codes.
- api_field: config.languageCode
arg_name: language
hidden: true
action:
deprecated:
warn: Flag {flag_name} is deprecated. Use --language-code instead.
help_text: |
The language of the supplied audio as a BCP-47
(https://www.rfc-editor.org/rfc/bcp/bcp47.txt) language tag. Example:
"en-US". See https://cloud.google.com/speech/docs/languages for a list
of the currently supported language codes.
- api_field: config.speechContexts.phrases
arg_name: hints
default: []
help_text: |
A list of strings containing word and phrase "hints" so that the speech
recognition is more likely to recognize them. This can be used to
improve the accuracy for specific words and phrases, for example, if
specific commands are typically spoken by the user. This can also be
used to add additional words to the vocabulary of the recognizer. See
https://cloud.google.com/speech/limits#content.
- api_field: config.maxAlternatives
arg_name: max-alternatives
default: 1
help_text: |
Maximum number of recognition hypotheses to be returned. The server
may return fewer than max_alternatives. Valid values are 0-30. A value
of 0 or 1 will return a maximum of one.
- api_field: config.profanityFilter
arg_name: filter-profanity
help_text: |
If True, the server will attempt to filter out profanities, replacing
all but the initial character in each filtered word with asterisks,
e.g. ```f***```.
- api_field: config.encoding
arg_name: encoding
default: encoding-unspecified
help_text: |
The type of encoding of the file. Required if the file format is not
WAV or FLAC.
- api_field: config.sampleRateHertz
arg_name: sample-rate
help_text: |
The sample rate in Hertz. For best results, set the sampling rate of
the audio source to 16000 Hz. If that's not possible, use the native
sample rate of the audio source (instead of re-sampling).
- api_field: config.enableWordTimeOffsets
arg_name: include-word-time-offsets
help_text: |
If True, the top result includes a list of words with the start and
end time offsets (timestamps) for those words. If False, no word-level
time offset information is returned.

View File

@@ -0,0 +1,27 @@
# -*- coding: utf-8 -*- #
# Copyright 2023 Google LLC. All Rights Reserved.
#
# 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.
"""Command group for ml speech locations operations."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
@base.Hidden
class Locations(base.Group):
"""Manage Google cloud speech-to-text locations."""

View File

@@ -0,0 +1,38 @@
# -*- coding: utf-8 -*- #
# Copyright 2023 Google LLC. All Rights Reserved.
#
# 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.
"""Cloud Speech-to-text locations describe command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.ml.speech import client
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.ml.speech import flags_v2
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class Create(base.Command):
"""Obtain details about Speech-to-text location."""
@staticmethod
def Args(parser):
"""Register flags for this command."""
flags_v2.AddLocationPositionalArgToParser(parser)
def Run(self, args):
location = args.CONCEPTS.location.Parse()
speech_client = client.SpeechV2Client()
return speech_client.GetLocation(location)

View File

@@ -0,0 +1,37 @@
# -*- coding: utf-8 -*- #
# Copyright 2023 Google LLC. All Rights Reserved.
#
# 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.
"""Cloud Speech-to-text locations list command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.ml.speech import client
from googlecloudsdk.calliope import base
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class Create(base.ListCommand):
"""List Speech-to-text locations."""
@staticmethod
def Args(parser):
parser.display_info.AddUriFunc(lambda location: location.name)
def Run(self, args):
speech_client = client.SpeechV2Client()
return speech_client.ListLocations(
filter_str=args.filter, limit=args.limit, page_size=args.page_size
)

View File

@@ -0,0 +1,29 @@
# -*- coding: utf-8 -*- #
# Copyright 2017 Google LLC. All Rights Reserved.
#
# 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.
"""Command group for ml speech operations."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
class Operations(base.Group):
"""Interact with Google Cloud Speech operations.
Get information about Google Cloud Speech long-running operations.
"""

View File

@@ -0,0 +1,22 @@
- help_text:
brief: Get description of a long-running speech recognition operation.
description: |
Get information about a long-running speech recognition operation.
examples: |
To fetch details for the operation '12345':
$ {command} 12345
request:
collection: speech.operations
api_version: v1
resource_method_params:
name: '{operationsId}'
arguments:
resource:
help_text: The ID of the operation to describe.
spec: !REF googlecloudsdk.command_lib.ml.speech.resources:operation
output:
format: json

View File

@@ -0,0 +1,28 @@
- help_text:
brief: Poll long-running speech recognition operation until it completes.
description: |
Poll a long-running speech recognition operation until it completes. When
the operation is complete, this command will display the results of the
transcription.
examples: |
To wait for the result of operation '12345':
$ {command} 12345
request:
collection: speech.operations
api_version: v1
arguments:
resource:
help_text: The ID of the operation to wait for.
spec: !REF googlecloudsdk.command_lib.ml.speech.resources:operation
async:
collection: speech.operations
operation_get_method_params:
name: operationsId
result_attribute: response
output:
format: json

View File

@@ -0,0 +1,129 @@
# -*- coding: utf-8 -*- #
# Copyright 2022 Google LLC. All Rights Reserved.
#
# 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.
"""Recognize speech in provided audio."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.util import apis
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.ml.speech import flags
from googlecloudsdk.command_lib.ml.speech import util
@base.ReleaseTracks(base.ReleaseTrack.GA)
class RecognizeGA(base.Command):
"""Get transcripts of short (less than 60 seconds) audio from an audio file."""
detailed_help = {
'DESCRIPTION':
"""\
Get a transcript of an audio file that is less than 60 seconds. You can use
an audio file that is on your local drive or a Google Cloud Storage URL.
If the audio is longer than 60 seconds, you will get an error. Please use
`{parent_command} recognize-long-running` instead.
""",
'EXAMPLES':
"""\
To get a transcript of an audio file 'my-recording.wav':
$ {command} 'my-recording.wav' --language-code=en-US
To get a transcript of an audio file in bucket 'gs://bucket/myaudio' with a
custom sampling rate and encoding that uses hints and filters profanity:
$ {command} 'gs://bucket/myaudio' \\
--language-code=es-ES --sample-rate=2200 --hints=Bueno \\
--encoding=OGG_OPUS --filter-profanity
""",
'API REFERENCE':
"""\
This command uses the speech/v1 API. The full documentation for this API
can be found at: https://cloud.google.com/speech-to-text/docs/quickstart-protocol
"""
}
API_VERSION = 'v1'
flags_mapper = flags.RecognizeArgsToRequestMapper()
@classmethod
def Args(cls, parser):
parser.display_info.AddFormat('json')
cls.flags_mapper.AddRecognizeArgsToParser(parser, cls.API_VERSION)
def MakeRequest(self, args, messages):
return messages.RecognizeRequest(
audio=util.GetRecognitionAudioFromPath(args.audio, self.API_VERSION),
config=self.flags_mapper.MakeRecognitionConfig(args, messages))
def Run(self, args):
"""Run 'ml speech recognize'.
Args:
args: argparse.Namespace, The arguments that this command was invoked
with.
Returns:
Nothing.
"""
client = apis.GetClientInstance(util.SPEECH_API, self.API_VERSION)
self._request = self.MakeRequest(args, client.MESSAGES_MODULE)
return client.speech.Recognize(self._request)
def Epilog(self, unused_resources_were_displayed):
util.MaybePrintSttUiLink(self._request)
@base.ReleaseTracks(base.ReleaseTrack.BETA)
class RecognizeBeta(RecognizeGA):
__doc__ = RecognizeGA.__doc__
detailed_help = RecognizeGA.detailed_help.copy()
API_VERSION = 'v1p1beta1'
@classmethod
def Args(cls, parser):
super(RecognizeBeta, RecognizeBeta).Args(parser)
cls.flags_mapper.AddBetaRecognizeArgsToParser(parser)
def MakeRequest(self, args, messages):
request = super(RecognizeBeta, self).MakeRequest(args, messages)
self.flags_mapper.UpdateBetaArgsInRecognitionConfig(args, request.config)
return request
RecognizeBeta.detailed_help['API REFERENCE'] = """\
This command uses the speech/v1p1beta1 API. The full documentation for this API
can be found at: https://cloud.google.com/speech-to-text/docs/quickstart-protocol
"""
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class RecognizeAlpha(RecognizeBeta):
__doc__ = RecognizeBeta.__doc__
API_VERSION = 'v1p1beta1'
@classmethod
def Args(cls, parser):
super(RecognizeAlpha, RecognizeAlpha).Args(parser)
cls.flags_mapper.AddAlphaRecognizeArgsToParser(parser, cls.API_VERSION)
def MakeRequest(self, args, messages):
request = super(RecognizeAlpha, self).MakeRequest(args, messages)
self.flags_mapper.UpdateAlphaArgsInRecognitionConfig(args, request.config)
return request

View File

@@ -0,0 +1,160 @@
# -*- coding: utf-8 -*- #
# Copyright 2022 Google LLC. All Rights Reserved.
#
# 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.
"""Recognize speech in provided audio."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.util import apis
from googlecloudsdk.api_lib.util import waiter
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.ml.speech import flags
from googlecloudsdk.command_lib.ml.speech import util
# As per https://cloud.google.com/speech-to-text/docs/basics, async recognition
# accepts audios of 480 minutes in duration. Since recognition can run up to 3x
# the audio length setting timeout at that limit.
OPERATION_TIMEOUT_MS = 3 * 480 * 60 * 1000
@base.ReleaseTracks(base.ReleaseTrack.GA)
class RecognizeLongRunningGA(base.Command):
"""Get transcripts of longer audio from an audio file."""
detailed_help = {
'DESCRIPTION':
"""\
Get a transcript of audio up to 80 minutes in length. If the audio is
under 60 seconds, you may also use `{parent_command} recognize` to
analyze it.
""",
'EXAMPLES':
"""\
To block the command from completing until analysis is finished, run:
$ {command} AUDIO_FILE --language-code=LANGUAGE_CODE --sample-rate=SAMPLE_RATE
You can also receive an operation as the result of the command by running:
$ {command} AUDIO_FILE --language-code=LANGUAGE_CODE --sample-rate=SAMPLE_RATE --async
This will return information about an operation. To get information about the
operation, run:
$ {parent_command} operations describe OPERATION_ID
To poll the operation until it's complete, run:
$ {parent_command} operations wait OPERATION_ID
""",
'API REFERENCE':
"""\
This command uses the speech/v1 API. The full documentation for this API
can be found at: https://cloud.google.com/speech-to-text/docs/quickstart-protocol
""",
}
API_VERSION = 'v1'
flags_mapper = flags.RecognizeArgsToRequestMapper()
@classmethod
def Args(cls, parser):
parser.display_info.AddFormat('json')
cls.flags_mapper.AddRecognizeArgsToParser(parser, cls.API_VERSION)
# LRO specific flags.
base.ASYNC_FLAG.AddToParser(parser)
parser.add_argument(
'--output-uri',
type=util.ValidateOutputUri,
help='Location to which the results should be written. Must be a '
'Google Cloud Storage URI.')
def MakeRequest(self, args, messages):
request = messages.LongRunningRecognizeRequest(
audio=util.GetRecognitionAudioFromPath(args.audio, self.API_VERSION),
config=self.flags_mapper.MakeRecognitionConfig(args, messages))
if args.output_uri is not None:
request.outputConfig = messages.TranscriptOutputConfig(
gcsUri=args.output_uri)
return request
def Run(self, args):
"""Run 'ml speech recognize'.
Args:
args: argparse.Namespace, The arguments that this command was invoked
with.
Returns:
Nothing.
"""
client = apis.GetClientInstance(util.SPEECH_API, self.API_VERSION)
self._request = self.MakeRequest(args, client.MESSAGES_MODULE)
operation = client.speech.Longrunningrecognize(self._request)
if args.async_:
return operation
return waiter.WaitFor(
waiter.CloudOperationPollerNoResources(client.operations, lambda x: x),
operation.name,
'Waiting for [{}] to complete. This may take several minutes.'.format(
operation.name),
wait_ceiling_ms=OPERATION_TIMEOUT_MS)
def Epilog(self, unused_resources_were_displayed):
util.MaybePrintSttUiLink(self._request)
@base.ReleaseTracks(base.ReleaseTrack.BETA)
class RecognizeLongRunningBeta(RecognizeLongRunningGA):
__doc__ = RecognizeLongRunningGA.__doc__
detailed_help = RecognizeLongRunningGA.detailed_help.copy()
API_VERSION = 'v1p1beta1'
@classmethod
def Args(cls, parser):
super(RecognizeLongRunningBeta, RecognizeLongRunningBeta).Args(parser)
cls.flags_mapper.AddBetaRecognizeArgsToParser(parser)
def MakeRequest(self, args, messages):
request = super(RecognizeLongRunningBeta, self).MakeRequest(args, messages)
self.flags_mapper.UpdateBetaArgsInRecognitionConfig(args, request.config)
return request
RecognizeLongRunningBeta.detailed_help['API REFERENCE'] = """\
This command uses the speech/v1p1beta1 API. The full documentation for this API
can be found at: https://cloud.google.com/speech-to-text/docs/quickstart-protocol
"""
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class RecognizeLongRunningAlpha(RecognizeLongRunningBeta):
__doc__ = RecognizeLongRunningBeta.__doc__
API_VERSION = 'v1p1beta1'
@classmethod
def Args(cls, parser):
super(RecognizeLongRunningAlpha, RecognizeLongRunningAlpha).Args(parser)
cls.flags_mapper.AddAlphaRecognizeArgsToParser(parser, cls.API_VERSION)
def MakeRequest(self, args, messages):
request = super(RecognizeLongRunningAlpha, self).MakeRequest(args, messages)
self.flags_mapper.UpdateAlphaArgsInRecognitionConfig(args, request.config)
return request

View File

@@ -0,0 +1,26 @@
# -*- coding: utf-8 -*- #
# Copyright 2022 Google LLC. All Rights Reserved.
#
# 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.
"""Command group for ml speech operations."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class Recognizers(base.Group):
"""Manage Google cloud speech-to-text recognizers."""

View File

@@ -0,0 +1,88 @@
# -*- coding: utf-8 -*- #
# Copyright 2022 Google LLC. All Rights Reserved.
#
# 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.
"""Cloud Speech-to-text recognizers create command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.ml.speech import client
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.ml.speech import flag_validations
from googlecloudsdk.command_lib.ml.speech import flags_v2
from googlecloudsdk.core import log
@base.UniverseCompatible
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class Create(base.Command):
"""Create a speech-to-text recognizer."""
def ValidateCreateRecognizerFlags(self, args):
"""Validates create flags."""
flag_validations.ValidateSpeakerDiarization(args)
flag_validations.ValidateDecodingConfig(args)
@staticmethod
def Args(parser):
"""Register flags for this command."""
flags_v2.AddAllFlagsToParser(
parser, require_base_recognizer_attributes=True, use_store_true=True
)
def Run(self, args):
recognizer = args.CONCEPTS.recognizer.Parse()
self.ValidateCreateRecognizerFlags(args)
speech_client = client.SpeechV2Client()
is_async = args.async_
recognition_config, _ = speech_client.InitializeRecognitionConfig(
args.model, args.language_codes
)
recognition_config, _ = speech_client.InitializeDecodingConfigFromArgs(
recognition_config,
args,
)
recognition_config.features, _ = (
speech_client.InitializeASRFeaturesFromArgs(args)
)
operation = speech_client.CreateRecognizer(
recognizer,
args.display_name,
args.model,
args.language_codes,
recognition_config,
)
if is_async:
log.CreatedResource(
operation.name, kind='speech recognizer', is_async=True
)
return operation
resource = speech_client.WaitForRecognizerOperation(
location=recognizer.Parent().Name(),
operation_ref=speech_client.GetOperationRef(operation),
message='waiting for recognizer [{}] to be created'.format(
recognizer.RelativeName()
),
)
log.CreatedResource(resource.name, kind='speech recognizer')
return resource

View File

@@ -0,0 +1,56 @@
# -*- coding: utf-8 -*- #
# Copyright 2022 Google LLC. All Rights Reserved.
#
# 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.
"""Cloud Speech-to-text recognizers delete command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.ml.speech import client
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.ml.speech import flags_v2
from googlecloudsdk.core import log
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class Delete(base.Command):
"""Delete a Speech-to-text recognizer."""
@staticmethod
def Args(parser):
"""Register flags for this command."""
flags_v2.AddRecognizerArgToParser(parser)
base.ASYNC_FLAG.AddToParser(parser)
base.ASYNC_FLAG.SetDefault(parser, False)
def Run(self, args):
recognizer = args.CONCEPTS.recognizer.Parse()
speech_client = client.SpeechV2Client()
is_async = args.async_
operation = speech_client.DeleteRecognizer(recognizer)
if is_async:
log.DeletedResource(
operation.name, kind='speech recognizer', is_async=True)
return operation
resource = speech_client.WaitForRecognizerOperation(
location=recognizer.Parent().Name(),
operation_ref=speech_client.GetOperationRef(operation),
message='waiting for recognizer [{}] to be deleted'.format(
recognizer.RelativeName()))
log.DeletedResource(resource.name, kind='speech recognizer')
return resource

View File

@@ -0,0 +1,38 @@
# -*- coding: utf-8 -*- #
# Copyright 2022 Google LLC. All Rights Reserved.
#
# 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.
"""Cloud Speech-to-text recognizers describe command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.ml.speech import client
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.ml.speech import flags_v2
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class Create(base.Command):
"""Obtain details about Speech-to-text recognizer."""
@staticmethod
def Args(parser):
"""Register flags for this command."""
flags_v2.AddRecognizerArgToParser(parser)
def Run(self, args):
recognizer = args.CONCEPTS.recognizer.Parse()
speech_client = client.SpeechV2Client()
return speech_client.GetRecognizer(recognizer)

View File

@@ -0,0 +1,44 @@
# -*- coding: utf-8 -*- #
# Copyright 2022 Google LLC. All Rights Reserved.
#
# 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.
"""Cloud Speech-to-text recognizers list command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.ml.speech import client
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.ml.speech import flags_v2
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class Create(base.ListCommand):
"""List Speech-to-text recognizers."""
@staticmethod
def Args(parser):
"""Register flags for this command."""
flags_v2.AddLocationArgToParser(parser)
parser.display_info.AddFormat(
'table(name.segment(-1):label=NAME,'
'createTime.date(tz=LOCAL),'
'updateTime.date(tz=LOCAL),'
'model,'
'language_codes.join(sep=","))')
def Run(self, args):
location = args.CONCEPTS.location.Parse()
speech_client = client.SpeechV2Client()
return speech_client.ListRecognizers(location, limit=args.limit)

View File

@@ -0,0 +1,90 @@
# -*- coding: utf-8 -*- #
# Copyright 2024 Google LLC. All Rights Reserved.
#
# 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.
"""Cloud Speech-to-text recognizers run short audio command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.ml.speech import client
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.ml.speech import flag_validations
from googlecloudsdk.command_lib.ml.speech import flags_v2
@base.UniverseCompatible
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class RunBatch(base.Command):
"""Get transcripts of long (more than 60 seconds) audio from a gcloud uri."""
def ValidateRunBatchFlags(self, args):
"""Validates run batch flags."""
flag_validations.ValidateDecodingConfig(args)
flag_validations.ValidateAudioSource(args, batch=True)
@staticmethod
def Args(parser):
"""Register flags for this command."""
flags_v2.AddRecognizeRequestFlagsToParser(parser, add_async_flag=True)
def Run(self, args):
resource = args.CONCEPTS.recognizer.Parse()
speech_client = client.SpeechV2Client()
self.ValidateRunBatchFlags(args)
recognition_config_update_mask = []
recognition_config, recognition_config_update_mask = (
speech_client.InitializeRecognitionConfig(
args.model, args.language_codes, recognition_config_update_mask
)
)
recognition_config, recognition_config_update_mask = (
speech_client.InitializeDecodingConfigFromArgs(
recognition_config,
args,
default_to_auto_decoding_config=True,
update_mask=recognition_config_update_mask,
)
)
recognition_config.features, recognition_config_update_mask = (
speech_client.InitializeASRFeaturesFromArgs(
args, update_mask=recognition_config_update_mask
)
)
if args.hint_phrases or args.hint_phrase_sets:
recognition_config.adaptation, recognition_config_update_mask = (
speech_client.InitializeAdaptationConfigFromArgs(
args, update_mask=recognition_config_update_mask
)
)
operation = speech_client.RunBatch(
resource,
args.audio,
recognition_config,
update_mask=recognition_config_update_mask,
)
if args.async_:
return operation
return speech_client.WaitForBatchRecognizeOperation(
location=resource.Parent().Name(),
operation_ref=operation.name,
message='waiting for batch recognize to finish',
)

View File

@@ -0,0 +1,82 @@
# -*- coding: utf-8 -*- #
# Copyright 2024 Google LLC. All Rights Reserved.
#
# 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.
"""Cloud Speech-to-text recognizers run short audio command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.ml.speech import client
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.ml.speech import flag_validations
from googlecloudsdk.command_lib.ml.speech import flags_v2
@base.UniverseCompatible
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class RunShort(base.Command):
"""Get transcripts of short (less than 60 seconds) audio from an audio file."""
def ValidateRunShortFlags(self, args):
"""Validates run short flags."""
flag_validations.ValidateDecodingConfig(args)
flag_validations.ValidateAudioSource(args)
@staticmethod
def Args(parser):
"""Register flags for this command."""
flags_v2.AddRecognizeRequestFlagsToParser(parser)
def Run(self, args):
resource = args.CONCEPTS.recognizer.Parse()
speech_client = client.SpeechV2Client()
self.ValidateRunShortFlags(args)
recognition_config_update_mask = []
recognition_config, recognition_config_update_mask = (
speech_client.InitializeRecognitionConfig(
args.model, args.language_codes, recognition_config_update_mask
)
)
recognition_config, recognition_config_update_mask = (
speech_client.InitializeDecodingConfigFromArgs(
recognition_config,
args,
default_to_auto_decoding_config=True,
update_mask=recognition_config_update_mask,
)
)
recognition_config.features, recognition_config_update_mask = (
speech_client.InitializeASRFeaturesFromArgs(
args, update_mask=recognition_config_update_mask
)
)
if args.hint_phrases or args.hint_phrase_sets:
recognition_config.adaptation, recognition_config_update_mask = (
speech_client.InitializeAdaptationConfigFromArgs(
args, update_mask=recognition_config_update_mask
)
)
return speech_client.RunShort(
resource,
args.audio,
recognition_config,
recognition_config_update_mask,
)

View File

@@ -0,0 +1,101 @@
# -*- coding: utf-8 -*- #
# Copyright 2022 Google LLC. All Rights Reserved.
#
# 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.
"""Cloud Speech-to-text recognizers update command."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.api_lib.ml.speech import client
from googlecloudsdk.calliope import base
from googlecloudsdk.command_lib.ml.speech import flag_validations
from googlecloudsdk.command_lib.ml.speech import flags_v2
from googlecloudsdk.core import log
@base.UniverseCompatible
@base.ReleaseTracks(base.ReleaseTrack.ALPHA)
class Update(base.Command):
"""Update a Speech-to-text recognizer."""
def ValidateUpdateRecognizerFlags(self, args):
"""Validates update flags."""
flag_validations.ValidateDecodingConfig(args)
@staticmethod
def Args(parser):
"""Register flags for this command."""
flags_v2.AddAllFlagsToParser(parser)
def Run(self, args):
recognizer = args.CONCEPTS.recognizer.Parse()
speech_client = client.SpeechV2Client()
is_async = args.async_
self.ValidateUpdateRecognizerFlags(args)
recognition_config_update_mask = []
recognition_config, recognition_config_update_mask = (
speech_client.InitializeRecognitionConfig(
args.model, args.language_codes, recognition_config_update_mask
)
)
recognition_config, recognition_config_update_mask = (
speech_client.InitializeDecodingConfigFromArgs(
recognition_config,
args,
update_mask=recognition_config_update_mask,
)
)
recognition_config.features, recognition_config_update_mask = (
speech_client.InitializeASRFeaturesFromArgs(
args, update_mask=recognition_config_update_mask
)
)
recognition_config_update_mask = [
'default_recognition_config.' + field
for field in recognition_config_update_mask
]
operation = speech_client.UpdateRecognizer(
recognizer,
args.display_name,
args.model,
args.language_codes,
recognition_config,
update_mask=recognition_config_update_mask,
)
if is_async:
log.UpdatedResource(
operation.name, kind='speech recognizer', is_async=True
)
return operation
resource = speech_client.WaitForRecognizerOperation(
location=recognizer.Parent().Name(),
operation_ref=speech_client.GetOperationRef(operation),
message='waiting for recognizer [{}] to be updated'.format(
recognizer.RelativeName()
),
)
log.UpdatedResource(resource.name, kind='speech recognizer')
return resource

View File

@@ -0,0 +1,27 @@
# -*- coding: utf-8 -*- #
# Copyright 2019 Google LLC. All Rights Reserved.
#
# 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.
"""Command group for ml translate."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
@base.ReleaseTracks(base.ReleaseTrack.BETA, base.ReleaseTrack.ALPHA)
class Translate(base.Group):
"""Cloud ML Translate command groups."""

View File

@@ -0,0 +1,75 @@
- release_tracks: [ALPHA, BETA]
help_text:
brief:
Translates a large volume of text in asynchronous batch mode.
description: |
Translates a large volume of text in asynchronous batch mode. This command
provides real-time output as the inputs are being processed.
examples: |
The following command translates 'input.txt' file into French and Spanish:
$ {command} --source=gs://input.txt=text/plain --zone=us-central1 --target-language-codes=fr-CA,es-ES --source-language=en-US --models=fr-CA=TRL321456,es-ES=general/base --destination=gs://output
request:
collection: translate.projects.locations
method: batchTranslateText
modify_request_hooks:
- googlecloudsdk.command_lib.ml.translate.hooks:UpdateRequestBatchTranslateText
BETA:
api_version: v3
ALPHA:
api_version: v3beta1
arguments:
resource:
help_text: project.
spec: !REF googlecloudsdk.command_lib.ml.translate.resources:project
override_resource_collection: true
params:
- _REF_: googlecloudsdk.command_lib.ml.translate.flags:zone
- arg_name: source
required: true
metavar: FILE_PATH[=FILE_TYPE]
type: 'googlecloudsdk.calliope.arg_parsers:ArgDict:allow_key_only=True'
help_text: |
Comma-separated list of entries of the form FILE_PATH[=FILE_TYPE]
specifying source files and files types for the translation. FILE_PATH must
be a Google Cloud Storage URI. FILE_TYPE defaults to 'text/html' if not
present. Possible FILE_TYPES are 'text/html', 'text/plain'.
Usage:
'--source gs://input/input.txt=text/plain,gs://input/my.html=text/html'
- arg_name: models
metavar: KEY=VALUE
type: 'googlecloudsdk.calliope.arg_parsers:ArgDict:'
help_text: |
Models to use for translation. Comma-separated dictionary where map's key
is target language code, map's value is model name. Value can be a built-in
general model, or an AutoML Translation model.
Usage:
'--models es-ES=TRL321456789,en-US=general/nmt'
- arg_name: glossaries
metavar: KEY=VALUE
type: 'googlecloudsdk.calliope.arg_parsers:ArgDict:'
help_text: |
Glossaries to be applied for translation. Comma-separated dictionary
where map's key is target language code, map's value is glossary name.
- arg_name: destination
required: true
help_text: |
Location to which the results should be written. Must be a Google Cloud
Storage URI.
- arg_name: target-language-codes
type: 'googlecloudsdk.calliope.arg_parsers:ArgList:'
required: true
help_text: |
The languages to which the text is to be translated. Specify up to 10
language codes here.
- arg_name: source-language
required: true
help_text: |
Source language code of the text.

View File

@@ -0,0 +1,51 @@
- release_tracks: [ALPHA, BETA]
help_text:
brief: Use the Google Cloud Translation API to detect languages.
description: |
Detects the language of text in a request.
examples: |
The following command detects the language of 'What beautiful weather!'
$ {command} --content='What beautiful weather!' --zone=us-central1
request:
collection: translate.projects.locations
method: detectLanguage
BETA:
api_version: v3
ALPHA:
api_version: v3beta1
modify_request_hooks:
- googlecloudsdk.command_lib.ml.translate.hooks:UpdateRequestLangDetection
arguments:
resource:
help_text: project.
spec: !REF googlecloudsdk.command_lib.ml.translate.resources:project
override_resource_collection: true
params:
- _REF_: googlecloudsdk.command_lib.ml.translate.flags:zone
- arg_name: mime-type
help_text: |
Format of the source text, for example, 'text/html', 'text/plain'. Defaults to
'text/html'.
- arg_name: model
help_text: |
Language detection model to be used. If not specified, the default
(language-detection/default) model is used.
Authorization requires the following Google IAM permission on the specified resource model:
cloudtranslate.languageDetectionModels.predict
- group:
mutex: true
required: true
help_text: Contents group.
params:
- arg_name: content
help_text: |
Content of the input in string format.
- arg_name: content-file
help_text: |
Specify a local file path with content.

View File

@@ -0,0 +1,52 @@
- release_tracks: [ALPHA, BETA]
help_text:
brief: Returns a list of supported languages for translation.
description: |
List supported languages for translation.
examples: |
The following command lists supported languages.
$ {command} --zone=global
request:
collection: translate.projects.locations
method: getSupportedLanguages
BETA:
api_version: v3
ALPHA:
api_version: v3beta1
modify_request_hooks:
- googlecloudsdk.command_lib.ml.translate.hooks:UpdateRequestGetSupportedLanguages
arguments:
resource:
help_text: endpoint location
spec: !REF googlecloudsdk.command_lib.ml.translate.resources:project
override_resource_collection: true
params:
- _REF_: googlecloudsdk.command_lib.ml.translate.flags:zone
- api_field: displayLanguageCode
arg_name: display-language-code
help_text: |
The language to use to return localized, human-readable name of supported languages.
If missing, then display names aren't returned in the response.
- api_field: model
arg_name: model
help_text: |
Get supported languages of specified model.
Authorization requires one or more of the following Google IAM permissions on the specified
resource model:
cloudtranslate.generalModels.get
automl.models.get
Defaults to 'general/base'.
Usage:
AutoML models: '--model=TRL321456789'
General models: '--model=general/nmt'

View File

@@ -0,0 +1,79 @@
- release_tracks: [ALPHA, BETA]
help_text:
brief: Use the Google Cloud Translation API to translate between languages.
description: |
Translates input text and returns translated text.
examples: |
The following command translates 'What beautiful weather!' into French.
$ {command} --content='What beautiful weather!' --zone=us-central1 --target-language=fr-CA
request:
collection: translate.projects.locations
method: translateText
BETA:
api_version: v3
ALPHA:
api_version: v3beta1
modify_request_hooks:
- googlecloudsdk.command_lib.ml.translate.hooks:UpdateRequestTranslateText
arguments:
resource:
help_text: endpoint location
spec: !REF googlecloudsdk.command_lib.ml.translate.resources:project
override_resource_collection: true
params:
- _REF_: googlecloudsdk.command_lib.ml.translate.flags:zone
- arg_name: model
help_text: |
The model type requested for this translation. The format depends on the model type:
for AutoML Translation models: model-id
for General (built-in) models: general/nmt or general/base
Authorization requires one or more of the following Google IAM permissions on the specified
resource model:
cloudtranslate.generalModels.predict
automl.models.predict
If missing, the system decides which google base model to use.
Usage:
AutoML models: '--model=TRL321456789'
General models: '--model=general/nmt'
- group:
mutex: true
required: true
help_text: Contents group.
params:
- arg_name: content
help_text: |
The content of the input in string format. We recommend that the content be less
than 30k codepoints.
- arg_name: content-file
help_text: |
Specify a local file path containing the text to be translated.
- arg_name: target-language
required: true
help_text: |
The BCP-47 language code to use for translation of the input text.
- arg_name: source-language
help_text: |
The BCP-47 language code of the input text if known, for example, 'en-US' or 'sr-Latn'. If
the source language isn't specified, the API attempts to identify the source language
automatically and returns the source language in the response.
- arg_name: glossary-config
help_text: |
Glossary to be applied. The glossary must be within the same region as the model.
- arg_name: mime-type
help_text: |
The format of the source text, for example, 'text/html', 'text/plain'. Defaults to
'text/html'.

View File

@@ -0,0 +1,28 @@
# -*- coding: utf-8 -*- #
# Copyright 2016 Google LLC. All Rights Reserved.
#
# 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.
"""Command group for ml video."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
@base.ReleaseTracks(
base.ReleaseTrack.GA, base.ReleaseTrack.BETA, base.ReleaseTrack.ALPHA)
class VideoIntelligence(base.Group):
"""Cloud ML Video-Intelligence command groups."""

View File

@@ -0,0 +1,64 @@
request:
collection: videointelligence.videos
method: annotate
api_version: v1
async:
collection: videointelligence.projects.locations.operations
extract_resource_result: false
result_attribute: response
args:
- arg_name: input_path
is_positional: true
help_text: |
Path to the video to be analyzed. Must be a local path or a Google
Cloud Storage URI.
- api_field: outputUri
arg_name: output-uri
help_text: |
Location to which the results should be written. Must be a Google
Cloud Storage URI.
processor: googlecloudsdk.command_lib.ml.video.util:ValidateOutputUri
- api_field: videoContext.segments
arg_name: segments
help_text: |
Segments from the video which you want to analyze (by default, the
entire video will be treated as one segment). Must be in the format
START1:END1[,START2:END2,...] (inclusive). START and END of segments must
be a properly formatted duration string of the form `HhMmSs` where:
```
* H is the number of hours from beginning of video
* M is the number of minutes from the beginning of video
* S is the number of seconds from the beginning of the video
```
H, M and S can be specified as ints or floats for fractional units
(to microsecond resolution). Unit chars (e.g. `h`, `m` or `s`) are
required. Microseconds can be specified using fractional seconds
e.g. 0.000569s == 569 microseconds.
Examples:
0s:23.554048s,24s:29.528064s
0:1m40s,3m50s:5m10.232265s
type: str
processor: googlecloudsdk.command_lib.ml.video.util:ValidateAndParseSegments
- api_field: locationId
arg_name: region
choices:
- arg_value: us-east1
enum_value: us-east1
- arg_value: us-west1
enum_value: us-west1
- arg_value: europe-west1
enum_value: europe-west1
- arg_value: asia-east1
enum_value: asia-east1
help_text: |
Optional Cloud region where annotation should take place. If no region
is specified, a region will be determined based on video file location.

View File

@@ -0,0 +1,33 @@
- release_tracks: []
help_text:
brief: Detect explicit content in videos.
description: |
Detect adult content within a video. Adult content is content generally
appropriate for 18 years of age and older, including but not limited to
nudity, sexual activities, and pornography (including cartoons or anime).
The response includes a bucketized likelihood value, from VERY_UNLIKELY to
VERY_LIKELY. When Explicit Content Detection evaluates a video, it does so on
a per-frame basis and considers visual content only (not audio).
examples: |
To detect explicit content in a video file named 'gs://my_bucket/input_file.mp4', run the following command.:
$ {command} gs://my_bucket/input_file.mp4
request:
_COMMON_: request
static_fields:
features: [EXPLICIT_CONTENT_DETECTION]
modify_request_hooks:
- googlecloudsdk.command_lib.ml.video.util:UpdateRequestWithInput
async:
_COMMON_: async
arguments:
params:
- _COMMON_args
output:
format: json

View File

@@ -0,0 +1,43 @@
- release_tracks: []
help_text:
brief: Detect general labels for videos.
description: |
Detect general categories in videos, such as modes of transportation or
animals. Use the --detection-mode flag to control whether labels are
detected for shots, frames, or both.
examples: |
To detect labels in video file 'gs://my_bucket/input_file.mp4':
$ {command} gs://my_bucket/input_file.mp4
request:
_COMMON_: request
static_fields:
features: [LABEL_DETECTION]
modify_request_hooks:
- googlecloudsdk.command_lib.ml.video.util:UpdateRequestWithInput
async:
_COMMON_: async
arguments:
params:
- _COMMON_args
- api_field: videoContext.labelDetectionConfig.labelDetectionMode
arg_name: detection-mode
help_text: The mode of label detection requested.
choices:
- arg_value: shot
enum_value: SHOT_MODE
help_text: Detect labels at the per-shot level.
- arg_value: frame
enum_value: FRAME_MODE
help_text: Detect labels at the per-frame level.
- arg_value: shot-and-frame
enum_value: SHOT_AND_FRAME_MODE
help_text: Detect labels at both the per-shot and per-frame level.
default: shot
output:
format: json

View File

@@ -0,0 +1,26 @@
- release_tracks: [ALPHA, BETA]
help_text:
brief: Detect and track objects in a video.
description: |
Detect and track objects in a video.
examples: |
To detect and track objects in video file 'gs://my_bucket/input_file.mp4':
$ {command} gs://my_bucket/input_file.mp4
request:
_COMMON_: request
static_fields:
features: [OBJECT_TRACKING]
modify_request_hooks:
- googlecloudsdk.command_lib.ml.video.util:UpdateRequestWithInput
async:
_COMMON_: async
arguments:
params:
- _COMMON_args
output:
format: json

View File

@@ -0,0 +1,27 @@
- release_tracks: []
help_text:
brief: Detect shot changes in videos.
description: |
Detect when the shot changes in a video.
examples: |
To detect shot changes in a video file named 'gs://my_bucket/input_file.mp4', run the following command:
$ {command} gs://my_bucket/input_file.mp4
request:
_COMMON_: request
static_fields:
features: [SHOT_CHANGE_DETECTION]
modify_request_hooks:
- googlecloudsdk.command_lib.ml.video.util:UpdateRequestWithInput
async:
_COMMON_: async
arguments:
params:
- _COMMON_args
output:
format: json

View File

@@ -0,0 +1,33 @@
- release_tracks: [ALPHA, BETA]
help_text:
brief: Detect text in videos.
description: |
Detect text in videos.
examples: |
To detect text in video file 'gs://my_bucket/input_file.mp4':
$ {command} gs://my_bucket/input_file.mp4
request:
_COMMON_: request
static_fields:
features: [TEXT_DETECTION]
modify_request_hooks:
- googlecloudsdk.command_lib.ml.video.util:UpdateRequestWithInput
async:
_COMMON_: async
arguments:
params:
- _COMMON_args
- api_field: videoContext.textDetectionConfig.languageHints
arg_name: language-hints
default: []
help_text: Language hints can be specified if the languages to be detected are known
beforehand. It can increase the accuracy of the detection. Language hints must be language
codes in BCP-47 format. Automatic language detection is performed if no language hints are
provided.
output:
format: json

View File

@@ -0,0 +1,26 @@
# -*- coding: utf-8 -*- #
# Copyright 2016 Google LLC. All Rights Reserved.
#
# 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.
"""Command group for ml operations."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
class Operations(base.Group):
"""Command group for working with Cloud Video Intelligence operations."""

View File

@@ -0,0 +1,22 @@
- release_tracks: []
help_text:
brief: Get description of a long-running video analysis operation.
description: |
Get information about a long-running video analysis operation.
examples: |-
To get information about a long-running operation with name 'projects/my-project/locations/us-east1/operations/123', run the following command:
$ {command} projects/my-project/locations/us-east1/operations/123
request:
collection: videointelligence.projects.locations.operations
api_version: v1
arguments:
resource:
help_text: The ID of the operation to describe.
spec: !REF googlecloudsdk.command_lib.ml.video.resources:operation
output:
format: json

View File

@@ -0,0 +1,28 @@
- release_tracks: []
help_text:
brief: Poll long-running video analysis operation until it completes.
description: |
Poll a long-running video analysis operation until it completes. When
the operation is complete, this command will display the results of the
analysis.
examples: |
To poll a long-running video analysis operation named 'projects/my-project/locations/us-east1/operations/123' until it completes, run the following:
$ {command} projects/my-project/locations/us-east1/operations/123
request:
collection: videointelligence.projects.locations.operations
api_version: v1
arguments:
resource:
help_text: ID for the operation to poll until complete.
spec: !REF googlecloudsdk.command_lib.ml.video.resources:operation
async:
collection: videointelligence.projects.locations.operations
result_attribute: response
output:
format: json

View File

@@ -0,0 +1,86 @@
- release_tracks: [ALPHA, BETA]
help_text:
brief: Transcribe speech in a video.
description: |
Transcribe speech within a video.
examples: |
To transcribe speech in video file 'gs://my_bucket/input_file.mp4':
$ {command} gs://my_bucket/input_file.mp4
request:
_COMMON_: request
static_fields:
features: [SPEECH_TRANSCRIPTION]
modify_request_hooks:
- googlecloudsdk.command_lib.ml.video.util:UpdateRequestWithInput
async:
_COMMON_: async
arguments:
params:
- _COMMON_args
- api_field: videoContext.speechTranscriptionConfig.enableAutomaticPunctuation
arg_name: enable-automatic-punctuation
help_text: |
If enabled, adds punctuation to recognition result hypotheses. This feature is only
available in select languages. Setting this for requests in other languages has no effect at
all. The default disabled case does not add punctuation to result hypotheses.
- api_field: videoContext.speechTranscriptionConfig.enableSpeakerDiarization
arg_name: enable-speaker-diarization
help_text: |
If enabled, perform speaker detection for each recognized word in the top alternative of the
recognition result using a speaker_tag provided in the WordInfo results section. When this
is enabled, we send all the words from the beginning of the audio for the top alternative in
every consecutive responses. This is done in order to improve our speaker tags as our models
learn to identify the speakers in the conversation over time.
- api_field: videoContext.speechTranscriptionConfig.diarizationSpeakerCount
arg_name: diarization-speaker-count
help_text: |
Optional estimated number of speakers in the conversation. If not specified, defaults to
'2'. Ignored unless --enable-speaker-diarization is enabled.
- api_field: videoContext.speechTranscriptionConfig.maxAlternatives
arg_name: max-alternatives
help_text: |
Maximum number of recognition hypotheses to be returned. Specifically, the maximum number of
`SpeechRecognitionAlternative` messages within each `SpeechTranscription`. The server may
return fewer than `max_alternatives`. Valid values are `0`-`30`. A value of `0` or `1` will
return a maximum of one. If omitted, will return a maximum of one
- api_field: videoContext.speechTranscriptionConfig.languageCode
arg_name: language-code
required: true
help_text: |
The language of the supplied audio as a
[BCP-47](https://www.rfc-editor.org/rfc/bcp/bcp47.txt)
language tag. Example: "en-US". See
[Language Support](https://cloud.google.com/speech/docs/languages) for a list of the
currently supported language codes.
- api_field: videoContext.speechTranscriptionConfig.filterProfanity
arg_name: filter-profanity
help_text: |
If enabled, the server will attempt to filter out profanities, replacing all but the
initial character in each filtered word with asterisks, e.g. ```f***```. If disabled or
omitted, profanities will not be filtered out.
- api_field: videoContext.speechTranscriptionConfig.enableWordConfidence
arg_name: enable-word-confidence
help_text: |
If enabled, the top result includes a list of words and the confidence for those words. If
disabled, no word-level confidence information is returned. The default is disabled.
- api_field: videoContext.speechTranscriptionConfig.audioTracks
arg_name: audio-tracks
processor: googlecloudsdk.command_lib.ml.video.util:AudioTrackProcessor
help_text: |
For file formats, such as MXF or MKV, supporting multiple audio tracks, specify up to two
commas separated tracks. Default track is 0.
- api_field: videoContext.speechTranscriptionConfig.speechContexts.phrases
arg_name: hints
default: []
help_text: |
list of strings containing words and phrases "hints" so that the speech recognition is
more likely to recognize them. This can be used to improve the accuracy for specific words
and phrases, for example, if specific commands are typically spoken by the user. This can
also be used to add additional words to the vocabulary of the recognizer. See
(https://cloud.google.com/speech/limits#content).
output:
format: yaml

View File

@@ -0,0 +1,29 @@
# -*- coding: utf-8 -*- #
# Copyright 2017 Google LLC. All Rights Reserved.
#
# 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.
"""Command group for ml vision."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
@base.ReleaseTracks(base.ReleaseTrack.GA,
base.ReleaseTrack.BETA,
base.ReleaseTrack.ALPHA)
class Vision(base.Group):
"""Use Google Cloud Vision to analyze images."""

View File

@@ -0,0 +1,59 @@
help_text:
language_hints: |
Language hints can be provided to Google Cloud Vision API. In most cases,
an empty value yields the best results since it enables automatic language
detection. For languages based on the Latin alphabet, setting
`language_hints` is not needed. Text detection returns an error if one or
more of the specified languages is not one of the supported languages.
(See https://cloud.google.com/vision/docs/languages.) To provide language
hints run:
$ {command} --language-hints ja,ko
request:
collection: vision.images
method: annotate
api_version: v1
response:
error:
field: responses.error
code: code
message: message
args:
image_field:
api_field: requests.image
arg_name: image_path
is_positional: true
help_text: |
Path to the image to be analyzed. This can be either a local path
or a URL. If you provide a local file, the contents will be sent
directly to Google Cloud Vision. If you provide a URL, it must be in
Google Cloud Storage format (gs://bucket/object) or an HTTP URL
(http://... or https://...)
processor: googlecloudsdk.command_lib.ml.vision.util:GetImageFromPath
language_hints_field:
api_field: requests.imageContext.languageHints
arg_name: language-hints
help_text: List of languages to use for text detection.
max_results_field:
api_field: requests.features.maxResults
arg_name: max-results
help_text: Maximum number of results to be provided.
model_field:
api_field: requests.features.model
arg_name: model-version
default: builtin/stable
release_tracks: [ALPHA, BETA]
help_text: |
Model version to use for the feature.
type: str
choices:
- arg_value: builtin/stable
enum_value: builtin/stable
- arg_value: builtin/latest
enum_value: builtin/latest

View File

@@ -0,0 +1,72 @@
- release_tracks: [GA]
help_text:
brief: Detect dense text in an image.
description: |
Detect dense text in an image, such as books and research reports.
Google Cloud Vision uses OCR (Optical Character Recognition) to analyze text.
This is a premium feature for dense text such as books, research
reports, and PDFs. To detect small amounts of text such as on signs, use
`detect-text` instead. For more information on this feature, see the Google
Cloud Vision documentation at https://cloud.google.com/vision/docs/.
{language_hints}
language_hints: !COMMON help_text.language_hints
examples: |
To detect dense text in image 'gs://my_bucket/input_file':
$ {command} gs://my_bucket/input_file
request:
_COMMON_: request
static_fields:
requests.features.type: DOCUMENT_TEXT_DETECTION
response:
_COMMON_: response
arguments:
params:
- _COMMON_: args.image_field
- _COMMON_: args.language_hints_field
output:
format: json
- release_tracks: [ALPHA, BETA]
help_text:
brief: Detect dense text in an image.
description: |
Detect dense text in an image, such as books and research reports.
Google Cloud Vision uses OCR (Optical Character Recognition) to analyze text.
This is a premium feature for dense text such as books, research
reports, and PDFs. To detect small amounts of text such as on signs, use
`detect-text` instead. For more information on this feature, see the Google
Cloud Vision documentation at https://cloud.google.com/vision/docs/.
{language_hints}
language_hints: !COMMON help_text.language_hints
examples: |
To detect dense text in image 'gs://my_bucket/input_file':
$ {command} gs://my_bucket/input_file
request:
_COMMON_: request
static_fields:
requests.features.type: DOCUMENT_TEXT_DETECTION
response:
_COMMON_: response
arguments:
params:
- _COMMON_: args.image_field
- _COMMON_: args.language_hints_field
- _COMMON_: args.model_field
output:
format: json

View File

@@ -0,0 +1,54 @@
- release_tracks: [GA]
help_text:
brief: Detect faces within an image.
description: |
Detect faces within an image.
examples: |
To detect faces in image 'gs://my_bucket/input_file':
$ {command} gs://my_bucket/input_file
request:
_COMMON_: request
static_fields:
requests.features.type: FACE_DETECTION
response:
_COMMON_: response
arguments:
params:
- _COMMON_: args.image_field
- _COMMON_: args.max_results_field
output:
format: json
- release_tracks: [ALPHA, BETA]
help_text:
brief: Detect faces within an image.
description: |
Detect faces within an image.
examples: |
To detect faces in image 'gs://my_bucket/input_file':
$ {command} gs://my_bucket/input_file
request:
_COMMON_: request
static_fields:
requests.features.type: FACE_DETECTION
response:
_COMMON_: response
arguments:
params:
- _COMMON_: args.image_field
- _COMMON_: args.max_results_field
- _COMMON_: args.model_field
output:
format: json

View File

@@ -0,0 +1,52 @@
- release_tracks: [GA]
help_text:
brief: Detect general attributes of an image.
description: |
Detect general attributes of an image, such as dominant color.
examples: |
To detect general attributes of image 'gs://my_bucket/input_file':
$ {command} gs://my_bucket/input_file
request:
_COMMON_: request
static_fields:
requests.features.type: IMAGE_PROPERTIES
response:
_COMMON_: response
arguments:
params:
- _COMMON_: args.image_field
output:
format: json
- release_tracks: [ALPHA, BETA]
help_text:
brief: Detect general attributes of an image.
description: |
Detect general attributes of an image, such as dominant color.
examples: |
To detect general attributes of image 'gs://my_bucket/input_file':
$ {command} gs://my_bucket/input_file
request:
_COMMON_: request
static_fields:
requests.features.type: IMAGE_PROPERTIES
response:
_COMMON_: response
arguments:
params:
- _COMMON_: args.image_field
- _COMMON_: args.model_field
output:
format: json

View File

@@ -0,0 +1,56 @@
- release_tracks: [GA]
help_text:
brief: Detect broad sets of categories within an image.
description: |
Label Detection detects categories in an image, ranging from modes of
transportation to animals.
examples: |
To detect categories in an image 'gs://my_bucket/input_file':
$ {command} gs://my_bucket/input_file
request:
_COMMON_: request
static_fields:
requests.features.type: LABEL_DETECTION
response:
_COMMON_: response
arguments:
params:
- _COMMON_: args.image_field
- _COMMON_: args.max_results_field
output:
format: json
- release_tracks: [ALPHA, BETA]
help_text:
brief: Detect broad sets of categories within an image.
description: |
Label Detection detects categories in an image, ranging from modes of
transportation to animals.
examples: |
To detect categories in an image 'gs://my_bucket/input_file':
$ {command} gs://my_bucket/input_file
request:
_COMMON_: request
static_fields:
requests.features.type: LABEL_DETECTION
response:
_COMMON_: response
arguments:
params:
- _COMMON_: args.image_field
- _COMMON_: args.max_results_field
- _COMMON_: args.model_field
output:
format: json

View File

@@ -0,0 +1,56 @@
- release_tracks: [GA]
help_text:
brief: Detect popular natural and man-made structures within an image.
description: |
Google Cloud Vision will recognize landmarks in an image, such as "Palace
of Fine Arts."
examples: |
To recognize landmarks in an image 'gs://my_bucket/input_file':
$ {command} gs://my_bucket/input_file
request:
_COMMON_: request
static_fields:
requests.features.type: LANDMARK_DETECTION
response:
_COMMON_: response
arguments:
params:
- _COMMON_: args.image_field
- _COMMON_: args.max_results_field
output:
format: json
- release_tracks: [ALPHA, BETA]
help_text:
brief: Detect popular natural and man-made structures within an image.
description: |
Google Cloud Vision will recognize landmarks in an image, such as "Palace
of Fine Arts."
examples: |
To recognize landmarks in an image 'gs://my_bucket/input_file':
$ {command} gs://my_bucket/input_file
request:
_COMMON_: request
static_fields:
requests.features.type: LANDMARK_DETECTION
response:
_COMMON_: response
arguments:
params:
- _COMMON_: args.image_field
- _COMMON_: args.max_results_field
- _COMMON_: args.model_field
output:
format: json

View File

@@ -0,0 +1,54 @@
- release_tracks: [GA]
help_text:
brief: Detect popular product logos within an image.
description: |
Detect popular product logos within an image.
examples: |
To detect product logos in an image 'gs://my_bucket/input_file':
$ {command} gs://my_bucket/input_file
request:
_COMMON_: request
static_fields:
requests.features.type: LOGO_DETECTION
response:
_COMMON_: response
arguments:
params:
- _COMMON_: args.image_field
- _COMMON_: args.max_results_field
output:
format: json
- release_tracks: [ALPHA, BETA]
help_text:
brief: Detect popular product logos within an image.
description: |
Detect popular product logos within an image.
examples: |
To detect product logos in an image 'gs://my_bucket/input_file':
$ {command} gs://my_bucket/input_file
request:
_COMMON_: request
static_fields:
requests.features.type: LOGO_DETECTION
response:
_COMMON_: response
arguments:
params:
- _COMMON_: args.image_field
- _COMMON_: args.max_results_field
- _COMMON_: args.model_field
output:
format: json

View File

@@ -0,0 +1,29 @@
- release_tracks: [ALPHA, BETA, GA]
help_text:
brief: Detect and extract multiple objects in an image with object localization.
description: |
Detect and extract multiple objects in an image with object localization.
Object localization identifies multiple objects in an image
and provides a LocalizedObjectAnnotation for each object in the image.
examples: |
To detect objects for image 'gs://my_bucket/input_file':
$ {command} gs://my_bucket/input_file
request:
_COMMON_: request
static_fields:
requests.features.type: OBJECT_LOCALIZATION
response:
_COMMON_: response
arguments:
params:
- _COMMON_: args.image_field
- _COMMON_: args.model_field
output:
format: json

View File

@@ -0,0 +1,60 @@
- release_tracks: [BETA, ALPHA]
help_text:
brief: detect products within an image
description: |
detect products within an image
examples: |
To detect product in image 'gs://my-bucket/my-image.jpg' by searching in product set
'my-product-set', in category 'toys', run:
$ {command} gs://my-bucket/my-image.jpg --product-set='my-product-set' --product-set-location=us-east1 --category='toys'
request:
_COMMON_: request
static_fields:
requests.features.type: PRODUCT_SEARCH
modify_request_hooks:
- googlecloudsdk.command_lib.ml.vision.product_search.utils:AddProductSetToDetectProductRequest
- googlecloudsdk.command_lib.ml.vision.product_search.utils:AddBoundingPolygonToDetectProductRequest
response:
_COMMON_: response
arguments:
params:
- _COMMON_: args.image_field
- _COMMON_: args.max_results_field
- api_field: requests.imageContext.productSearchParams.productCategories
arg_name: category
help_text: Product category to search in.
required: true
choices:
- arg_value: apparel
enum_value: apparel
- arg_value: homegoods
enum_value: homegoods
- arg_value: toys
enum_value: toys
- api_field: requests.imageContext.productSearchParams.filter
arg_name: filter
help_text: |-
Filter expression to restrict search results based on product labels. ANDs of ORs of
key-value expressions are supported, where expressions within an OR must
have the same key. Expressions separated by AND must have different keys.
An '=' should be used to connect the key and value. For example,
'(color = red OR color = blue) AND brand = Google' is acceptable, but not
'(color = red OR brand = Google)' or 'color: red'.
- arg_name: bounding-polygon
help_text: |-
Bounding polygon around the areas of interest in the image. If it is not specified, system
discretion will be applied. A bounding polygon can be specified by a list of vertices or
normalized vertices. A vertex (x, y) represents a 2D point in the image. x, y are integers
and are in the same scale as the original image. The normalized vertex coordinates are
relative to orginal image and range from 0 to 1. For example,
--bounding-polygon=0.,0.,0.,0.3,0.3,0.,0.3,0.3 specifies a polygon with 4 normalized
vertices - (0., 0.), (0., 0.3), (0.3, 0.), (0.3, 0.3). Notice that the decimal point is
needed for normalized vertex coordindates.
additional_arguments_hook: googlecloudsdk.command_lib.ml.vision.product_search.utils:ProductSetArgsForDetectProduct
output:
format: json

View File

@@ -0,0 +1,56 @@
- release_tracks: [GA]
help_text:
brief: Detect explicit content in an image.
description: |
Safe Search Detection detects adult content, violent content, medical
content and spoof content in an image.
examples: |
To detect adult content, violent content, medical
content and spoof content in an image 'gs://my_bucket/input_file':
$ {command} gs://my_bucket/input_file
request:
_COMMON_: request
static_fields:
requests.features.type: SAFE_SEARCH_DETECTION
response:
_COMMON_: response
arguments:
params:
- _COMMON_: args.image_field
output:
format: json
- release_tracks: [ALPHA, BETA]
help_text:
brief: Detect explicit content in an image.
description: |
Safe Search Detection detects adult content, violent content, medical
content and spoof content in an image.
examples: |
To detect adult content, violent content, medical
content and spoof content in an image 'gs://my_bucket/input_file':
$ {command} gs://my_bucket/input_file
request:
_COMMON_: request
static_fields:
requests.features.type: SAFE_SEARCH_DETECTION
response:
_COMMON_: response
arguments:
params:
- _COMMON_: args.image_field
- _COMMON_: args.model_field
output:
format: json

View File

@@ -0,0 +1,68 @@
- release_tracks: [GA]
help_text:
brief: Detect and extract text within an image.
description: |
Detect and extract text within an image.
Google Cloud Vision uses OCR (Optical Character Recognition) to detect
text within an image, with support for a broad array of languages and
automatic label detection.
{language_hints}
language_hints: !COMMON help_text.language_hints
examples: |
To detect and extract text within an image 'gs://my_bucket/input_file':
$ {command} gs://my_bucket/input_file
request:
_COMMON_: request
static_fields:
requests.features.type: TEXT_DETECTION
response:
_COMMON_: response
arguments:
params:
- _COMMON_: args.image_field
- _COMMON_: args.language_hints_field
output:
format: json
- release_tracks: [ALPHA, BETA]
help_text:
brief: Detect and extract text within an image.
description: |
Detect and extract text within an image.
Google Cloud Vision uses OCR (Optical Character Recognition) to detect
text within an image, with support for a broad array of languages and
automatic label detection.
{language_hints}
language_hints: !COMMON help_text.language_hints
examples: |
To detect and extract text within an image 'gs://my_bucket/input_file':
$ {command} gs://my_bucket/input_file
request:
_COMMON_: request
static_fields:
requests.features.type: TEXT_DETECTION
response:
_COMMON_: response
arguments:
params:
- _COMMON_: args.image_field
- _COMMON_: args.language_hints_field
- _COMMON_: args.model_field
output:
format: json

View File

@@ -0,0 +1,56 @@
- release_tracks: [ALPHA, BETA, GA]
help_text:
brief: Detect and transcribe text from PDF files stored in Google Cloud Storage.
description: |
Detect and transcribe text from PDF files stored in Google Cloud Storage.
The Vision API accepts PDF files up to 2000 pages.
Larger files will return an error.
examples: |
To detect text for input PDF file 'gs://my_bucket/input_file' and store output in 'gs://my_bucket/out_put_prefix':
$ {command} gs://my_bucket/input_file
gs://my_bucket/out_put_prefix
request:
collection: vision.files
method: asyncBatchAnnotate
api_version: v1
static_fields:
requests.features.type: DOCUMENT_TEXT_DETECTION
requests.inputConfig.mimeType: 'application/pdf'
response:
error:
field: error
code: code
message: message
arguments:
params:
- api_field: requests.inputConfig.gcsSource
arg_name: input_file
is_positional: true
help_text: |
Google Cloud Storage location to read the input from. It must be in
Google Cloud Storage format (gs://bucket/object)
processor: googlecloudsdk.command_lib.ml.vision.util:GetGcsSourceFromPath
- api_field: requests.outputConfig.gcsDestination
arg_name: output_path
is_positional: true
help_text: |
Google Cloud Storage location to store the output file. It must be in
Google Cloud Storage format (gs://bucket/object)
processor: googlecloudsdk.command_lib.ml.vision.util:GetGcsDestinationFromPath
- api_field: requests.outputConfig.batchSize
arg_name: batch-size
help_text: |
Maximum number of response protos to put into each output JSON file on
Google Cloud Storage.
The valid range is [1, 100]. If not specified, the default value is 20.
- _COMMON_: args.model_field
output:
format: json

View File

@@ -0,0 +1,55 @@
- release_tracks: [ALPHA, BETA, GA]
help_text:
brief: Detect and transcribe text from TIFF files stored in Google Cloud Storage.
description: |
Detect and transcribe text from TIFF files stored in Google Cloud Storage.
The Vision API accepts TIFF files up to 2000 pages.
Larger files will return an error.
examples: |
To detect text for input TIFF file `gs://my_bucket/input_file` and store output in `gs://my_bucket/out_put_prefix`:
$ {command} gs://my_bucket/input_file
gs://my_bucket/out_put_prefix
request:
collection: vision.files
method: asyncBatchAnnotate
api_version: v1
static_fields:
requests.features.type: DOCUMENT_TEXT_DETECTION
requests.inputConfig.mimeType: 'image/tiff'
response:
error:
field: error
code: code
message: message
arguments:
params:
- api_field: requests.inputConfig.gcsSource
arg_name: input_file
is_positional: true
help_text: |
Google Cloud Storage location to read the input from. It must be in
Google Cloud Storage format (gs://bucket/object)
processor: googlecloudsdk.command_lib.ml.vision.util:GetGcsSourceFromPath
- api_field: requests.outputConfig.gcsDestination
arg_name: output_path
is_positional: true
help_text: |
Google Cloud Storage location to store the output file. It must be in
Google Cloud Storage format (gs://bucket/object)
processor: googlecloudsdk.command_lib.ml.vision.util:GetGcsDestinationFromPath
- api_field: requests.outputConfig.batchSize
arg_name: batch-size
help_text: |
Maximum number of response protos to put into each output JSON file on
Google Cloud Storage.
The valid range is [1, 100]. If not specified, the default value is 20.
- _COMMON_: args.model_field
output:
format: json

View File

@@ -0,0 +1,59 @@
- release_tracks: [GA]
help_text:
brief: Detect entities in an image from similar images on the web.
description: |
Detect entities in an image from similar images on the web.
examples: |
To detect entities in an image `gs://my_bucket/input_file`:
$ {command} gs://my_bucket/input_file
request:
_COMMON_: request
static_fields:
requests.features.type: WEB_DETECTION
response:
_COMMON_: response
arguments:
params:
- _COMMON_: args.image_field
- _COMMON_: args.max_results_field
output:
format: json
- release_tracks: [ALPHA, BETA]
help_text:
brief: Detect entities in an image from similar images on the web.
description: |
Detect entities in an image from similar images on the web.
examples: |
To detect entities in an image `gs://my_bucket/input_file`:
$ {command} gs://my_bucket/input_file
request:
_COMMON_: request
static_fields:
requests.features.type: WEB_DETECTION
response:
_COMMON_: response
arguments:
params:
- _COMMON_: args.image_field
- _COMMON_: args.max_results_field
- _COMMON_: args.model_field
- api_field: requests.imageContext.webDetectionParams.includeGeoResults
arg_name: include-geo-results
action: store_true
help_text: Whether to include results derived from the geo information in the
image.
output:
format: json

View File

@@ -0,0 +1,27 @@
# -*- coding: utf-8 -*- #
# Copyright 2019 Google LLC. All Rights Reserved.
#
# 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.
"""Command group for operations of ml vision."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
@base.ReleaseTracks(base.ReleaseTrack.BETA,
base.ReleaseTrack.ALPHA)
class Operations(base.Group):
"""Manage Google Cloud Vision operations."""

View File

@@ -0,0 +1,25 @@
- release_tracks: [BETA, ALPHA]
help_text:
brief: describe a long-running operation
description: describe a long-running operation
examples: |-
To describe the long-running operation with name 'projects/my-project/locations/us-east1/operations/123', run:
$ {command} projects/my-project/locations/us-east1/operations/123
request:
collection: vision.operations
api_version: v1
disable_resource_check: true
arguments:
params:
- arg_name: operation
api_field: name
is_positional: true
required: true
help_text: |
Full name of the operation to describe.
output:
format: json

View File

@@ -0,0 +1,27 @@
# -*- coding: utf-8 -*- #
# Copyright 2019 Google LLC. All Rights Reserved.
#
# 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.
"""Command group for ml vision product-search."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
@base.ReleaseTracks(base.ReleaseTrack.BETA,
base.ReleaseTrack.ALPHA)
class ProductSearch(base.Group):
"""Uses Google Cloud Vision to analyze product in images."""

View File

@@ -0,0 +1,27 @@
# -*- coding: utf-8 -*- #
# Copyright 2019 Google LLC. All Rights Reserved.
#
# 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.
"""Command group for ml vision product-search images."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
@base.ReleaseTracks(base.ReleaseTrack.BETA,
base.ReleaseTrack.ALPHA)
class Images(base.Group):
"""Use the Google Cloud Vision API to manipulate reference images."""

View File

@@ -0,0 +1,44 @@
- release_tracks: [ALPHA, BETA]
help_text:
brief: create a reference image.
description: create a reference image.
examples: |
To create a reference image 'my-image' in product 'my-product' in the
location 'us-east1' from image of 'gs://my-bucket/image.jpg' with two
bounding polygons, run:
$ {command} my-image --location=my-location --product=my-product --storage-location=gs://my-bucket/image.jpg --flags-file=my-flags.yaml
The content of 'my-flags.yaml' is as following:
```
- --bounding-polygon:
vertices:
- {x: 0, y: 0}
- {x: 0, y: 10}
- {x: 10, y: 0}
- {x: 10, y: 10}
- --bounding-polygon:
normalized-vertices:
- {x: 0.8, y: 0.8}
- {x: 0.8, y: 1}
- {x: 1, y: 0.8}
- {x: 1, y: 1}
```
request:
collection: vision.projects.locations.products.referenceImages
api_version: v1
modify_request_hooks:
- googlecloudsdk.command_lib.ml.vision.product_search.utils:AddBoundingPolygonsToReferenceImageCreationRequest
arguments:
resource:
help_text: Reference image to create.
spec: !REF googlecloudsdk.command_lib.ml.vision.resources:reference_image
params:
- api_field: referenceImage.uri
arg_name: storage-location
required: true
help_text: |-
The Google Cloud Storage URI of the reference image. The URI must start with 'gs://'.
additional_arguments_hook: googlecloudsdk.command_lib.ml.vision.product_search.utils:AddBoundingPolygonsArg

View File

@@ -0,0 +1,17 @@
- release_tracks: [ALPHA, BETA]
help_text:
brief: delete a reference image.
description: delete a reference image.
examples: |
To delete the image 'my-image' from 'my-product' in location of 'us-east1', run:
$ {command} my-image --location=us-east1 --product=my-product
request:
collection: vision.projects.locations.products.referenceImages
api_version: v1
arguments:
resource:
help_text: Reference image to delete.
spec: !REF googlecloudsdk.command_lib.ml.vision.resources:reference_image

View File

@@ -0,0 +1,17 @@
- release_tracks: [ALPHA, BETA]
help_text:
brief: descibe a reference image.
description: descibe a reference image.
examples: |
To describe the image 'my-image' of 'my-product' in location of 'us-east1', run:
$ {command} my-image --location=us-east1 --product=my-product
request:
collection: vision.projects.locations.products.referenceImages
api_version: v1
arguments:
resource:
help_text: Reference image to describe.
spec: !REF googlecloudsdk.command_lib.ml.vision.resources:reference_image

View File

@@ -0,0 +1,30 @@
- release_tracks: [ALPHA, BETA]
help_text:
brief: list all reference images for a product.
description: list all reference images for a product.
examples: |
To list all reference images in product 'my-product' and 'my-product' is in 'us-east1', run:
$ {command} --location=us-east1 --product=my-product
request:
collection: vision.projects.locations.products.referenceImages
api_version: v1
response:
id_field: name
arguments:
resource:
help_text: The product of reference images to list.
spec: !REF googlecloudsdk.command_lib.ml.vision.resources:product
is_positional: false
output:
format: |
table(
name.scope("referenceImages"):label=NAME,
name.scope("products").segment(0):label=PRODUCT,
uri:label=IMAGE_LOCATION
)

View File

@@ -0,0 +1,27 @@
# -*- coding: utf-8 -*- #
# Copyright 2019 Google LLC. All Rights Reserved.
#
# 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.
"""Command group for ml product-search product-sets."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
@base.ReleaseTracks(base.ReleaseTrack.BETA,
base.ReleaseTrack.ALPHA)
class ProductSet(base.Group):
"""Uses Google Cloud Vision to manipulate product sets."""

View File

@@ -0,0 +1,28 @@
- release_tracks: [ALPHA, BETA]
help_text:
brief: Add a product to the specified product set.
description: Add a product to the specified product set. One product can be added to at most 100 product sets.
examples: |
To add product 'my-product' to product set 'my-product-set' in location 'us-east1', run:
$ {command} my-product-set --location=us-east1 --product=my-product
request:
collection: vision.projects.locations.productSets
method: addProduct
modify_request_hooks:
- googlecloudsdk.command_lib.ml.vision.product_search.utils:FixProductInAddProductToProductSetRequest
arguments:
resource:
help_text: Product set to add product to.
spec: !REF googlecloudsdk.command_lib.ml.vision.resources:product_set
params:
- api_field: addProductToProductSetRequest.product
arg_name: product
required: true
help_text: |-
The id of the product to add to the product set. The product must be in the same project
and location as the specified product set.

View File

@@ -0,0 +1,26 @@
- release_tracks: [ALPHA, BETA]
help_text:
brief: Create a new product set.
description: Create a product set.
examples: |-
To create a product set 'my-product-set' in location 'us-east1' with a display name
'my favorite', run:
$ {command} my-product-set --location=us-east1 --display-name='my favorite'
request:
collection: vision.projects.locations.productSets
arguments:
resource:
help_text: Product set to create.
spec: !REF googlecloudsdk.command_lib.ml.vision.resources:product_set
params:
- api_field: productSet.displayName
arg_name: display-name
required: true
help_text: |-
The user provided name for this product set. It must not be empty and can be up to 4096
characters long.

View File

@@ -0,0 +1,17 @@
- release_tracks: [ALPHA, BETA]
help_text:
brief: Delete a product set.
description: Delete a product set.
examples: |-
To delete 'my-product-set' from location 'us-east1', run:
$ {command} my-product-set --location=us-east1
request:
collection: vision.projects.locations.productSets
arguments:
resource:
help_text: Product set to delete.
spec: !REF googlecloudsdk.command_lib.ml.vision.resources:product_set

View File

@@ -0,0 +1,17 @@
- release_tracks: [ALPHA, BETA]
help_text:
brief: Describe a product set.
description: Describe a product set.
examples: |-
To describe 'my-product-set' in location 'us-east1', run:
$ {command} my-product-set --location=us-east1
request:
collection: vision.projects.locations.productSets
arguments:
resource:
help_text: Product set to describe.
spec: !REF googlecloudsdk.command_lib.ml.vision.resources:product_set

View File

@@ -0,0 +1,38 @@
- release_tracks: [ALPHA, BETA]
command_type: GENERIC
help_text:
brief: Import a list of reference images to specified product sets.
description: Import a list of reference images to specified product sets based on a list of image information.
examples: |
To import reference images from 'gs://my-bucket/my-object.csv' into location 'us-east1', run:
$ {command} --location=us-east1 gs://my-bucket/my-object.csv
request:
collection: vision.projects.locations.productSets
disable_resource_check: true
method: import
arguments:
resource:
help_text: Location to import to.
spec: !REF googlecloudsdk.command_lib.ml.vision.resources:location
is_positional: false
override_resource_collection: true
is_parent_resource: true
params:
- api_field: importProductSetsRequest.inputConfig.gcsSource.csvFileUri
arg_name: source
is_positional: true
required: true
help_text: |-
Google Cloud Storage URI of the input csv file which must start with `gs://`.
The format of the input csv file should be one image per line.
In each line, there are 8 columns - `image-uri`, `image-id`, `product-set-id`, `product-id`,
`product-category`, `product-display-name`, `labels`, and `bounding-poly`.
The `image-uri`, `product-set-id`, `product-id`, and `product-category` columns are required.
See https://cloud.google.com/vision/product-search/docs/csv-format for more information on the
csv format and the meaning of each column.
async:
collection: vision.projects.locations.operations
extract_resource_result: false

View File

@@ -0,0 +1,29 @@
- release_tracks: [ALPHA, BETA]
help_text:
brief: List product sets in a location.
description: List product sets in a location.
examples: |-
To list all product sets in location 'us-east1', run:
$ {command} --location=us-east1
request:
collection: vision.projects.locations.productSets
arguments:
resource:
help_text: Location to list all product sets.
spec: !REF googlecloudsdk.command_lib.ml.vision.resources:location
is_positional: false
response:
id_field: name
output:
format: |
table(
name.scope("productSets"):label=NAME,
name.scope("locations").segment(0):label=LOCATION,
displayName
)

View File

@@ -0,0 +1,24 @@
- release_tracks: [ALPHA, BETA]
command_type: LIST
help_text:
brief: List products in a product set.
description: List products in a product set.
examples: |
To list products in product set 'my-product-set' in location 'us-east1', run:
$ {command} --product-set=my-product-set --location=us-east1
request:
collection: vision.projects.locations.productSets.products
method: list
modify_request_hooks:
- googlecloudsdk.command_lib.ml.vision.product_search.utils:FixNameInListProductsInProductSetRequest
arguments:
resource:
help_text: Product set in which to list products.
spec: !REF googlecloudsdk.command_lib.ml.vision.resources:product_set_product
output:
format: json

View File

@@ -0,0 +1,28 @@
- release_tracks: [ALPHA, BETA]
help_text:
brief: Remove a product from a product set.
description: Remove a product from a product set.
examples: |
To remove product 'my-product' from product set 'my-product-set' in location 'us-east1', run:
$ {command} my-product-set --location=us-east1 --product=my-product
request:
collection: vision.projects.locations.productSets
method: removeProduct
modify_request_hooks:
- googlecloudsdk.command_lib.ml.vision.product_search.utils:FixProductInRemoveProductFromProductSetRequest
arguments:
resource:
help_text: Product set to remove product from.
spec: !REF googlecloudsdk.command_lib.ml.vision.resources:product_set
params:
- api_field: removeProductFromProductSetRequest.product
arg_name: product
required: true
help_text: |-
The id of the product to remove from the product set. The product must be in the same
project and location as the specified product set.

View File

@@ -0,0 +1,25 @@
- release_tracks: [ALPHA, BETA]
help_text:
brief: Update a product set.
description: Update a product set.
examples: |
To change the display name to 'my favorite' of product set 'my-product-set'
in locaiton 'us-east1', run:
$ {command} my-produt-set --location=us-east1 --display-name='my favorite'
request:
collection: vision.projects.locations.productSets
arguments:
resource:
help_text: Product set to update.
spec: !REF googlecloudsdk.command_lib.ml.vision.resources:product_set
params:
- api_field: productSet.displayName
arg_name: display-name
help_text: |-
The user provided name for this product set. It must not be empty and must be at most 4096
characters long.

View File

@@ -0,0 +1,27 @@
# -*- coding: utf-8 -*- #
# Copyright 2019 Google LLC. All Rights Reserved.
#
# 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.
"""Command group for ml vision product-search products."""
from __future__ import absolute_import
from __future__ import division
from __future__ import unicode_literals
from googlecloudsdk.calliope import base
@base.ReleaseTracks(base.ReleaseTrack.BETA,
base.ReleaseTrack.ALPHA)
class Product(base.Group):
"""Uses Google Cloud Vision to manipulate products."""

View File

@@ -0,0 +1,44 @@
- release_tracks: [ALPHA, BETA]
help_text:
brief: create a product.
description: Create a product.
examples: |
To create a product 'my-product' in 'us-east1' with category of 'toys' and display name of
'favorite product', run:
$ {command} my-product --location=us-east1 --category=toys --display-name='favorite product'
request:
collection: vision.projects.locations.products
modify_request_hooks:
- googlecloudsdk.command_lib.ml.vision.product_search.utils:PrepareProductLabelsForProductCreationRequest
arguments:
resource:
help_text: The product to create.
spec: !REF googlecloudsdk.command_lib.ml.vision.resources:product
params:
- api_field: product.displayName
arg_name: display-name
required: true
help_text: |-
The display name of this product. It must not be empty and can be up to 4096 characters
long.
- api_field: product.description
arg_name: description
help_text: |-
An optional description of this product. It can be up to 4096 characters long.
- api_field: product.productCategory
arg_name: category
required: true
choices:
- arg_value: homegoods
enum_value: homegoods
- arg_value: apparel
enum_value: apparel
- arg_value: toys
enum_value: toys
help_text: |-
The category for the product. After being set, it cannot be changed.
additional_arguments_hook: googlecloudsdk.command_lib.ml.vision.product_search.utils:ProductLabelsArgumentsForCreate

View File

@@ -0,0 +1,17 @@
- release_tracks: [ALPHA, BETA]
help_text:
brief: delete a product.
description: delete a product.
examples: |
To delete product 'my-product' in location 'us-east1', run:
$ {command} my-product --location=us-east1
request:
collection: vision.projects.locations.products
arguments:
resource:
help_text: The product to delete.
spec: !REF googlecloudsdk.command_lib.ml.vision.resources:product

View File

@@ -0,0 +1,43 @@
- release_tracks: [ALPHA]
help_text:
brief: Deletes all Products in a ProductSet or all Products that are in no ProductSet.
description: Deletes all Products in a ProductSet or all Products that are in no ProductSet.
examples: |
To delete all products in no product sets in location 'us-east1' and project 'test-project', run:
$ {command} --orphan-products us-east1 --project=test-project
request:
collection: vision.projects.locations.products
method: purge
modify_request_hooks:
- googlecloudsdk.command_lib.ml.vision.product_search.utils:PromptDeleteAll
arguments:
resource:
help_text: The location in which to delete the product set.
spec: !REF googlecloudsdk.command_lib.ml.vision.resources:non_primary_location
is_parent_resource: true
params:
- api_field: purgeProductsRequest.force
arg_name: force
help_text: |
If specified, user will not be prompted and all the products in specified set will
be deleted. If not specified, user will be prompted to continue the delete.
- group:
mutex: true
required: true
params:
- api_field: purgeProductsRequest.productSetPurgeConfig.productSetId
arg_name: product-set
help_text: |
Delete all Products that are in a ProductSet. Even if the Product is in multiple
ProductSets, the Product is still deleted.
- api_field: purgeProductsRequest.deleteOrphanProducts
action: store_true
arg_name: orphan-products
help_text: |
Delete all Products that are in no ProductSet.

View File

@@ -0,0 +1,17 @@
- release_tracks: [ALPHA, BETA]
help_text:
brief: describe a product.
description: describe a product.
examples: |
To describe product 'my-product' in location 'us-east1', run:
$ {command} my-product --location=us-east1
request:
collection: vision.projects.locations.products
arguments:
resource:
help_text: The product to describe.
spec: !REF googlecloudsdk.command_lib.ml.vision.resources:product

View File

@@ -0,0 +1,29 @@
- release_tracks: [ALPHA, BETA]
help_text:
brief: list all products in a location.
description: list all products in a location.
examples: |
To list products in location 'us-east1', run:
$ {command} --location=us-east1
request:
collection: vision.projects.locations.products
response:
id_field: name
arguments:
resource:
help_text: The location to list all products.
spec: !REF googlecloudsdk.command_lib.ml.vision.resources:location
is_positional: false
output:
format: |
table(
name.scope("products"):label=NAME,
name.scope("locations").segment(0):label=LOCATION,
displayName
)

View File

@@ -0,0 +1,40 @@
- release_tracks: [ALPHA, BETA]
help_text:
brief: update a product.
description: update a product.
examples: |
To change the display name to 'new-display--name', and description to 'new-description' of
product 'my-product' in location 'us-east1', run:
$ {command} my-product --location=us-east1 --display-name='new-display-name' --description='new-description'
To add labels 'color=blue' to and remove 'weight=10lbs' from product 'my-product' in location 'us-east1',
run:
$ {command} my-product --location=us-east1 --add-product-labels='color=blue' --remove-product-labels='weight=10lbs'
To clear all labels from product 'my-product' in location 'us-east1', run:
$ {command} my-product --location=us-east1 --clear-product-labels
request:
collection: vision.projects.locations.products
modify_request_hooks:
- googlecloudsdk.command_lib.ml.vision.product_search.utils:UpdateLabelsAndUpdateMaskForProductUpdateRequest
arguments:
resource:
help_text: The product to update.
spec: !REF googlecloudsdk.command_lib.ml.vision.resources:product
params:
- api_field: product.displayName
arg_name: display-name
help_text: |-
The display name of this product. It must not be empty and can be up to 4096 characters
long.
- api_field: product.description
arg_name: description
help_text: |-
An optional description of this product. It can be up to 4096 characters long.
additional_arguments_hook: googlecloudsdk.command_lib.ml.vision.product_search.utils:ProductLabelsArgumentsForUpdate

View File

@@ -0,0 +1,68 @@
- release_tracks: [GA]
help_text:
brief: Suggest a bounding box in an image.
description: |
Returns the coordinates of a bounding box that surrounds the dominant
object or face in an image.
examples: |
To get the coordinates of a bounding box that surrounds the dominant
object or face in an image `gs://my_bucket/input_file`:
$ {command} gs://my_bucket/input_file
request:
_COMMON_: request
static_fields:
requests.features.type: CROP_HINTS
response:
_COMMON_: response
arguments:
params:
- _COMMON_: args.image_field
- api_field: requests.imageContext.cropHintsParams.aspectRatios
arg_name: aspect-ratios
type: googlecloudsdk.command_lib.ml.vision.flags:AspectRatioType
help_text: A list of aspect ratio hints for the suggested bounding box. Aspect
ratios may be specified either as a decimal number (ex. 1.333) or as a ratio
of width to height (ex 4:3).
output:
format: json
- release_tracks: [ALPHA, BETA]
help_text:
brief: Suggest a bounding box in an image.
description: |
Returns the coordinates of a bounding box that surrounds the dominant
object or face in an image.
examples: |
To get the coordinates of a bounding box that surrounds the dominant
object or face in an image `gs://my_bucket/input_file`:
$ {command} gs://my_bucket/input_file
request:
_COMMON_: request
static_fields:
requests.features.type: CROP_HINTS
response:
_COMMON_: response
arguments:
params:
- _COMMON_: args.image_field
- _COMMON_: args.model_field
- api_field: requests.imageContext.cropHintsParams.aspectRatios
arg_name: aspect-ratios
type: googlecloudsdk.command_lib.ml.vision.flags:AspectRatioType
help_text: A list of aspect ratio hints for the suggested bounding box. Aspect
ratios may be specified either as a decimal number (ex. 1.333) or as a ratio
of width to height (ex 4:3).
output:
format: json