Expose streamlit app with Colab

Ngrok is a service that allow you to expose TCP, HTTP and HTTPS port outside your network without the necessity to have a public IP. In particular we will use pyngrok to expose a simply streamlit app.

How to work on Google Colab with Streamlit

So start a colab notebook and follow the guide.

Create Streamlit APP

We can start by installing streamlit and writing an app.py:

!pip install streamlitwith open('app.py', 'w') as f:
f.write('import streamlit as st\nst.title("Title")')

We can edit this file like in the figure by clicking it on colab file system.

Now we are ready to run it, and put the process in background:

!streamlit run app.py &>/dev/null&

Now the app is exposed at localhost:8501 inside your colab.

Public expose with Ngrok

Now to use that port we need pyngrok to expose outside the colab notebook.

Start registering on Ngrok ang copy the Key.
Now into the notebook you can install pyngrok and past your Key.

!pip install pyngrok==4.1.1
from pyngrok import ngrok
!ngrok authtoken <PASTE YOUR API KEY>
public_url = ngrok.connect(port='8501')
print(public_url)

Now it printed a public url where you can find your streamlit app.

(Remember that if you edit the app.py it automatically reload the app without need to restart)

Conclusions

Streamlit is a very good tool to create simplyest python web interfaces for our demo, and it is very most used in AI demos like on Spaces in Huggingface, but it can be used for any demo you want. It also have a simply authentication lib to protect the access. With that tecqnique we can expose to the world something that are on our computer or into a colab notebook, for example to use GPU in our demo.
For these exciting feature we must regrate the opensource community, so contribute you too and enjoy!

--

--

--

Linux user and Open Source fun. Deep learning PhD Student, Full stack web developer, Mobile developer, Musitian.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Bitcoin Php Class Variable

Weekly report — 06.06.2022–12.06.2022

RegEx Examples

Sonarqube: First steps and understanding the metrics

Creating a Ticker Like Marquee Text using RecyclerView in Android

Designing your first REST API — Part 1

Gateway DAO Whitepaper

MSR Interview #2: Georgios Gousios

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Nicola Landro

Nicola Landro

Linux user and Open Source fun. Deep learning PhD Student, Full stack web developer, Mobile developer, Musitian.

More from Medium

Konnichiwa, Streamlit

Python Lesson 32: Intro to Python NLP (NLP pt. 1)

How to make text in images on the harddrive searchable

output of the script

Creating Weather Chat-bot