Personality Prediction System End to End Deployment on Flask

Jino Rohit
3 min readJun 6, 2022

I’m planning to cover a three part series with main emphasis on deployment starting with local deployment on flask, moving onto EC2 servers and then finally dockers.

Modelling is fun and all but are you able to produce any business value with the models simply lying in your google colab/jupyter notebooks etc? Without deploying your complex model, there would be no point in making a model in the first place.

Model Deployment might just be the hardest stage

It works on mine tho!

Familiar familiar lines where your friend hands over his model to you along with instructions to run the code yet you can’t seem to run it. This can happen due to conflicting packages, missing libraries or even poor code quality. This is where softwares like Docker can help which packages everything as a whole. We will be covering this soon .

It’s not always about the results

Imagine a model scoring 99.99% accuracy yet taking 20 minutes to make a single prediction? Do you think that will work real time? Sometimes we need to sacrifice performance for time efficiency and other factors.

What about the servers?

Can you always get a large enough server to handle all your load requests? Very few companies have access to such high capacity servers or even cloud services.

Model deterioration

This is a phase after model deployment. You job doesn’t end here . Sometimes updates can break the whole code, the shift in data where the model must’ve trained on a different distribution and suddenly it starts seeing a new distribution and starts making mistakes. In this case, the model has to be retrained.

You can find the whole code here — https://github.com/JINO-ROHIT/Medium_Flask_Blog

In this project, I have built a very simple personality predictor app that runs on flask server. We will divide the whole process into four stages

Before that, we need to build a nice folder structure, something like this

Static — is where you can keep all your images and other metadata

Templates — is to store the html files that will get displayed on the website

app.py — is the main file where you create the flask server instance and pass the feature inputs for final prediction and render the results back

baseline_personality.pkl — the serialized version of your trained model

requirements.txt — a list of all the dependencies to run the code

Stage 1 — Model Building on Jupyter Notebook

Disclaimer — Here, the emphasis is to not make state of the art predictions rather to get a simple baseline model working and then deploy it.

Stage 2— Building a Frontend

We will be using simple HTML to build our frontend. A simple HTML form that can take in the features from the user should suffice. Although feel free get as creative as you want ( I suck at CSS tho )

Stage 3— Building the Flask server

Stage 4— Results and Experimentation

Once you have all the pieces in place, you just have to run the app.py script and your flask server will startup on the url — http://127.0.0.1:5000/.

On clicking this you should be able to the index.html render up. Let’s try giving some values to see how it works.

Now this is pretty cool ! We were able to build our very own personality predictor system and deploy it as well. I would encourage you to experiment more and build more cooler stuffs. Until then, toodles :)

You can also find me here — https://www.linkedin.com/in/jino-rohit-6032541b5/

--

--