So, I have a website where I want to show my outputs of my machine learning programs in real-time. Every output is based on the User's input.
I have successfully created my python scripts which give me my desired output, but untill now i was just running my script on my local machine.
I am using matplotlib, numpy, sci-kit and packages similar to them, I need to create a web UI that could run a python script from an html button click and then show the matplotlib graph that was generated.
I have been searching for an answer for quite sometime now, here are my findings
Now I somewhat understand all these techniques. but I cannot find some perfect example to help me with my situation. Few things that I want you to know is, I have a ready HTML file, along with CSS. I am using the Google Console VM-instances for my remote server.
So, in all I just need a solution to my following problem.
Your flask endpoint could look something like this:
@app.route('/evaluate', methods = ['GET', 'POST'])
def index():
if request.method == 'POST':
# Computed ML output
output = compute_data(data)
# Format to graph data
graph_data = transform_to_graph(output)
# Pass data to the template
return render_template('graph-view.html', graph_data=graph_data)
return render_template('main.html')
Where main.html will be page with button and user input:
<!DOCTYPE html>
<html>
<head>
<title>User Input</title>
</head>
<body>
<h1>Provide with input</h1>
<form method="post" action="/evaluate">
<input type="text" name="data">
<input type="submit" value="Evaluate">
</form>
</body>
</html>
This could be pretty simple and straightforward tutorial for Flask basics: https://www.codementor.io/overiq/basics-of-flask-fzvh8ueed. Search for other sources and you will get into that quickly. For deployment you will also need application server running your flask app, as flask by it self isn't production ready. I could recommend Gunicorn, here is one of the many tutorials showing setup of Gunicorn with Nginx proxy web server: https://tutorials.technology/tutorials/71-How-to-setup-Flask-with-gunicorn-and-nginx-with-examples.html. Please search for this topic, there's plenty of tutorials out there.