End to End Deployment of Breast Cancer Prediction Through Machine Learning using Flask Part-2

VAIBHAV HARIRAMANI
7 min readFeb 22, 2021

--

This is second part in two-part series. you should read the first part first.

As mentioned in the previous post, in this post we learn how to deploy End to End deploying your machine learning model through flask.it’s quite easy — which is exactly what we will learn in detail in this post.

In previous post, we prepared a machine learning model using Xgboost classiefier with low bias and variance And then dumped into pickle file.

pickle.dump(xgb_classifier_pt, open('breast_cancer_detector.pickle', 'wb'))

Now its time for the flask for the model to deploy.

Now we have to switch towards text editor for the deployment and creating flask application. you can choose any IDE i prefer sublime OR VS Code .

Flask is a micro web framework written in Python. It is classified as a microframework because it does not require particular tools or libraries. It has no database abstraction layer, form validation, or any other components where pre-existing third-party libraries provide common functions.The main aim of using flask is to create static webpage using html,css in it.

Create a new flask file name it as app.py and write below code in it

The code here depicts the loading of dumped model ‘breast_cancer_detector.pickle’ and then we are accessing the index.html file for the home page which will take various parameter as input from patient’s database we will discuss this further.

then we have the predict function which will be implemented when we will enter the 30 constraints parameters as an input in the box and then array of size 30 goes to the data frame for the prediction and return prediction on the basis of those parameter which will give output that is tumor Malignant(1) or Benign(0) according to those input by user and in same webpage .

Then we will create html file as ‘index.html’ and write below code in it.

The code tells about the title of the webpage with background of image world.jpg and then in heading 3 lines as in the center of the webpage with various different size .

Then , we make a placeholder Form which will help us to store the input value and display placeholder name on webpage. Then,we will make the “Click here to predict ”button for the prediction.

PREDICTION will be 0 or 1 according to the data entered

and then header for the name. the code next to it depicts about the displaying the icons of the social media handles with the font size and the specific color. Each specific icon is hyperlinked to my social media handle and then end of the body and html code.

Now our model is ready to run command first change directory to the folder where we have the flask file then run python app.py

Then ,it will be return localhost url http://127.0.0.1:8500/ and it will be going to predict after the http://127.0.0.1:8500/predict .

Now its time to deploy our flask App globally.

How to Deploy to Heroku

Heroku is a service for deploying a server. Once you’ve deployed your app, you can access it at a URL provided by Heroku, or add your own. When I first started using Heroku, I found server deployment intimidating, so I’m writing this guide which should take you from zero knowledge to a high level of competency.

Two ways to access Heroku

Heroku has a graphical user interface available as its website, and a command line interface available as a downloadable program. To be an effective user of Heroku, you should use both, so if you haven’t already, go install the Heroku CLI.

Deployment with Heroku CLI

Let’s deploy this project on heroku through heroku CLI.

  1. Register on heroku.
  2. Then create new app and then write name of app and choose a region.
  3. Download to the system Heroku CLI and then open command prompt or terminal.
  4. Execute these commands on cmd with folder directory.
  5. Now its time for the flask for the model to deploy.
cd my-project/
git init
heroku git:remote -a my-project
git add .
git commit -am "make it better"
git push heroku master

6. Then go to settings your webpage is created.

Deployment with GitHub

We can also deploy our model by using github integration. The most common way to deploy to Heroku is via GitHub.

  1. ) create new repo on github

2.) After creating Github Repo upload your project either via web or via git bash.

3.) At the top right of heroku.dashboard.com, hit new and then create new app. Give it a name — the name is up to you — and then select either Europe or America for the location of the server (closer to your users is better).

4.) Once you’ve created a Heroku app, you should deploy some code to it. One way to do so is to press the GitHub button, and then select the repo you want to deploy to underneath the GitHub button.

5.) Finally, press enable automatic deploys. This means that any changes to the master branch of your GitHub repo will be sent to Heroku and be deployed automatically.

Once our application has deployed, we can navigate to the URL of our application and see it live on the Internet. Hence, Our model is deployed globally at https//app-name.herokuapp.com/ .

Wrapping Up

Heroku is a great platform to deploy your dynamic web projects. Using Heroku, you can deploy a web application without having to create your own server. Heroku also has a favorable free plan which will allow you to run an application for free in the cloud.

Now you’re ready to start deploying your applications to Heroku like an expert!

You can clone the Github repository via the link below:

Connect with me on Twitter and LinkedIn.

Do find time check out my other articles and further readings in the reference section. Kindly remember to follow me so as to get notified of my publications.

Thank You for reading

Please give 👏🏻 Claps if you like the blog.

GEEKY BAWA

just a silly Geek who love to seek out new technologies and experience cool stuff.

Do Checkout My other Blogs

Do Checkout My Youtube channel

Do Checkout My M.L. Model

If you want to get in touch and by the way, you know a good joke you can connect with me on Twitter or LinkedIn.

Thanks for reading!😄 🙌

Made with ❤️by Vaibhav Hariramani

Don’t forget to tag us

if you find this blog beneficial for you don’t forget to share it with your friends and mention us as well. And Don’t forget to share us on Linkedin, instagram, facebook , twitter, Github

More Resources

To learn more about these Resources you can Refer to some of these articles written by Me:-

Download THE VAIBHAV HARIRAMANI APP

The Vaibhav Hariramani App (Latest Version)

Download THE VAIBHAV HARIRAMANI APP consist of Tutorials,Projects,Blogs and Vlogs of our Site developed Using Android Studio with Web View try installing it in your android device.

Follow me

on Linkedin, instagram, facebook , twitter, Github

Happy coding ❤️ .

--

--

VAIBHAV HARIRAMANI

Hi there! I am Vaibhav Hariramani a Travel & Tech blogger who love to seek out new technologies and experience cool stuff.