![]() ![]() Now that we have the barebones of our site up and running, how do we run the python scripts on the inputs and then show the user the results? Running the Python scripts on the inputs. Even more importantly don’t forget to state method = “POST” so Flask knows to request the information stored in the form. It’s important here to state “enctype= ‘multipart/form-data”, so Flask knows how to encode the input. As you can see here, we’ve specified the input type as “file” and specifically stated. Line 12 is simply the form title, which is nothing more than text, line 13 is the file selection and line 14 is the submit button. Within the form, we have three div tags ( lines 12,13, & 14). In line 11 we specify the beginning of our form and close it at line 15. Lines 11–15 are the ones of interest to us, however. In this case, it's simply ‘/’ - so our initial page.Īs can be seen, it's a pretty straightforward HTML page as you’ll have seen one hundred times before. And finally, we use the route decorator to tell Flask which URL should call our function. Just don’t call it Flask as this will conflict with Flask itself. We then initialise the app ( line 5) - you can call it whatever you want but it's a convention to use dunder ‘name’. We first have to import all the required packages from Flask, which can be seen below ( Line 2). The setup for this project is pretty straightforward. So as a reminder the goal here is to take a user input from an HTML form, run a python script on it and output the result in a fully automatic process. I’ve written a pretty popular piece on how to show Matplotlib plots and Panda’s dataframes before - if that sounds useful then please check it out. And since they are written in Python, it is easy to integrate Python scripts into your routing. Flask, along with Django, is commonly used in web development. ![]() The best approach I found was to use Flask - a micro web framework written in Python. Turns out it's actually not that easy to run Python scripts online and I didn’t find much help online - but below is all that I found. So the aim of the game was to produce a website that takes user input, runs python scrips on them, and then returns them to the user in a usable fashion. This is super useful as it's completely automated, as long as the servers don’t crash (they might - I have no idea) then this should just run itself. But this article is aimed more at all you techy lot and centres around how to run python scripts on user input and produce an output - without saving the input anywhere. You can read about the usefulness of the website here. So being a man of the people, I thought I’d give them what they don’t know they need - a website where they can analyse their own eBook. All data scientists know how good computers are getting at analysing text, but most other people don’t.
0 Comments
Leave a Reply. |
Details
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |