Hysen Labs
Model or dataset
shivasj/Integrating-a-Machine-Learning-Model-into-a-Web-app avatar
shivasj

Integrating-a-Machine-Learning-Model-into-a-Web-app

Integrating a Machine Learning Model into a Web app

100 stars54 forksJavaScriptLicense varies
01
DEEP OPEN-SOURCE ANALYSIS

Exposing a trained model through a web app

A walkthrough that wraps a serialized machine learning model in a Python class, serves it with Flask, and wires the endpoints into an AngularJS app.

02
DEEP OPEN-SOURCE ANALYSIS

Wrapping the model

The first step in the tutorial is to encapsulate all the model logic into a Python class. In the example there is already a pre trained model, serialized into a pickle object, and the class loads that persisted model in its init method. From there the object can be used for prediction by the web application. The class defines two methods, classify and train, which set up the interface the rest of the stack will call.

03
DEEP OPEN-SOURCE ANALYSIS

The Flask layer

The second step is exposing those methods as REST APIs with Flask. The two endpoints, classify review and train review, both map to the MovieClassifier class and the appropriate method within it, and both return JSON objects with the results from the machine learning model. Once the app runs, the endpoints are available at local addresses for classify and train, with an id parameter identifying the content in the database. The results, including the sentiment and its probability, are computed by the Flask API and handed back to the frontend.

04
DEEP OPEN-SOURCE ANALYSIS

Feeding the frontend

The AngularJS web application consumes the two functions, text summarization and sentiment analysis. In the sentiment flow, every new review is stored in the backend database and then classified with the pre trained model. The README walks through the screen that lists the reviews already tested, and shows the sentiment and probability values returned by the Flask API displayed on the page. Newly entered reviews appear in the list after being saved, which closes the loop between the database, the model, and the UI.

06
DEEP OPEN-SOURCE ANALYSIS

Official sources

07
Community notes

Community notes