Run streamlit app in google colab

                     


        Step 1: Create a New Notebook and write your app.py

The first step will be to create a new notebook and write the code for your app, saving it as app.py using the %%write app.py code at the start of the code, and do not forget to import Streamlit in your code

Step 2: Get an Authentication Token from ngrok

The next step is to get an authentication token from ngrok by creating a new account at ngrok.com, and in the dashboard, you will find your Auth token at the ‘Connect your account’ section. Copy and paste the token in a new cell following this format.

Step 3: Download and save ngrok in sandbox

Next, download and save a stable version of ngrok to the sandbox.

Step 4: Unzip ngrok

Next, unzip the ngrok file.

Step 5: Create a Local Tunnel for ngrok to host app.py

A local tunnel needs to be created for ngrok to host the app.py For this, run the following code in a new cell, and a new URL will be given, but do not click on the URL until the final step is done

    get_ipython().system_raw('./ngrok http 8501 &')

Step 6: Run Streamlit app.py

The final step will be to run your code, simply using the code

    !streamlit run /content/app.py

The following should appear

Once everything is done, now go back and click on the https link in step 5, and this will lead you to the app. Enjoy!

Post a Comment

Previous Post Next Post