刘耀文

刘耀文

java开发者
github

Use Kaggle as an HTTP server deployment service 😂

Just learned about Kaggle. It offers 30 hours of free GPU computing power per week, but it uses jupyter notebook for its services. I'm not used to using notebooks for Python environments. I feel that it's more suitable for quickly implementing ideas using single-file code. For projects with many layers of engineering code, there is a sense of code separation. So I want to try if I can SSH into it.

Feasible Solution#

Use ngrok to expose the SSH server in Kaggle. The following is the notebook cell code:

# 1. Install and configure ngrok
!pip install pyngrok
from pyngrok import ngrok

# Set ngrok authentication token
ngrok.set_auth_token("your_auth_token")

# 2. Start SSH service
!DEBIAN_FRONTEND=noninteractive apt-get install -y openssh-server
!mkdir -p /var/run/sshd

# Configure SSH service to allow root login and enable password authentication
!echo "root:your_password" | chpasswd
!echo 'PermitRootLogin yes' >> /etc/ssh/sshd_config
!echo 'PasswordAuthentication yes' >> /etc/ssh/sshd_config
!service ssh start

# 3. Use ngrok to expose the SSH port
ssh_tunnel = ngrok.connect(22, "tcp")
print("SSH Tunnel:", ssh_tunnel.public_url)

# 4. Output the local SSH connection command
ssh_host, ssh_port = ssh_tunnel.public_url.replace("tcp://", "").split(":")
print(f"Use the following command to connect via SSH:\nssh root@{ssh_host} -p {ssh_port}")

Limitations

It was found that ngrok requires binding a credit card or debit card to use TCP ports, but it seems that cards from mainland China cannot be verified.

Using an HTTP proxy service

Expose the HTTP service on Kaggle.

%cd ../../
%cd kaggle
%ls
%cp -r input/testfilebox /my
%cd /my
%cd fcb-fronted
!npm  install
!npm run build
%cd ../
%pip install -r requirements.txt


# Set ngrok authentication token
ngrok.set_auth_token("your token")

# 2. Use ngrok to expose the HTTP port of the FastAPI service
http_tunnel = ngrok.connect(12345, "http")
print("Public URL:", http_tunnel.public_url)

!python main.py

This article is synchronized and updated to xLog by Mix Space.
The original link is https://me.liuyaowen.cn/posts//fun/20240901and1


Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.