A simple to no use no-fuss webapp to summarise your paragraphs. Think TL;DR.
Request live demo if http://107.22.27.124:8501/ is down! I am cutting on some server cost, the slug size for this app > 1Gb.
- Create a Git Repo
Note: Heroku allows deployment using Git or Docker.
git init
- Build your App
The code is in main.py
- Test your App (Local Environment)
streamlit run main.py
- Create your requeriments.txt file
This file contains the libraries that your code needs to work. To do this, you can use pipreqs
.
pipreqs /path/to/your/app/
After this command, a requirements.txt will be created in the folder of your app
streamlit
sentencepiece
torch
transformers
- Setup.sh and Procfile
Heroku needs these files for starting the app
- setup.sh : create a streamlit folder with both credentials.toml and config.toml files.
- Procfile : This file executes the setup.sh and then call streamlit run to run the app
# Setup.sh
mkdir -p ~/.streamlit/
echo "\
[server]\n\
headless = true\n\
port = $PORT\n\
enableCORS = false\n\
\n\
" > ~/.streamlit/config.toml
# Procfile
web: sh setup.sh && streamlit run main.py
- Create a Heroku Account
Create a free account
- Install Heroku CLI
- Login into Heroku CLI
Move to your App folder and execute heroku login
- Deploy the App
Deploy your app by running heroku create
in your app folder
- Check it
Check your app by running heroku ps:scale web=1
After that, push your code
git add .
git commit -m "message"
git push heroku master
- Open it
Open your app using heroku open
You can launch a Linux instance using the AWS Management Console as described in the following procedure. This tutorial is intended to help you quickly launch your first instance, so it doesn't cover all possible options. For information about advanced options, see Launch an instance using the new launch instance wizard. For information about other ways to launch your instance, see Launch your instance.
To launch an instance
-
Open the Amazon EC2 console at https://console.aws.amazon.com/ec2/.
-
From the EC2 console dashboard, in the Launch instance box, choose Launch instance, and then choose Launch instance from the options that appear.
-
Under Name and tags, for Name, enter a descriptive name for your instance.
-
Under Application and OS Images (Amazon Machine Image), do the following:
-
Choose Quick Start, and then choose Amazon Linux. This is the operating system (OS) for your instance.
-
From Amazon Machine Image (AMI), select an HVM version of Amazon Linux 2. Notice that these AMIs are marked Free tier eligible. An Amazon Machine Image (AMI) is a basic configuration that serves as a template for your instance.
-
-
Under Instance type, from the Instance type list, you can select the hardware configuration for your instance. Choose the
t2.micro
instance type, which is selected by default. Thet2.micro
instance type is eligible for the free tier. In Regions wheret2.micro
is unavailable, you can use at3.micro
instance under the free tier. For more information, see AWS Free Tier. -
Under Key pair (login), for Key pair name, choose the key pair that you created when getting set up. Warning
Do not choose Proceed without a key pair (Not recommended). If you launch your instance without a key pair, then you can't connect to it. -
Next to Network settings, choose Edit. For Security group name, you'll see that the wizard created and selected a security group for you. You can use this security group, or alternatively you can select the security group that you created when getting set up using the following steps:
-
Choose Select existing security group.
-
From Common security groups, choose your security group from the list of existing security groups.
-
-
Keep the default selections for the other configuration settings for your instance.
-
Review a summary of your instance configuration in the Summary panel, and when you're ready, choose Launch instance.
-
A confirmation page lets you know that your instance is launching. Choose View all instances to close the confirmation page and return to the console.
-
On the Instances screen, you can view the status of the launch. It takes a short time for an instance to launch. When you launch an instance, its initial state is
pending
. After the instance starts, its state changes torunning
and it receives a public DNS name. If the Public IPv4 DNS column is hidden, choose the settings icon ( ) in the top-right corner, toggle on Public IPv4 DNS, and choose Confirm. -
It can take a few minutes for the instance to be ready for you to connect to it. Check that your instance has passed its status checks; you can view this information in the Status check column.
There are several ways to connect to your Linux instance.
Important
You can't connect to your instance unless you launched it with a key pair for which you have the .pem
file and you launched it with a security group that allows SSH access from your computer.
After you've finished with the instance that you created for this tutorial, you should clean up by terminating the instance.
Important
Terminating an instance effectively deletes it; you can't reconnect to an instance after you've terminated it.
Step 2 -
Select your instance, and copy the Public DNS(IPv4) Address from the description. It should be something starting with ec2.
Once you have that run the following commands in the folder you saved the streamlit.pem
file.
chmod 400 streamlit.pem
ssh -i "streamlit.pem" ubuntu@<Your Public DNS(IPv4) Address>
Installing Miniconda
sudo apt-get update
wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda.sh
bash ~/miniconda.sh -b -p ~/miniconda
echo "PATH=$PATH:$HOME/miniconda/bin" >> ~/.bashrc
source ~/.bashrc
Installing Dependencies
pip install streamlit==0.65.2
pip install torch==1.9.0
pip install transformers==4.20.1
If torch installation gets stuck in the end use this command instead
pip install torch==1.9.0 --no-cache-dir
Getting a copy of app from GitHub
git clone https://github.com/siddharthksah/NLP_Paragraph_Summariser_WebApp
cd NLP_Paragraph_Summariser_WebApp
streamlit run main.py
This should give the external URL which will look something like http://107.22.27.124:8501/
To make sure the webapp is live even when we exit the terminal, we will use tmux. First, we stop our app using
Ctrl+C
and installtmux
.
sudo apt-get install tmux
tmux new -s StreamSession
streamlit run main.py
You will be able to see your app at the External URL. The next step is to detach our TMUX session so that it continues running in the background when you leave the SSH shell. To do this just press Ctrl+B and then D
(Don’t press Ctrl when pressing D).
That's it, done!
#Base Image to use
FROM python:3.7.9-slim
#Expose port 8080
EXPOSE 8080
#Optional - install git to fetch packages directly from github
RUN apt-get update && apt-get install -y git
#Copy Requirements.txt file into app directory
COPY requirements.txt app/requirements.txt
#install all requirements in requirements.txt
RUN pip install -r app/requirements.txt
#Copy all files in current directory into app directory
COPY . /app
#Change Working Directory to app directory
WORKDIR /app
#Run the application on port 8080
ENTRYPOINT ["streamlit", "run", "main.py", "--server.port=8080", "--server.address=0.0.0.0"]
Building the Docker Image
docker build -f Dockerfile -t app:latest .
Running the docker image and creating the container
docker run -p 8501:8501 app:latest
You might need to use sudo before the docker commands if the user does not have admin privileges.
After you made your own Docker image, you can sign up for an account on https://hub.docker.com/. After verifying your email you are ready to go and upload your first docker image.
- Log in on https://hub.docker.com/
- Click on Create Repository.
- Choose a name (e.g. verse_gapminder) and a description for your repository and click Create.
- Log into the Docker Hub from the command line
docker login --username=yourhubusername --email=youremail@company.com
just with your own user name and email that you used for the account. Enter your password when prompted. If everything worked you will get a message similar to
WARNING: login credentials saved in /home/username/.docker/config.json
Login Succeeded
Check the image ID using
docker images
and what you will see will be similar to
REPOSITORY TAG IMAGE ID CREATED SIZE
verse_gapminder_gsl latest 023ab91c6291 3 minutes ago 1.975 GB
verse_gapminder latest bb38976d03cf 13 minutes ago 1.955 GB
rocker/verse latest 0168d115f220 3 days ago 1.954 GB
and tag your image
docker tag bb38976d03cf yourhubusername/verse_gapminder:firsttry
The number must match the image ID and :firsttry is the tag. In general, a good choice for a tag is something that will help you understand what this container should be used in conjunction with, or what it represents. If this container contains the analysis for a paper, consider using that paper’s DOI or journal-issued serial number; if it’s meant for use with a particular version of a code or data version control repo, that’s a good choice too - whatever will help you understand what this particular image is intended for.
Push your image to the repository you created
docker push yourhubusername/verse_gapminder