Hey guys,
In this tutorial, I will show you how to deploy your streamlit web application for free on
render. If you follow the steps from this tutorial,
your web application will be live on the internet, and you can share it with the world. Before we start, let me point out that you
could also deploy your app to the streamlit community cloud. The deployment process is super easy, and
it is also free. In just a couple of clicks, you have your
streamlit app up and running on the internet. While I like the streamlit community cloud,
in some cases, you might want to avoid the streamlit branding in the lower right corner
of your app or wish to have the option to scale up the server in the future. That is why we are going to deploy the streamlit
app to render. In the past, I have created a similar tutorial,
where I deployed a streamlit app to Heroku. However, Heroku announced that they will stop
their free trier at the end of November 2022. Ok, and with that out of the way, let us get
started. I assume that you have already developed a
streamlit application. For this video, I have picked a streamlit
project from my YouTube channel. In that tutorial, I created a digital resume,
which looks like this. I will also leave a link to the video tutorial
in the info card above and the description below if you are interested in this project. That said, this site is currently running
my local host. So, let us now see how to deploy this website
to the internet. By the way, the other files in the directory
are also needed for this project. So, I want to make sure to deploy those files
as well. As a first step, I will create a "requirements.txt"
file. The "requirements.txt" file contains all the
libraries the server must install to run your app. This file can be created manually by going
through your streamlit app and looking at what libraries are used. Yet, I prefer to generate this file automatically. To do so, I will use the "pipreqs" package. To install that package, spin up your terminal
or command prompt, type "pip install pipreqs" and hit enter. Once you have installed the package, ensure
you are in the same directory as your streamlit app. In my case, the project folder is on my desktop
in a folder called "digital resume". Inside this folder, I will now run "pipreqs
--encoding=utf8". I have used utf8 encoding, as I also have
used some emojis in my app. Otherwise, pipreqs might throw an error that
it cannot encode the Python file. Once done, you should see a new text file
in your folder. If you open up this file, you can see a list
of the required libraries. In my case, I have also used Pillow besides
streamlit. With that in place, we will upload the project
to GitHub. And do not worry if you have never worked
with Git or GitHub. I will explain each step as I go along. If you have not already created a free account
on GitHub, then go ahead and create one. It just takes a couple of minutes to set up
an account. After you are logged in, you want to create
a new repository. Just click on the little icon up here. Next, enter a name for your repo. In my case, I will simply type "digital resume
render tutorial". Afterwards, click on the "Creating repository"
button. Alright, so now we have a new empty repository
on GitHub. As the next step, we want to upload the files
from our computer to that repository. And to do that, I would recommend using GIT. Git is a free version control system. In simple terms, you can use GIT to keep track
of any changes that have been made to your files. To use GIT, we need to install it. Just head over to the following website. I will, of course, leave the link also in
the description below. On the website, download GIT for your operating
system. In my case, I will pick Windows and the 64BIT
version. Once downloaded, open up the installer and
keep the default settings. So click everywhere on next until GIT is installed. As I have it already installed, I will click
on cancel. Once that is in place, go back to your streamlit
project folder and open the terminal again. As before, ensure that you are in the correct
folder. Now, this will not be a complete tutorial
on GIT; I will show the basic commands to get your website up & running. The first command will be "git init". After running this command, you should see
a new folder. The git folder starts with a dot. That means it is a hidden folder. To also show hidden folders in Windows, you
can go to view and toggle on or off 'hidden items'. As the next step, we want to tell git to include
all files for the next commit. To do so, type "git add" and a period. I know those commands might confuse you if
you have never worked with git before. But stick with me; we just need a couple of
more commands. Next, we will commit the files to the staging
area by typing "git commit -m" followed by your message. In my case, I will simply type "initial commit". Ok, and with that, we can now connect our
local git folder with GitHub. Therefore, go back to your empty GitHub repo
and copy the following line to your clipboard. Paste it into your terminal and hit enter. As the last step will upload those files to
GitHub. If you followed the steps I have shown here,
you need to type "git push -u origin master" and press enter. Once that is done, we can go back to our repo. After refreshing it, you should now see all
your files here. Alright, and with that, let us now deploy
this GitHub repo to "render". On "render.com", you want to create a new
account. There is no credit card required. Once you have set up an account, click "Get
Started For Free". Render offers different services. For our streamlit app, we are only interested
in the "Web Services". Therefore, click on "New Web Service". Next, you want to connect your GitHub account. Just click here and then hit the install button. Afterwards, you should see a list of all your
repositories. Select the one you want to deploy. So, for me, it was the "digital resume render
tutorial". Next, enter a name for your web service. This name will also be part of your URL. I will call mine "digital-cv". I will keep the default settings for the environment,
region, branch, and build command. By the way, here you can also see why we have
created the "requirements.txt" file. When deploying the app, render will pick the
libraries you have specified in there and install them for your app. For the start command, you want to type "streamlit
run", followed by the name of your Python file. In my case, my python file is called "app.py". Alright, and to deploy the app, simply click
on "Create Web Service". Afterwards, you should see a window with the
logs. Now, deploying an app might take some time. In my case, it took around 15 minutes. When you see in the logs a message that states
that the streamlit app has started, you know that the deployment process is done. To validate this, click on events. You should now see a green cloud saying that
the deployment is live. If that is the case, you can reach your app
by clicking the following link. Alright, guys, and here it is. Your streamlit app is live on the internet. Now, a couple of remarks regarding the free
tier on render. Like on Heroku, your website will fall asleep
after 15 minutes of inactivity. This is not a problem per se; it just means
it might take up to 30 seconds to load and wake up your website. So, keep that in mind if your website might
take some time to load. And with that said, let me also show you the
steps if you want to make changes to your website. Let us say, in my app, I want to change the
name of the CV. Instead of John Doe, it should be Peter Parker. After those changes, I will save the script. Next, I will return to my terminal and reenter
some of the commands we have seen earlier. First, I will type "git add .". Afterwards,
I will commit the changes using "git commit -m" followed by the message. In my case, I will write "Change Name". As we have already connected the local git
folder with GitHub, I can directly type "git push -u origin master" to push the changes
to GitHub. You could validate this by going back to your
GitHub repo. On here, let me reload the site. You should now see your changes when you open
the "app.py" file. And also, if I navigate to my Dashboard and
reload the site, we can see that render will automatically deploy your changes. Now, once again. This process might take some time. In my case, it took around 6 minutes. But once done, you should see another green
cloud with your commit message. If you now go back to your website and reload
your page, it could take a couple of moments until you see your changes. Also, you might need to clear the cache on
your browser to see the modifications. In Chrome, you can hold down "CTRL" and then
click on the refresh icon. If I do that, I can now see the updates on
the website. Ok, guys, and that is all I have for you today. I hope you found this tutorial helpful. As always, if you have any questions, please
let me know in the comments. Thanks for watching, and see you in the next
video.