Creating a WEB UI for my python scripts Creating a WEB UI for my python scripts flask flask

Creating a WEB UI for my python scripts


  • Hi, so you will need some python web framework, as you alreadymentioned flask could be good option.
  • To deploy your application to the production you will also need a webserver running on your remote server.
  • After that, you can setup your web server to communicate with yourflask running application.

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.