My Brain Cells

Easiest (and best) learning materials for anyone with a curiosity for machine learning and artificial intelligence, Deep learning, Programming, and other fun life hacks.

Running Streamlit from Google Colab


Streamlit is a Python library for building Web Apps. System’s configuration and compatibility plays a handy role in running the Web App locally on your computer.

Google Colab comes to the rescue here . We can use Colab without worrying about the system configuration.

I have divided the Colab notebook into 3 cells each indicating specific task.

1st Cell

!pip install streamlit
!pip install pyngrok==4.1.1
from pyngrok import ngrok

Installing Streamlit for creating web Apps.

Installing Pyngrok which is python wrapper for Ngrok Server. Ngrok is a powerful solution for providing secure tunnels from your local system to the public.

2nd Cell

import streamlit as st
st.title(‘Diazonic Labs’)

we use the magic command %%writefile to write the contents of the cell to a file.

I have just imported a simple Hello World kind of program displaying a text.

3rd Cell

!nohup streamlit run &
url = ngrok.connect(port = ‘8501’)

Use the command line statement streamlit run to run the Web App.

Append it with nohup command so that thee output is stored in nohup file

Also put & towards the end. This helps a streamlit file run in the background.

Next connect to ngrok with default port of 8501 and get the public URL

NOTE: Run the cells in order .

Once you get the public URL, make changes only in the 2nd cell and execute it. Dont execute cells 1 and 3 after you get public URL. This might lead to errors.


Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top