Skip to content
This repository was archived by the owner on Feb 23, 2024. It is now read-only.

Commit

Permalink
feat: Added shadow removal and rotation correction options to Documen…
Browse files Browse the repository at this point in the history
…t Translation and Batch Document Translation API (#511)

* feat: Added shadow removal and rotation correction options to Document Translation and Batch Document Translation API

PiperOrigin-RevId: 554540042

Source-Link: googleapis/googleapis@a3aded7

Source-Link: https://github.com/googleapis/googleapis-gen/commit/07b1ee544ff188f96e8e08b39186cd1e104e1984
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiMDdiMWVlNTQ0ZmYxODhmOTZlOGUwOGIzOTE4NmNkMWUxMDRlMTk4NCJ9

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

* feat: Added shadow removal and rotation correction options to Document Translation and Batch Document Translation API

PiperOrigin-RevId: 554540978

Source-Link: googleapis/googleapis@8cf2ae1

Source-Link: https://github.com/googleapis/googleapis-gen/commit/5a136ebbed847eb9e72deb672d0481ff04ab0398
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiNWExMzZlYmJlZDg0N2ViOWU3MmRlYjY3MmQwNDgxZmYwNGFiMDM5OCJ9

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

---------

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
  • Loading branch information
gcf-owl-bot[bot] and gcf-owl-bot[bot] authored Aug 8, 2023
1 parent 440c434 commit 285059a
Show file tree
Hide file tree
Showing 10 changed files with 133 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ async def sample_translate_text():
``projects/{project-number-or-id}/locations/global/models/general/nmt``.
If not provided, the default Google model (NMT) will be
used.
used
This corresponds to the ``model`` field
on the ``request`` instance; if ``request`` is provided, this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ def sample_translate_text():
``projects/{project-number-or-id}/locations/global/models/general/nmt``.
If not provided, the default Google model (NMT) will be
used.
used
This corresponds to the ``model`` field
on the ``request`` instance; if ``request`` is provided, this
Expand Down
47 changes: 36 additions & 11 deletions google/cloud/translate_v3/types/translation_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@


class TranslateTextGlossaryConfig(proto.Message):
r"""Configures which glossary should be used for a specific
target language, and defines options for applying that glossary.
r"""Configures which glossary is used for a specific target
language and defines options for applying that glossary.
Attributes:
glossary (str):
Expand Down Expand Up @@ -152,8 +152,7 @@ class TranslateTextRequest(proto.Message):
``global``. For example,
``projects/{project-number-or-id}/locations/global/models/general/nmt``.
If not provided, the default Google model (NMT) will be
used.
If not provided, the default Google model (NMT) will be used
glossary_config (google.cloud.translate_v3.types.TranslateTextGlossaryConfig):
Optional. Glossary to be applied. The glossary must be
within the same region (have the same location-id) as the
Expand Down Expand Up @@ -904,14 +903,19 @@ class TranslateDocumentRequest(proto.Message):
should follow rules in
https://cloud.google.com/translate/attribution#attribution_and_logos
is_translate_native_pdf_only (bool):
Optional. If true, the page limit of online
native pdf translation is 300 and only native
pdf pages will be translated.
Optional. is_translate_native_pdf_only field for external
customers. If true, the page limit of online native pdf
translation is 300 and only native pdf pages will be
translated.
enable_shadow_removal_native_pdf (bool):
Optional. If true, use the text removal to remove the shadow
text on background image for native pdf translation. Shadow
removal feature can only be enabled when
is_translate_native_pdf_only is false
Optional. If true, use the text removal server to remove the
shadow text on background image for native pdf translation.
Shadow removal feature can only be enabled when
is_translate_native_pdf_only: false && pdf_native_only:
false
enable_rotation_correction (bool):
Optional. If true, enable auto rotation
correction in DVS.
"""

parent: str = proto.Field(
Expand Down Expand Up @@ -962,6 +966,10 @@ class TranslateDocumentRequest(proto.Message):
proto.BOOL,
number=12,
)
enable_rotation_correction: bool = proto.Field(
proto.BOOL,
number=13,
)


class DocumentTranslation(proto.Message):
Expand Down Expand Up @@ -1807,6 +1815,15 @@ class BatchTranslateDocumentRequest(proto.Message):
``Machine Translated by Google``. Customized attribution
should follow rules in
https://cloud.google.com/translate/attribution#attribution_and_logos
enable_shadow_removal_native_pdf (bool):
Optional. If true, use the text removal server to remove the
shadow text on background image for native pdf translation.
Shadow removal feature can only be enabled when
is_translate_native_pdf_only: false && pdf_native_only:
false
enable_rotation_correction (bool):
Optional. If true, enable auto rotation
correction in DVS.
"""

parent: str = proto.Field(
Expand Down Expand Up @@ -1851,6 +1868,14 @@ class BatchTranslateDocumentRequest(proto.Message):
proto.STRING,
number=10,
)
enable_shadow_removal_native_pdf: bool = proto.Field(
proto.BOOL,
number=11,
)
enable_rotation_correction: bool = proto.Field(
proto.BOOL,
number=12,
)


class BatchDocumentInputConfig(proto.Message):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -824,12 +824,12 @@ async def batch_translate_document(
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
metadata: Sequence[Tuple[str, str]] = (),
) -> operation_async.AsyncOperation:
r"""Translates a large volume of documents in
asynchronous batch mode. This function provides
real-time output as the inputs are being processed. If
caller cancels a request, the partial results (for an
input file, it's all or nothing) may still be available
on the specified output location.
r"""Translates a large volume of document in asynchronous
batch mode. This function provides real-time output as
the inputs are being processed. If caller cancels a
request, the partial results (for an input file, it's
all or nothing) may still be available on the specified
output location.
This call returns immediately and you can use
google.longrunning.Operation.name to poll the status of
the call.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1045,12 +1045,12 @@ def batch_translate_document(
timeout: Union[float, object] = gapic_v1.method.DEFAULT,
metadata: Sequence[Tuple[str, str]] = (),
) -> operation.Operation:
r"""Translates a large volume of documents in
asynchronous batch mode. This function provides
real-time output as the inputs are being processed. If
caller cancels a request, the partial results (for an
input file, it's all or nothing) may still be available
on the specified output location.
r"""Translates a large volume of document in asynchronous
batch mode. This function provides real-time output as
the inputs are being processed. If caller cancels a
request, the partial results (for an input file, it's
all or nothing) may still be available on the specified
output location.
This call returns immediately and you can use
google.longrunning.Operation.name to poll the status of
the call.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,12 +407,12 @@ def batch_translate_document(
]:
r"""Return a callable for the batch translate document method over gRPC.
Translates a large volume of documents in
asynchronous batch mode. This function provides
real-time output as the inputs are being processed. If
caller cancels a request, the partial results (for an
input file, it's all or nothing) may still be available
on the specified output location.
Translates a large volume of document in asynchronous
batch mode. This function provides real-time output as
the inputs are being processed. If caller cancels a
request, the partial results (for an input file, it's
all or nothing) may still be available on the specified
output location.
This call returns immediately and you can use
google.longrunning.Operation.name to poll the status of
the call.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -414,12 +414,12 @@ def batch_translate_document(
]:
r"""Return a callable for the batch translate document method over gRPC.
Translates a large volume of documents in
asynchronous batch mode. This function provides
real-time output as the inputs are being processed. If
caller cancels a request, the partial results (for an
input file, it's all or nothing) may still be available
on the specified output location.
Translates a large volume of document in asynchronous
batch mode. This function provides real-time output as
the inputs are being processed. If caller cancels a
request, the partial results (for an input file, it's
all or nothing) may still be available on the specified
output location.
This call returns immediately and you can use
google.longrunning.Operation.name to poll the status of
the call.
Expand Down
72 changes: 67 additions & 5 deletions google/cloud/translate_v3beta1/types/translation_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ class OutputConfig(proto.Message):
Since index.csv will be keeping updated during the process,
please make sure there is no custom retention policy applied
on the output bucket that may avoid file updating.
(https://cloud.google.com/storage/docs/bucket-lock?hl=en#retention-policy)
(https://cloud.google.com/storage/docs/bucket-lock#retention-policy)
The format of translations_file (for target language code
'trg') is:
Expand Down Expand Up @@ -887,6 +887,26 @@ class TranslateDocumentRequest(proto.Message):
See
https://cloud.google.com/translate/docs/advanced/labels
for more information.
customized_attribution (str):
Optional. This flag is to support user customized
attribution. If not provided, the default is
``Machine Translated by Google``. Customized attribution
should follow rules in
https://cloud.google.com/translate/attribution#attribution_and_logos
is_translate_native_pdf_only (bool):
Optional. is_translate_native_pdf_only field for external
customers. If true, the page limit of online native pdf
translation is 300 and only native pdf pages will be
translated.
enable_shadow_removal_native_pdf (bool):
Optional. If true, use the text removal server to remove the
shadow text on background image for native pdf translation.
Shadow removal feature can only be enabled when
is_translate_native_pdf_only: false && pdf_native_only:
false
enable_rotation_correction (bool):
Optional. If true, enable auto rotation
correction in DVS.
"""

parent: str = proto.Field(
Expand Down Expand Up @@ -925,6 +945,22 @@ class TranslateDocumentRequest(proto.Message):
proto.STRING,
number=8,
)
customized_attribution: str = proto.Field(
proto.STRING,
number=10,
)
is_translate_native_pdf_only: bool = proto.Field(
proto.BOOL,
number=11,
)
enable_shadow_removal_native_pdf: bool = proto.Field(
proto.BOOL,
number=12,
)
enable_rotation_correction: bool = proto.Field(
proto.BOOL,
number=13,
)


class DocumentTranslation(proto.Message):
Expand Down Expand Up @@ -1266,10 +1302,9 @@ class GlossaryInputConfig(proto.Message):
For equivalent term sets glossaries:
- CSV (``.csv``): Multi-column CSV file defining equivalent
glossary terms in multiple languages. The format is
defined for Google Translation Toolkit and documented in
`Use a
glossary <https://support.google.com/translatortoolkit/answer/6306379?hl=en>`__.
glossary terms in multiple languages. See documentation
for more information -
`glossaries <https://cloud.google.com/translate/docs/advanced/glossary>`__.
This field is a member of `oneof`_ ``source``.
"""
Expand Down Expand Up @@ -1760,6 +1795,21 @@ class BatchTranslateDocumentRequest(proto.Message):
If nothing specified, output files will be in the same
format as the original file.
customized_attribution (str):
Optional. This flag is to support user customized
attribution. If not provided, the default is
``Machine Translated by Google``. Customized attribution
should follow rules in
https://cloud.google.com/translate/attribution#attribution_and_logos
enable_shadow_removal_native_pdf (bool):
Optional. If true, use the text removal server to remove the
shadow text on background image for native pdf translation.
Shadow removal feature can only be enabled when
is_translate_native_pdf_only: false && pdf_native_only:
false
enable_rotation_correction (bool):
Optional. If true, enable auto rotation
correction in DVS.
"""

parent: str = proto.Field(
Expand Down Expand Up @@ -1800,6 +1850,18 @@ class BatchTranslateDocumentRequest(proto.Message):
proto.STRING,
number=8,
)
customized_attribution: str = proto.Field(
proto.STRING,
number=10,
)
enable_shadow_removal_native_pdf: bool = proto.Field(
proto.BOOL,
number=11,
)
enable_rotation_correction: bool = proto.Field(
proto.BOOL,
number=12,
)


class BatchDocumentInputConfig(proto.Message):
Expand Down
4 changes: 2 additions & 2 deletions scripts/fixup_translate_v3_keywords.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ def partition(
class translateCallTransformer(cst.CSTTransformer):
CTRL_PARAMS: Tuple[str] = ('retry', 'timeout', 'metadata')
METHOD_TO_PARAMS: Dict[str, Tuple[str]] = {
'batch_translate_document': ('parent', 'source_language_code', 'target_language_codes', 'input_configs', 'output_config', 'models', 'glossaries', 'format_conversions', 'customized_attribution', ),
'batch_translate_document': ('parent', 'source_language_code', 'target_language_codes', 'input_configs', 'output_config', 'models', 'glossaries', 'format_conversions', 'customized_attribution', 'enable_shadow_removal_native_pdf', 'enable_rotation_correction', ),
'batch_translate_text': ('parent', 'source_language_code', 'target_language_codes', 'input_configs', 'output_config', 'models', 'glossaries', 'labels', ),
'create_glossary': ('parent', 'glossary', ),
'delete_glossary': ('name', ),
'detect_language': ('parent', 'model', 'content', 'mime_type', 'labels', ),
'get_glossary': ('name', ),
'get_supported_languages': ('parent', 'display_language_code', 'model', ),
'list_glossaries': ('parent', 'page_size', 'page_token', 'filter', ),
'translate_document': ('parent', 'target_language_code', 'document_input_config', 'source_language_code', 'document_output_config', 'model', 'glossary_config', 'labels', 'customized_attribution', 'is_translate_native_pdf_only', 'enable_shadow_removal_native_pdf', ),
'translate_document': ('parent', 'target_language_code', 'document_input_config', 'source_language_code', 'document_output_config', 'model', 'glossary_config', 'labels', 'customized_attribution', 'is_translate_native_pdf_only', 'enable_shadow_removal_native_pdf', 'enable_rotation_correction', ),
'translate_text': ('contents', 'target_language_code', 'parent', 'mime_type', 'source_language_code', 'model', 'glossary_config', 'labels', ),
}

Expand Down
4 changes: 2 additions & 2 deletions scripts/fixup_translate_v3beta1_keywords.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ def partition(
class translateCallTransformer(cst.CSTTransformer):
CTRL_PARAMS: Tuple[str] = ('retry', 'timeout', 'metadata')
METHOD_TO_PARAMS: Dict[str, Tuple[str]] = {
'batch_translate_document': ('parent', 'source_language_code', 'target_language_codes', 'input_configs', 'output_config', 'models', 'glossaries', 'format_conversions', ),
'batch_translate_document': ('parent', 'source_language_code', 'target_language_codes', 'input_configs', 'output_config', 'models', 'glossaries', 'format_conversions', 'customized_attribution', 'enable_shadow_removal_native_pdf', 'enable_rotation_correction', ),
'batch_translate_text': ('parent', 'source_language_code', 'target_language_codes', 'input_configs', 'output_config', 'models', 'glossaries', 'labels', ),
'create_glossary': ('parent', 'glossary', ),
'delete_glossary': ('name', ),
'detect_language': ('parent', 'model', 'content', 'mime_type', 'labels', ),
'get_glossary': ('name', ),
'get_supported_languages': ('parent', 'display_language_code', 'model', ),
'list_glossaries': ('parent', 'page_size', 'page_token', 'filter', ),
'translate_document': ('parent', 'target_language_code', 'document_input_config', 'source_language_code', 'document_output_config', 'model', 'glossary_config', 'labels', ),
'translate_document': ('parent', 'target_language_code', 'document_input_config', 'source_language_code', 'document_output_config', 'model', 'glossary_config', 'labels', 'customized_attribution', 'is_translate_native_pdf_only', 'enable_shadow_removal_native_pdf', 'enable_rotation_correction', ),
'translate_text': ('contents', 'target_language_code', 'parent', 'mime_type', 'source_language_code', 'model', 'glossary_config', 'labels', ),
}

Expand Down

0 comments on commit 285059a

Please sign in to comment.