But of course you could use Heroku, AWS etc but that’s another topic for another day, I’ll just focus on GCP for now.
A brief background on the projectIt is machine learning model for spam SMS message classification by training on existing collection of SMS massages labelled with ‘spam’ or ‘ham’.
The Spam detector features scikit-learn’s Multinomial Naive Bayes classifier based on Naive Bayes algorithm for multinomially distributed data:Naive Bayes methods are a set of supervised learning algorithms based on applying Bayes’ theorem with the “naive” assumption of conditional independence between every pair of features given the value of the class variable.
Naive Bayes learners and classifiers can be extremely fast compared to more sophisticated methods.
The decoupling of the class conditional feature distributions means that each distribution can be independently estimated as a one dimensional distribution.
This in turn helps to alleviate problems stemming from the curse of dimensionality.
Flask LogoMeanwhile, Flask serves as the web framework, to receive the user input’s through the frontend (HTTP Request) and realize its prediction capabilities.
Born in 2010, Flask is a small framework by most standards, small enough to be called a “microframework”.
Flask promotes readability and easy understanding of its source code.
Flask is a lightweight Web framework written in Python and it has since become one of most widely used Python web frameworks for start-ups, and a perfect tool for quick and simple solutions in most businesses.
Flask aims at keeping the core of the framework small but highly extensible thus writing application or extensions very easily and flexible, while empowering developer to choose their own configuration for their applicationDeploying on Google Cloud PlatformWe will use Google App Engine on a standard environment.
It allows us to “build highly scalable applications on a fully managed serverless platform”.
There are a few requisites or assumptions that I’ll make before proceeding:I assumed that you have installed Flask and the libraries involved in a virtual environment (if not, it will be shown later).
You have a Google Account with access to the Google Cloud Platform Console and has created a new project on it.
Make sure billing is enabled for your project.
A billing account needs to be linked to your project in order for the application to be deployed to App Engine3.
Installed Google Cloud SDK, follows its instruction for installation.
You have successfully tested your application locally.
Project Folder StructureRoughly speaking, your main folder would have this structure and do note “nlp” is my virtual environment and we will be creating the app.
py and requirements.
yamlThe sample app.
yaml specifies the runtime the application should run in, for this project, it would run on Python 3.
For Python 2.
7, can refer to the code below:Python 2.
txtIf you have not install the necessary libraries into the virtual environment, you can use the code below.
The environment should be activated first and access it using the terminal, command prompt etc to install the new dependencies based on the requirements.
pip install -t lib -r requirements.
txt-t lib: This flag copies the libraries into a lib folder, which uploads to App Engine during deployment.
txt: pip to install everything from requirements.
DeploymentBefore we start, it would be the best (optional) to update the Cloud SDK installed:gcloud components updateThen, at the root folder, we will deploy it using your cmd/terminal with the code below:gcloud app deploy –project [ID of Project]Or you could just do it without the ID of the project as well!Choose the most suitable region and just wait for a few minutes, depending on your project, it will present you with a link that could be accessed by anyone to view/use your web application!Or just use the code below:gcloud app browse –project=#the link usually is "projectid".
comConclusionVoilà!.GCP made the process of deploying a web application quicker and with ease.
I hope that I could try out other options in the near future or other projects.
Feel free to reach out to me if there’s problem or questions!.My site could be found here: spamdetector.
com/georgeblu1/Spam-Detector-Web-AppDevelop a NLP Model in Python & Deploy It with Flask, Step by Step: https://towardsdatascience.
com/develop-a-nlp-model-in-python-deploy-it-with-flask-step-by-step-744f3bdd7776Flask Framework CookbookFlask Web DevelopmentPython Machine Learning.. More details