Run Flask on Google Colab Using Ngrok Python Library

Google Co-laboratory Lab, or "Co-lab" for short, allows you to write and execute Python in your browser, with
1. Zero configuration required
2. Free access to GPU's
3. Easy Sharing



Today we'll learn how we can run a development server on Google Colab to test(or develop) Flask web applications.

Google Co-lab provides a VM(virtual machine) so we cannot access the localhost(all it doen it route it to our local machine's localhost 127.0.0.1:5000) as we do on our local machine when running a local web server. What we can do is expose it to a public URL using flask-ngrok Python library.

Follow these simple steps:-

1. Let us first install flask-ngrok in our Co-lab notebook:

2. After the library is installed let's create a simple Flask app with flask-ngrok:

3. Run the Google Co-lab cell




A Secure URL is provided for the server running on Co-lab. Traffic stats can be used to debug in case of any errors in you flask web app.

URL Format Provide by ngrok : <9 digit random alpha-numeric id>.ngrok.io

This method proves useful in ways to demonstrate your web app to your peers before deploying it into production server. Especially in projects involving the requirement of high computational power (object detection, image classification).

Source Code Link : Google Co-Lab Notebook Link 

Post a Comment

Previous Post Next Post