Hello everyone! I was told to post this here because some might find it interesting. Colaboratory is a free-to-use Jupyter Notebook environment and hosted run-time provided by Google. While it is fairly restrictive out of the box in terms of port access I found a clever way to develop and run Streamlit apps using ngrok as a tunnel to the Streamlit TCP port. Enjoy!
Wait you mean Streamlit on free Colab TPU ?
Definitely need to test that, huge thanks for the tip !
NB : oh and welcome to the forums @tuffacton
i try to run it but got this error message in ngrox Failed to complete tunnel connection The error encountered was: connect: connection refused**"
Hi Sinta, are you modifying any code? I just ran a fresh notebook from the gist and it seems to be working for me. Are you willing to share your notebook?
hello i get the problems like here when i click my Locall url:
This site can’t be reached
172.28.0.2 took too long to respond.
Try:
- Checking the connection
- Checking the proxy and the firewall
- [Running Windows Network Diagnostics](javascript:diagnoseErrors())
ERR_CONNECTION_TIMED_OUT
I receive the same kind of error
Read the instructions in the notebook clearly. Do not use the IPs in the last cell, only use the url provided by ngrok. Colaboratory will not expose arbitrary ports.
Great one @tuffacton!
Currently, I’ve got the " Too Many Connections" error message, preventing my scripts to work seamlessly:
Have you come across this too?
Thanks,
Charly
Hey, Thanks for the awesome hack, however, I want to point out that, due to some dependency error, colab is asking to install a lower version of ipykernel.
Streamlit Version : 0.69.2
1st image shows that while installing streamlit on colab, receiving an error.
In 2nd image I’m trying to resolve the error by downgrading the ipykernel verson and restarting the runtime to make the changes.
In 3rd image after restarting the kernel I was able to install streamlit & ngrok
4th image shows successfully running streamlit app on colab by accessing the link given by ngork (arrow showing ngrok link in 3rd image.) as mentioned by @tuffacton .
Hope this helps.
Hi, Can anyone help me - How to remove the default code and write my own streamlit code and run here?
And when we run streamlit hello, where is this hello file written, how to replace it with my own file?
To run your own streamlit code file, upload your own say app.py file to the colab runtime and instead of !streamlit hello replace it with !streamlit run \content\app.py
Just discovered that npm
is available on Colab so you can use any node package in Colab, which means localtunnel to expose your Streamlit app to the world (until the notebook or the localtunnel server get shut down at least XD)
so you can run the following 4 Colab cells, and get the exposed URL at the end. :
!pip install streamlit
!npm install localtunnel
!streamlit run app.py &>/dev/null&
!npx localtunnel --port 8501
I actually do think ngrok is the more robust solution but there’s a bit more setup
Fanilo
Nice one Fanilo!
Can you benefit from Colab’s free GPU/TPU that way?
Charly
I tried to play it before but it didnt work,
so I thought this could never happen
but Wow you are really awesome
I was struggling with ngrok as every 2nd time it doesnt work. this workaround is awesome man.
Thank you!
from pyngrok import ngrok
for t in ngrok.get_tunnels():
ngrok.disconnect(t.public_url)