Build, Save and Deploy your first Web App Using Flask and PythonAnywhere
Sample tutorial for getting started with Flask and PythonAnywhere

Creating your first Web App for text summarization and deploy it with PythonAnywhere.
Introduction
Text summarization refers to the technique of shortening long pieces of text. The intention is to create a coherent and fluent summary having only the main points outlined in the document.
Automatic Text Summarization is one of the most challenging and interesting problems in the field of Machine Learning and Natural Language Processing (NLP).
Through this article, we’re going to build a simple Application for text Summarization using Flask, a Python web application framework. If you love reading but you have no time for lengthy text, then our App will be the best solution for you.
In this tutorial, we will be able to build a Text Summarizer Web application with Flask and some great NLP packages like SpaCy, NLTK, Gensim and Sumy and host it on PythonAnywhere. We will call this app Summerise.
Table of contents
- Text Summarization Approaches
- NLP packages that we used in this App
- Building our Web App with Flask
- Deploy our App with PythonAnywhere
- What’s Next?
Text Summarization Approaches
There are two main categories of how to summarize text in NLP:
Extraction-based summarization: These techniques involve pulling keyphrases from the source Text and combining them to make a summary. That’s why, identifying the right sentences for summarization is important in an extractive method.
Abstraction-based summarization: These techniques generate an entirely new summary by using advanced NLP techniques. When abstraction is applied for text summarization in deep learning problems, it can overcome the grammar inconsistencies of the extractive method.
However, the text summarization algorithms required to do abstraction are more difficult to develop, that’s why in this article and for simplicity purpose we will be focusing on the extractive summarization technique.
NLP packages that we used in this App
NLTK (Natural Language Toolkit) is used for such tasks as tokenization, lemmatization, stemming, parsing, etc. This library has tools for almost all NLP tasks.
Spacy is the main competitor of the NLTK. These two libraries can be used for the same tasks.
Gensim is a module that provides functions for summarizing texts. Summarizing is based on ranks of text sentences using a variation of the TextRank algorithm.
Sumy is simple library and command line utility for extracting summary from plain texts. The package contains simple evaluation framework for text summaries.
Building our Web App with Flask
In this tutorial we will show you step by step how to build a simple Python Flask application.
Flask is a microframework for Python based on Werkzeug, Jinja 2 and good intentions.

We assume that the user has prior experience with the following:
- Pip & virtualenv.
- HTML, CSS, and Bootstrap.
Setting up the development environment
Before we start with the technical material, we need to get our environment set up first. However, you may already have what we actually need if you are familiar with that.
But if you are not, that’s not a problem because I’m going to describe what you should need to set the environment.
In general, what we need:
- Download Anaconda for the operate system that’s relevant to you. For Windows you’re going to want to install the Python 3 version and we recommend the graphical installer. There’s a 64 bit version and a 32 bit version that depends on your computer. In fact, Anaconda’s going to come with lots of data science packages. Once you’ve downloaded Anaconda you should be able to run Python at your command line after you’ve finished the installation process.

2. Since you’ve already set up Anaconda and Python all right. Now let’s set up our development environment. We can see that we have Visual studio in the Anaconda Navigator. You just need to Click on Launch Button.

Let’s show you how you can install useful extension for Web development:
- In Visual Studio Code, go to extensions and Install Web Development Essentials Extension Pack. This is an extension pack with extensions that are extremely helpful for Web Developers (example: Live server, Bracket Pair Colorizor, Auto Rename Tag, etc.)

3. Now, we set up the virtual environment with the command line tool or the terminal exists in VS code (it’s optional to set up a virtual env but we recommend using it because you’re going to be able to run our code securely). Therefore, for convenience we’ve already created a requirements.txt file that you can use to install with single line all the libraries will be using.
In order to use this file at the command line, you need to cd (change directory) to wherever you saved the unzipped version of this code.
So let’s go to our command line, find the requirements.txt and show you how you can create a virtual environment and then easily install all the libraries required for the project.


Let’s activate our virtual environment and install the packages we’ll need for this project:

For references purposes the code for this project is available on my GitHub.
Running The Application
Set up the project folder as below. The templates folder will contain the index.html file that will display on the website. app.py is the file where all our Flask logic will go. Do not name any of your files as flask.py, because this will conflict with Flask itself. The static folder will contain css, js, images and video folders.
To display the App locally run $python app.py on your terminal and head over to http://127.0.0.1:5000 to see your application.
Deploy our App with PythonAnywhere
Have you wished to deploy your Python web apps to a live server? Now, it’s possible with PythonAnywhere that gives us access to a Linux server via the server terminal which we can access from our internet browser. In this part, we will run through steps to setup PythonAnywhere. Let’s get started!
1. Setting up an account:
We can easily sign up for a free plan on PythonAnywhere (Beginner Account) giving us access to 500 MB disk space. If we want more server resources, we may upgrade to one of the paid plans.

2. Go to the Web menu item and then press the Add new web app button, Click Next then click on Flask and click on the latest version of Python and then click Next again to accept the project path.
That’s it. You can visit your web app on https://yourusername.pythonanywhere.com. (change username with your actual PythonAnywhere username). That’s the URL of your app. If you want to upload your own project, please follow the next steps:
- In the Code section of the Web menu page click on Go to Directory next to Source Code.

2. Delete the flask_app.py file.
3. Use the Upload a file button to upload your own app.py Python file and create a templates and a static directory in the Directories section and upload your files there.
4. In the Code section of the Web menu page click on WSGI configuration file. Change flask_app with app and save the file.

5. Go to the Consoles, Click in Bash and install all the libraries required for this project.

6. Go to the Web menu page and click on the Reload button.
Now your Flask app should be running on https://yourusername.pythonanywhere.com. If you face any problems, just check your Error log File.
What’s Next?
Automatic Text Summarization is a hot topic of research, and in this article, we have covered just the basic and simple tips of this topic. Next time, we will explore the abstractive text summarization technique where deep learning plays a big role. In addition, we can also look into the following tasks:
Specific algorithms for summarization:
- Text summarization using RNNs and LSTM
- Text summarization using Generative Adversarial Networks (GANs)
Add more tricks:
- Calculate the number of words in the text
- Calculate the time when summarized the text
Front-end Design:
- Ameliorate the front-end design for our App to be more attractive
Conclusion
I think flask is a great framework specially for those who are getting started in this field. And I really hope this post helped you in understanding the concept of building and deploying a Web App for Text summarization.
I will try to cover the abstractive text summarization technique in a future article. Meanwhile, feel free to use the comments section below to let me know your thoughts or ask any questions you might have on this article.
Happy reading, happy learning and happy coding.
Before You Go
The corresponding source code can be found here.

