This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
input_configs = [{"gcs_source": gcs_source, "mime_type": "text/plain"}] | |
output_config = {"gcs_destination": {"output_uri_prefix": output_uri}} | |
operation = client.batch_translate_text( | |
parent=parent, | |
source_language_code="en", | |
target_language_codes="es", | |
input_configs=input_configs, | |
output_config=output_config) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
MODEL_PATH = 'projects/project_num/locations/us-central1/models/your_model_id' | |
response = client.translate_text( | |
["Let's try the Translation API on Google Cloud Platform."], | |
target_language_code="en", | |
source_language_code="ja", | |
parent=parent, | |
model=MODEL_PATH, | |
mime_type='text/plain' # mime types: text/plain, text/html | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from google.cloud import translate_v3 as translate | |
client = translate.TranslationServiceClient() | |
PROJECT_ID = "your_project_id" | |
LOCATION = "us-central1" | |
GLOSSARY_ID = "my_first_glossary" | |
client = translate.TranslationServiceClient() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from google.cloud import translate_v3 as translate | |
client = translate.TranslationServiceClient() | |
PROJECT_ID = "misc-230215" | |
# Set location so that all operations happen in a single zone. | |
# For now, this must be us-central1 | |
LOCATION = "us-central1" | |
# This URI should take the form gs://bucket_name/file_name |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from google.cloud import translate_v3 | |
client = translate.TranslationServiceClient() | |
PROJECT_ID = "your_project_id_here" | |
LOCATION = "us-central1" | |
response = client.translate_text( | |
parent=client.location_path(PROJECT_ID, LOCATION), | |
contents=["Let's try the Translation API on Google Cloud Platform."], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import microphone_stream | |
import dialogflow_v2 as dialogflow | |
import pyaudio | |
import re | |
PROJECT_ID = "talking-machines" | |
# Audio recording parameters | |
STREAMING_LIMIT = 10000 | |
SAMPLE_RATE = 44100 | |
CHUNK_SIZE = int(SAMPLE_RATE / 10) # 100ms | |
OUTPUT_BUFFER = 1000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { TranslationServiceClient } = require("@google-cloud/translate").v3beta1; | |
const projectId = "your_project_id"; | |
const location = "us-central1"; | |
async function translateText(srcText, targetLang, srcLang) { | |
// Translates text srcText to language targetLang. | |
// srcLang is optional and will be auto-detected if left empty. | |
// Instantiates a client |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function translateText(srcText, targetLang, srcLang) { | |
// Translates text srcText to language targetLang. | |
// srcLang is optional and will be auto-detected if left empty. | |
// Instantiates a client | |
const translationClient = new TranslationServiceClient(); | |
// Constructs a request | |
const request = { | |
parent: translationClient.locationPath(projectId, location), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const {TranslationServiceClient} = require('@google-cloud/translate').v3beta1; | |
const projectId = "your-project-id-230215"; | |
const location = "us-central1"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def getPrediction(in_sentences): | |
labels = ["Negative", "Positive"] | |
input_examples = [run_classifier.InputExample(guid="", text_a = x, text_b = None, label = 0) for x in in_sentences] # here, "" is just a dummy label | |
input_features = run_classifier.convert_examples_to_features(input_examples, label_list, MAX_SEQ_LENGTH, tokenizer) | |
predict_input_fn = run_classifier.input_fn_builder(features=input_features, seq_length=MAX_SEQ_LENGTH, is_training=False, drop_remainder=False) | |
predictions = estimator.predict(predict_input_fn) | |
return [(sentence, prediction['probabilities'], labels[prediction['labels']]) for sentence, prediction in zip(in_sentences, predictions)] | |
pred_sentences = [ | |
"That movie was absolutely awful", |