scripts.js

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 = "http://127.0.0.1:8000";...class HttpError extends Error { constructor(response) {        super(`${response.status} for ${response.url}`);        this.name = "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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.