This repository contains a Python script that automates the setup of an Ollama server on Kaggle, exposing it to the internet using Ngrok . The script installs necessary dependencies, configures Nginx as a reverse proxy, and sets up Ngrok for external access.
Before running this script, ensure you have the following:
- Kaggle Account : You need a Kaggle account to create and run notebooks.
- Ngrok Account : Sign up for a free Ngrok account at https://ngrok.com/ to get your authtoken .
- GPU-enabled Kaggle Notebook : Ensure you're using a GPU-enabled notebook to handle large models efficiently.
- Basic Knowledge of Kaggle Notebooks : Familiarity with Kaggle's interface and how to run code cells in a notebook.
The script performs the following steps:
- Install Dependencies : Installs required packages like
pciutils
,lshw
,pyngrok
, andngrok
. - Set Environment Variables : Configures environment variables for Ollama.
- Install Ollama : Downloads and installs the Ollama server.
- Start Ollama Server : Starts the Ollama server in the background.
- Pull Model : Pulls the specified model (default:
qwen2.5-coder
) from Ollama. - Install and Configure Nginx : Sets up Nginx as a reverse proxy to forward requests to the Ollama server.
- Set Up Ngrok : Exposes the Ollama server to the internet using Ngrok.
- Restart Services : Restarts Nginx and ensures all services are running correctly.
- Go to Kaggle and log in.
- Click on "Create" > "Notebook" to create a new notebook.
- In the notebook settings (gear icon), enable Internet access .
- Ensure the notebook is running on a GPU-enabled environment .
Run the following commands in the first cell of your notebook to install the required dependencies:
bash
-
!apt update
-
!apt install -y pciutils lshw
-
!pip install pyngrok ngrok
- Copy the Python script provided in this repository into a new code cell in your Kaggle notebook.
- Alternatively, you can upload the script file directly to the notebook by clicking the "Add Data" button and selecting the script.
- Execute the script by running the cell containing the code.
- When prompted, enter your Ngrok authtoken (you can find this in your Ngrok dashboard).
Once the script is running, follow these steps:
- Wait for Installation : The script will install dependencies, set up Ollama, and configure Nginx. This may take several minutes.
- Ngrok Tunnel : After Ngrok is set up, the script will display a URL. Click on the link to access your Ollama server externally.
- Access the Server : Use the Ngrok URL to interact with the Ollama server from any device connected to the internet.
-
Timeout Waiting for Ollama Server :
- Ensure you're using a GPU-enabled notebook.
- Increase the timeout value in the
wait_for_ollama_server
function if necessary.
-
Ngrok Authentication Failed :
- Double-check your Ngrok authtoken.
- Ensure you've entered the token correctly when prompted.
-
Nginx Configuration Errors :
-
Verify that the Nginx configuration file (
/etc/nginx/conf.d/ollamasvc.conf
) is correctly written. -
Restart Nginx manually using:
bash
- !sudo /etc/init.d/nginx restart
-
-
Model Pulling Fails :
- Ensure the model name (
qwen2.5-coder
) is correct. - Check your internet connection and retry.
- Ensure the model name (
If you encounter any issues or have suggestions for improvements, feel free to open an issue or submit a pull request. Contributions are welcome!