Reader small image

You're reading from  Hands-On Python Deep Learning for the Web

Product typeBook
Published inMay 2020
Reading LevelBeginner
PublisherPackt
ISBN-139781789956085
Edition1st Edition
Languages
Right arrow
Authors (2):
Anubhav Singh
Anubhav Singh
author image
Anubhav Singh

Anubhav Singh, a web developer since before Bootstrap was launched, is an explorer of technologies, often pulling off crazy combinations of uncommon tech. An international rank holder in the Cyber Olympiad, he started off by developing his own social network and search engine as his first projects at the age of 15, which stood among the top 500 websites of India during their operational years. He's continuously developing software for the community in domains with roads less walked on. You can often catch him guiding students on how to approach ML or the web, or both together. He's also the founder of The Code Foundation, an AI-focused start-up. Anubhav is a Venkat Panchapakesan Memorial Scholarship awardee and an Intel Software Innovator.
Read more about Anubhav Singh

Sayak Paul
Sayak Paul
author image
Sayak Paul

Sayak Paul is currently with PyImageSearch, where he applies deep learning to solve real-world problems in computer vision and bring solutions to edge devices. He is responsible for providing Q&A support to PyImageSearch readers. His areas of interest include computer vision, generative modeling, and more. Previously at DataCamp, Sayak developed projects and practice pools. Prior to DataCamp, Sayak worked at TCS Research and Innovation (TRDDC) on data privacy. There, he was a part of TCS's critically acclaimed GDPR solution called Crystal Ball. Outside of work, Sayak loves to write technical articles and speak at developer meetups and conferences.
Read more about Sayak Paul

View More author details
Right arrow

A General Production Framework for Deep Learning-Enabled Websites

We have covered decent ground on using industry-grade cloud Deep Learning (DL) APIs in our applications in previous chapters and we have learned about their use through practical examples. In this chapter, we will cover a general outline for developing DL-enabled websites. This will require us to bring together all the things that we have learned so far so that we can put them to use in real-life use cases. In this chapter, we will learn how to structure a DL web application for production by first preparing the dataset. We will then train a DL model in Python and then wrap the DL models in APIs using Flask.

The following is a high-level summary of this chapter:

  • Defining our problem statement
  • Breaking the problem into several components
  • Building a mental model to bind the project components
  • How we should be collecting...

Technical requirements

You can access the code used in this chapter at https://github.com/PacktPublishing/Hands-On-Python-Deep-Learning-for-Web/tree/master/Chapter9.

To run the code used in this chapter, you'll need the following software:

  • Python 3.6+
  • The Python PIL library
  • NumPy
  • Pandas
  • The Natural Language Toolkit (NLTK)
  • Flask 1.1.0+ and compatible versions of the following:
    • FlaskForm
    • wtforms
    • flask_restful
    • flask_jsonpify

All other installations will be described during the course of this chapter.

Defining the problem statement

Any project should start with a well-defined problem statement or the project development is bound to suffer. The problem statement governs all the major steps involved in an overall project development pipeline, starting from project planning to project cost.

In a DL-based web project, for example, the problem statement will direct us to the following:

  • Determine what kind of data we would need.
  • How much complexity there would be in terms of code, planning, and other resources.
  • What kind of user interface we would develop.
  • How much human involvement there would be so that an estimate can be prepared on the project’s manpower and so on.

Hence, a well-defined problem statement is really required in order for us to get started with further project development.

Imagine being a DL engineer at a company that is planning to build a recommendation...

How not to build an AI backend

Considering the vastness that web applications can grow to and the strong dependence of nearly every other platform on a backend that runs as a web-based service, it is important for the backend to be well thought of and properly executed. AI-based applications, even in a PoC stage, are often not blazingly fast in responding or take a lot of time to train on the new samples.

While we will be discussing tips and tricks to make a backend that does not choke under pressure due to bottlenecks, we need to lay down a few pointers that need to be avoided in the best possible way when developing an AI-integrated backend for a website.

Expecting the AI part of the website to be real time

AI is computationally...

A sample end-to-end AI-integrated web application

Now that we have discussed an overview and the pitfalls to avoid when creating an AI-powered website backend, let's move on to creating one—albeit a rather simple one—that demonstrates the general overview of the solution.

We will cover the following steps, as stated previously:

  • The collection of data as per the problem statement
  • Cleaning and preprocessing the data
  • Building the AI model
  • Creating an interface
  • Using the AI model on the interface

While we have previously discussed the pitfalls of collecting the data, we will briefly discuss here the tools and methods that can be employed to complete the task.

Data collection and cleanup

For the purpose of...

Building an interface

To build an interface for the web application, we need to think about how we would want our users to interact with the system. In our case, we are expecting the user to be presented with suggestions based on what they search for in a search bar the moment they submit the search query. This means we need the system to respond in real time and generate suggestions on the fly. To build this system, we will create an API that will respond to the search query.

Creating an API to answer search queries

We will create an API that accepts queries in the form of HTTP requests and replies with suggestions of products based on the search query entered by the user. To do so, follow these steps:

  1. We will begin by importing...

Summary

As a general overview, web applications that hone the power of DL have a few set methods to do so via APIs, in-browser JavaScript, or by silently embedding DL models in the backend of the application. In this chapter, we saw how to use the most common of these methods—an API-based DL web application—while at the same time, we saw a rough overview of how to design similar solutions. We covered the thought process that goes into the identification of the problem statement and a subsequent solution, along with the pitfalls and pain points to avoid during the design of a web application that integrates DL models.

In the next chapter, we will cover an end to end project that integrates DL on web applications for security purposes. We will see how DL can help us recognize suspicious activity and block spam users.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Hands-On Python Deep Learning for the Web
Published in: May 2020Publisher: PacktISBN-13: 9781789956085
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Authors (2)

author image
Anubhav Singh

Anubhav Singh, a web developer since before Bootstrap was launched, is an explorer of technologies, often pulling off crazy combinations of uncommon tech. An international rank holder in the Cyber Olympiad, he started off by developing his own social network and search engine as his first projects at the age of 15, which stood among the top 500 websites of India during their operational years. He's continuously developing software for the community in domains with roads less walked on. You can often catch him guiding students on how to approach ML or the web, or both together. He's also the founder of The Code Foundation, an AI-focused start-up. Anubhav is a Venkat Panchapakesan Memorial Scholarship awardee and an Intel Software Innovator.
Read more about Anubhav Singh

author image
Sayak Paul

Sayak Paul is currently with PyImageSearch, where he applies deep learning to solve real-world problems in computer vision and bring solutions to edge devices. He is responsible for providing Q&A support to PyImageSearch readers. His areas of interest include computer vision, generative modeling, and more. Previously at DataCamp, Sayak developed projects and practice pools. Prior to DataCamp, Sayak worked at TCS Research and Innovation (TRDDC) on data privacy. There, he was a part of TCS's critically acclaimed GDPR solution called Crystal Ball. Outside of work, Sayak loves to write technical articles and speak at developer meetups and conferences.
Read more about Sayak Paul