Let's create scripts.js as shown in the following. The JavaScript function is interacting with the endpoints and stitching together the overall user experience of the Pictorial Translator. Let's have a look at the following code:

  1. First, define serverUrl as the address of chalice local.
  2. We will also define a new HttpError to handle the exceptions that might occur during the HTTP requests.
  3. Add this JavaScript class at the end of the scripts.js file:
"use strict";const serverUrl = "";...class HttpError extends Error { constructor(response) {        super(`${response.status} for ${response.url}`); = "HttpError";        this.response = response;    }}
  1. Next, we will define four functions in scripts.js:
  • uploadImage() ...

Get Hands-On Artificial Intelligence on Amazon Web Services now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.