|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "markdown", |
| 5 | + "id": "5a6f5a26", |
| 6 | + "metadata": {}, |
| 7 | + "source": [ |
| 8 | + "# Running the Intugle Streamlit App on Google Colab\n", |
| 9 | + "\n", |
| 10 | + "This notebook guides you through the process of running the Intugle semantic model builder, which is a Streamlit application, directly within a Google Colab environment.\n", |
| 11 | + "\n", |
| 12 | + "Since Colab provides a containerized environment, we cannot directly access the web server started by Streamlit. To solve this, we will use `ngrok`, a tool that creates a secure public URL (a \"tunnel\") to the Streamlit application running inside our Colab instance.\n", |
| 13 | + "\n", |
| 14 | + "**Steps:**\n", |
| 15 | + "\n", |
| 16 | + "1. **Install** the required Python packages.\n", |
| 17 | + "2. **Configure and run `ngrok`** to expose the Streamlit app.\n", |
| 18 | + "3. **Shut down** the tunnel when you are finished." |
| 19 | + ] |
| 20 | + }, |
| 21 | + { |
| 22 | + "cell_type": "markdown", |
| 23 | + "id": "c20194c1", |
| 24 | + "metadata": {}, |
| 25 | + "source": [ |
| 26 | + "## 1. Install Dependencies\n", |
| 27 | + "\n", |
| 28 | + "First, we need to install the `intugle` library. We use the `[streamlit]` extra, which ensures that Streamlit and all other necessary dependencies for the web app are installed at the same time." |
| 29 | + ] |
| 30 | + }, |
| 31 | + { |
| 32 | + "cell_type": "code", |
| 33 | + "execution_count": null, |
| 34 | + "id": "b26de4ff", |
| 35 | + "metadata": {}, |
| 36 | + "outputs": [], |
| 37 | + "source": [ |
| 38 | + "!pip install intugle[streamlit]" |
| 39 | + ] |
| 40 | + }, |
| 41 | + { |
| 42 | + "cell_type": "markdown", |
| 43 | + "id": "df8720f3", |
| 44 | + "metadata": {}, |
| 45 | + "source": [ |
| 46 | + "## 2. Configure and Run the Streamlit App\n", |
| 47 | + "\n", |
| 48 | + "Next, we will start the Intugle Streamlit app and expose it to the web using `ngrok`.\n", |
| 49 | + "\n", |
| 50 | + "**Important:** You need a free `ngrok` authentication token for this step.\n", |
| 51 | + "\n", |
| 52 | + "1. Go to the [ngrok Dashboard](https://dashboard.ngrok.com/get-started/your-authtoken) and sign up for a free account.\n", |
| 53 | + "2. Copy your authentication token.\n", |
| 54 | + "3. Paste the token into the `PYNGROK_TOKEN` variable in the code block below, replacing `<your-key>`.\n", |
| 55 | + "\n", |
| 56 | + "The script will then:\n", |
| 57 | + "1. Set your `ngrok` auth token.\n", |
| 58 | + "2. Start the Intugle Streamlit server in the background on its default port (`8501`).\n", |
| 59 | + "3. Create a secure public URL that tunnels traffic to the Streamlit server.\n", |
| 60 | + "\n", |
| 61 | + "Once you run the cell, click the public URL that is printed to access the application in your browser.\n" |
| 62 | + ] |
| 63 | + }, |
| 64 | + { |
| 65 | + "cell_type": "code", |
| 66 | + "execution_count": null, |
| 67 | + "id": "4564ff48", |
| 68 | + "metadata": {}, |
| 69 | + "outputs": [], |
| 70 | + "source": [ |
| 71 | + "from pyngrok import ngrok\n", |
| 72 | + "\n", |
| 73 | + "# TODO: Replace <your-key> with your actual ngrok authentication token.\n", |
| 74 | + "# You can get a free token from https://dashboard.ngrok.com/get-started/your-authtoken\n", |
| 75 | + "PYNGROK_TOKEN = \"<your-key>\"\n", |
| 76 | + "\n", |
| 77 | + "# Set authentication token\n", |
| 78 | + "ngrok.set_auth_token(PYNGROK_TOKEN)\n", |
| 79 | + "\n", |
| 80 | + "# Start the Intugle Streamlit server in the background on port 8501\n", |
| 81 | + "# The `nohup` command ensures it keeps running, and `&` runs it as a background process.\n", |
| 82 | + "!nohup intugle-streamlit &\n", |
| 83 | + "\n", |
| 84 | + "# Start an ngrok tunnel to expose the Streamlit server\n", |
| 85 | + "# This connects to the default Streamlit port (8501)\n", |
| 86 | + "ngrok_tunnel = ngrok.connect(addr='8501', proto='http', bind_tls=True)\n", |
| 87 | + "\n", |
| 88 | + "# Print the public URL to access the app\n", |
| 89 | + "print(' * Tunnel URL:', ngrok_tunnel.public_url)" |
| 90 | + ] |
| 91 | + }, |
| 92 | + { |
| 93 | + "cell_type": "markdown", |
| 94 | + "id": "808123d4", |
| 95 | + "metadata": {}, |
| 96 | + "source": [ |
| 97 | + "## 3. Shut Down the Tunnel\n", |
| 98 | + "\n", |
| 99 | + "When you are finished using the application, it is good practice to close the `ngrok` tunnel to release the resources. The following script will find all active tunnels and disconnect them.\n" |
| 100 | + ] |
| 101 | + }, |
| 102 | + { |
| 103 | + "cell_type": "code", |
| 104 | + "execution_count": null, |
| 105 | + "id": "4fb8abf7", |
| 106 | + "metadata": {}, |
| 107 | + "outputs": [], |
| 108 | + "source": [ |
| 109 | + "# Close all active tunnels\n", |
| 110 | + "from pyngrok import ngrok\n", |
| 111 | + "\n", |
| 112 | + "active_tunnels = ngrok.get_tunnels()\n", |
| 113 | + "for tunnel in active_tunnels:\n", |
| 114 | + " ngrok.disconnect(tunnel.public_url)\n", |
| 115 | + " print(f\"Closed tunnel: {tunnel.public_url}\")\n" |
| 116 | + ] |
| 117 | + } |
| 118 | + ], |
| 119 | + "metadata": { |
| 120 | + "language_info": { |
| 121 | + "name": "python" |
| 122 | + } |
| 123 | + }, |
| 124 | + "nbformat": 4, |
| 125 | + "nbformat_minor": 5 |
| 126 | +} |
0 commit comments