MCPcopy Create free account
hub / github.com/GoogleCloudPlatform/nodejs-docs-samples / main

Function main

automl/translate_predict.js:17–63  ·  view source on GitHub ↗
(
  projectId = 'YOUR_PROJECT_ID',
  location = 'us-central1',
  modelId = 'YOUR_MODEL_ID',
  filePath = 'path_to_local_file.txt'
)

Source from the content-addressed store, hash-verified

15'use strict';
16
17function main(
18 projectId = 'YOUR_PROJECT_ID',
19 location = 'us-central1',
20 modelId = 'YOUR_MODEL_ID',
21 filePath = 'path_to_local_file.txt'
22) {
23 // [START automl_translate_predict]
24 /**
25 * TODO(developer): Uncomment these variables before running the sample.
26 */
27 // const projectId = 'YOUR_PROJECT_ID';
28 // const location = 'us-central1';
29 // const modelId = 'YOUR_MODEL_ID';
30 // const filePath = 'path_to_local_file.txt';
31
32 // Imports the Google Cloud AutoML library
33 const {PredictionServiceClient} = require('@google-cloud/automl').v1;
34 const fs = require('fs');
35
36 // Instantiates a client
37 const client = new PredictionServiceClient();
38
39 // Read the file content for translation.
40 const content = fs.readFileSync(filePath, 'utf8');
41
42 async function predict() {
43 // Construct request
44 const request = {
45 name: client.modelPath(projectId, location, modelId),
46 payload: {
47 textSnippet: {
48 content: content,
49 },
50 },
51 };
52
53 const [response] = await client.predict(request);
54
55 console.log(
56 'Translated content: ',
57 response.payload[0].translation.translatedContent.content
58 );
59 }
60
61 predict();
62 // [END automl_translate_predict]
63}
64
65process.on('unhandledRejection', err => {
66 console.error(err.message);

Callers 1

Calls 1

predictFunction · 0.70

Tested by

no test coverage detected