Simple Machine Learning Model Deployment with Flask in Python

Part 2 of how to deploy a machine learning model with Flask in Python.

Elanthirayan
Python in Plain English

--

Photo by Shahadat Rahman on Unsplash

Send the data from the server file to the web page and display the data on the webpage.

We need to pass the data when we are rendering the HTML page from Python.

Now let’s see how to pass the string value from the server file.

Look at the below code “BasicFlask.py”

from flask import Flask, render_template, requestapp = Flask(__name__)
@app.route(‘/’)
def before_submit():
return render_template(‘BasicWeb.html’, data=”My data from the python file!!!…”)


if __name__ == ‘__main__’:
app.run(port=3000, debug=True)

The above script is passing the data as “My data from the python file!!!…”

Then we will make the change in the HTML file so that it can display it on the web page.

<!DOCTYPE html>
<html>
<head>
<title>Basic Flask HTML</title>
</style>
</head>
<body>
<h1>Hello World!!</h1>
<h2>{{ data }}</h2>
</body>
</html>

{{ data }} will display any value that has been passed. “data” variable name has been passed from the server file.

Let’s see the output — what it looks like.

Data passed from the server

In the next part, we will see the conditions to use it in the HTML page, based on the data that is passed from server.

More content at plainenglish.io

--

--

Technology enthusiast with a passion for VR/AR, ML, and IoT. I am excited to explore and push the boundaries of what is possible with these tools/techniques.