准备

注册Kaggle

注册完后记得验证手机号

注册ngrok

获取ngrok_token

kaggle脚本

拉取kohya_ss并执行创建脚本

1
2
3
4
5
6
7
8
%cd /kaggle/working

!git clone https://github.com/bmaltais/kohya_ss.git

%cd /kaggle/working/kohya_ss

!./setup.sh -n
print("Kohya_SS is done setting up!")

创建文件夹并拷贝数据

1
2
3
4
5
6
7
8
9
10
11
12
13
import os
import shutil

# Create the directories
os.makedirs("/kaggle/working/training-data/img", exist_ok=True)
os.makedirs("/kaggle/working/training-data/my-lora", exist_ok=True)
os.makedirs("/kaggle/working/training-data/log", exist_ok=True)
os.makedirs("/kaggle/working/training-data/config", exist_ok=True)

!rm -r /kaggle/working/training-data/*
# Copy the files
shutil.copytree("/kaggle/input/training/image", f"/kaggle/working/training-data/img")
shutil.copytree("/kaggle/input/training/config", f"/kaggle/working/training-data/config")

安装 pyngrok

1
2
# 这行代码安装 pyngrok
!pip install pyngrok

配置ngrok内网穿透

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#---------------Ngrok---------------------
#ngrok穿透token
#前往https://dashboard.ngrok.com/get-started/your-authtoken 获取
ngrok_token = '2bswgJj**********M5V4' #直接将Token粘贴到这里
# Ngrok近期更新了流量限制,Ngrok每个月有10G流量限制,如果用完可以用临时邮箱再注册一个

# 确保运行这个单元,以便函数被定义
def ngrok_start(port: int, address_name: str, ngrok_token: str, should_run: bool):
if not should_run:
print('Skipping ngrok start')
return
print('Attempting to start ngrok...')
from pyngrok import conf, ngrok
conf.get_default().auth_token = ngrok_token
conf.get_default().monitor_thread = False
ssh_tunnels = ngrok.get_tunnels(conf.get_default())
if len(ssh_tunnels) == 0:
ssh_tunnel = ngrok.connect(port, bind_tls=True)
print(f'{address_name} URL: ' + ssh_tunnel.public_url)
else:
print(f'{address_name} URL: ' + ssh_tunnels[0].public_url)

启动ngrok

1
2
3
# 使用实际的 ngrok token 和正确的端口号
ngrok_token = '2bswgJj**********M5V4'
ngrok_start(7860, 'Gradio', ngrok_token, True)

启动gui

1
!bash gui.sh --share --headless

访问Kohya__ss

回到https://dashboard.ngrok.com/ ,然后选择Cloud Edge > Endpoints然后有一个全新的URL,那个URL就是你的网站,也可以在输出日志里找到.ngrok.io的链接