GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — added model in the sample by puneith · Pull Request #650 · GoogleCloudPlatform/python-docs-samples

added model in the sample #650

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
theacodes merged 8 commits into master from translate_model
Nov 15, 2016

Uh oh!

There was an error while loading. Please reload this page.

Merged

added model in the sample #650

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
8 commits
Select commit Hold shift + click to select a range
8f90e39
added model in the sample
puneithk Nov 13, 2016
0ec80c9
break at opening paren
puneithk Nov 14, 2016
e582020
added fix for the client as per new lib
puneithk Nov 14, 2016
0e77c55
added BASE as constant
puneithk Nov 14, 2016
4c528b2
Update quickstart.py
puneith Nov 15, 2016
7e06066
Update quickstart.py
puneith Nov 15, 2016
e529c82
changes to constructor translate client
puneithk Nov 15, 2016
cc71500
Merge branch 'translate_model' of github.com:GoogleCloudPlatform/pyth…
puneithk Nov 15, 2016
File filter
Filter by extension


Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

10 changes: 8 additions & 2 deletions 10 translate/cloud-client/quickstart.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,21 @@ def run_quickstart():
api_key = 'YOUR_API_KEY'

# Instantiates a client
translate_client = translate.Client(api_key)
translate_client = translate.Client(api_key=api_key)

# The text to translate
text = u'Hello, world!'
# The target language
target = 'ru'

# MT model type `base` or `nmt`
model = translate.BASE

# Translates some text into Russian
translation = translate_client.translate(text, target_language=target)
translation = translate_client.translate(
text,
target_language=target,
model=model)

print(u'Text: {}'.format(text))
print(u'Translation: {}'.format(translation['translatedText']))
Expand Down
2 changes: 1 addition & 1 deletion 2 translate/cloud-client/requirements.txt
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
@@ -1 +1 @@
google-cloud-translate==0.20.0
google-cloud-translate==0.21.0
18 changes: 11 additions & 7 deletions 18 translate/cloud-client/snippets.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

def detect_language(api_key, text):
"""Detects the text's language."""
translate_client = translate.Client(api_key)
translate_client = translate.Client(api_key=api_key)

# Text can also be a sequence of strings, in which case this method
# will return a sequence of results for each text.
Expand All @@ -41,7 +41,7 @@ def detect_language(api_key, text):

def list_languages(api_key):
"""Lists all available languages."""
translate_client = translate.Client(api_key)
translate_client = translate.Client(api_key=api_key)

results = translate_client.get_languages()

Expand All @@ -55,25 +55,28 @@ def list_languages_with_target(api_key, target):
Target must be an ISO 639-1 language code.
See https://g.co/cloud/translate/v2/translate-reference#supported_languages
"""
translate_client = translate.Client(api_key)
translate_client = translate.Client(api_key=api_key)

results = translate_client.get_languages(target_language=target)

for language in results:
print(u'{name} ({language})'.format(**language))


def translate_text(api_key, target, text):
def translate_text(api_key, target, text, model=translate.BASE):
"""Translates text into the target language.

Target must be an ISO 639-1 language code.
See https://g.co/cloud/translate/v2/translate-reference#supported_languages
"""
translate_client = translate.Client(api_key)
translate_client = translate.Client(api_key=api_key)

# Text can also be a sequence of strings, in which case this method
# will return a sequence of results for each text.
result = translate_client.translate(text, target_language=target)
result = translate_client.translate(
text,
target_language=target,
model=model)

print(u'Text: {}'.format(result['input']))
print(u'Translation: {}'.format(result['translatedText']))
Expand Down Expand Up @@ -103,6 +106,7 @@ def translate_text(api_key, target, text):
'translate-text', help=translate_text.__doc__)
translate_text_parser.add_argument('target')
translate_text_parser.add_argument('text')
translate_text_parser.add_argument('model')

args = parser.parse_args()

Expand All @@ -113,4 +117,4 @@ def translate_text(api_key, target, text):
elif args.command == 'list-languages-with-target':
list_languages_with_target(args.api_key, args.target)
elif args.command == 'translate-text':
translate_text(args.api_key, args.target, args.text)
translate_text(args.api_key, args.target, args.text, args.model)
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.