Full Stack Machine learning on AWS: Translating Text with AWS Amplify and Amazon Translate

nader dabit
Instructornader dabit
Share this video with your friends

Social Share Links

Send Tweet
Published 5 years ago
Updated 4 years ago

In this video, we'll create a new React app, initialize a new AWS Amplify project, and add text translation using Amazon Translate.

Instructor: [0:01] We'll start by creating a new React app by using create react app.

[0:12] Now, we'll change into the directory and initialize new amplify project by running amplify init. Here, we'll give the project a name, the environment a name, choose our default text editor, and then accept the defaults for the rest of the options.

[0:33] When prompted for the AWS profile, choose the AWS profile that you'd like to use.

[0:42] Next, we'll add authentication by running amplify add auth and accept all of the defaults.

[0:51] Now that authentication has been enabled, we can enable predictions by running amplify app predictions. Here, we'll choose convert as the category and translate text into a different language as the type of conversion.

[1:07] Next, we'll provide a name for the resource, and a target language and a source language. The target and source languages can be provided dynamically as well, but we're setting the base languages here.

[1:22] We'll allow both authenticated and guest users so that unauthenticated users can use our application.

[1:28] To deploy everything, we can now run amplify push.

[1:36] Now that the services have been deployed, we can now open index.js to configure our React application to work with amplify.

[1:44] Here, we'll employ amplify from AWS-amplify, the configuration from AWS-exports file and the Amazon AI predictions provider from AWS-amplify/predictions.

[2:07] Next, we'll configure both amplify as well adding the new amplify Amazon AI predictions provider.

[2:34] Next, we'll open app.js and import useState from React so that we can control the component's state. The Amplify API that we'll use is called Predictions, so we'll go ahead and import Predictions from AWS-amplify at the top of the file.

[2:51] To hold and update the response from the Predictions API, we'll create a variable called response and a function called setResponse. To hold and update the user's text input, we'll create a variable text and a function called updateText.

[3:23] Now, we'll create a function called translate that will call the Predictions API. In this function, we'll call it Predictions.convert, setting translateText as the Prediction's type. We'll then pass in the text as a source and set the response in a variable called data. We can then call set response using the translated text by calling setResponse and passing in data.text.

[4:04] In the UI, we'll create an input with an onChange handler that we'll call updateText passing in the event target value. We'll also set the value of the input to the dynamic text value. To call the translate function, we'll add the new button with an onClick handler set to translate. We can then view the response by setting it within a paragraph tag.

[4:46] Back at the command log, we'll now install AWS-amplify using either NPM or Yarn. We can now test everything out by running npm start.

egghead
egghead
~ 2 hours ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today