DEV Community

Cover image for Use ngrok with secret key on Google Colab
0xkoji
0xkoji

Posted on

21 1 1 1 1

Use ngrok with secret key on Google Colab

What is ngrok?

ngrok combines your reverse proxy, firewall, API gateway, and global load balancing to deliver apps and APIs.

https://ngrok.com/

Simply put, ngrok makes it easy to publish a web application running locally with a single command.
This is very useful to build prototyping.

For Google Colab, using ngrok would make things easy if you want to run an open source LLM and use it via an API server (like FastAPI, Flask etc).

How to use ngrok on Google Colab

There are 3 steps to use ngrok with Google Colab secret key.

  1. Download ngrok
  2. Set secret key
  3. Load secret key

Step1. Download ngrok

This step is pretty straightforward.
Download zip file for linux and unzip it.

!wget https://bin.equinox.io/c/4VmDzA7iaHb/ngrok-stable-linux-amd64.zip
!unzip -o ngrok-stable-linux-amd64.zip
Enter fullscreen mode Exit fullscreen mode

Step2. Set secret key

Click key icon in the sidebar and click Add a new secret.
You will need to fill two text box. One is the key name and you can name whatever you want and the other is the key value or token. Then you need to click a toggle button to enable the key.

Image description

Step3. Load secret key

The following code is very simple, load the secret key and pass it to ngrok via ngrok's python package for authentication.

import os
from google.colab import userdata
from pyngrok import conf
os.environ["NGROK"] = userdata.get("NGROK")
conf.get_default().auth_token = os.environ["NGROK"]
Enter fullscreen mode Exit fullscreen mode

These three steps will work for things that you need to pass a secret key or token on Google Colab.

Image of Datadog

The Future of AI, LLMs, and Observability on Google Cloud

Datadog sat down with Google’s Director of AI to discuss the current and future states of AI, ML, and LLMs on Google Cloud. Discover 7 key insights for technical leaders, covering everything from upskilling teams to observability best practices

Learn More

Top comments (2)

Collapse
 
detzam profile image
webstuff

now we need to see how to implement it into vagrant

Collapse
 
0xkoji profile image
0xkoji

???

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more