viyi commited on
Commit
7cd3fa8
1 Parent(s): 9ddfed2

Upload lite-start.ipynb

Browse files
Files changed (1) hide show
  1. lite-start.ipynb +1 -1
lite-start.ipynb CHANGED
@@ -1 +1 @@
1
- {"cells":[{"cell_type":"markdown","metadata":{},"source":["# NovelAi stable-diffusion-webui+api+sdxl\n","---\n","**version: 1.6.0  •  python: 3.10.6  •  torch: 2.0.1+cu118  •  xformers: 0.0.21  •  gradio: 3.41.2**\n","- 发布地址 [kaggle stable-diffusion-webui-novelai](https://www.kaggle.com/code/yiyiooo/stable-diffusion-webui-novelai)\n","- 这是一个用于快速体验ai绘画项目 [stable-diffusion-webui](https://github.com/AUTOMATIC1111/stable-diffusion-webui) 的笔记本,你可以直接启动就能在线体验ai绘图的乐趣。 \n","- kaggle和colab都是AI学习平台,请勿浪费计算资源,如果有需求,可以考虑AutoDL这类租用显卡的平台或者colab付费使用。\n","- 在保持可以免配置直接启动的情况下也提供了很多可自定义的配置,在下方的配置项里,请自行查看。 \n","- 同时也为新人提供了一份基础的帮助文档,包含了一些使用中可能遇到的问题,如果使用过程中有什么疑问,不妨先看看帮助文档。\n","- 如果你需要在此脚本上修改再发布,请随意,但请遵守相关法律法规,文明使用。\n","- 使用时如果遇到问题,尽可能通过帮助文档或者参考已有内容尝试自己解决。\n","- Q群 [816545732](http://qm.qq.com/cgi-bin/qm/qr?_wv=1027&k=OGQydingTPku9M_myV_cscWv6MVaCSde&authKey=RFadQ18FgReFkx7CRs8SNk4vHpxHz%2FD2ojHL3433MehuQOBlnG0hhWFIo8AX%2BFRU&noverify=0&group_code=816545732) ,这是我建的新群,如果有需要,可以进群,其实这个笔记已经非常简洁了,进群大概也不会有啥帮助。\n","- 使用前可以看一下最后的更新日志,可能有功能更新需要注意"]},{"cell_type":"markdown","metadata":{},"source":["## 重要文件列表\n","\n","- **这个列表仅加载一次 且会等待加载完成再开始安装sd**\n","- ```[]```内的是下载文件的目标目录,可以是相对目录也可以是觉得路径\n","- ```[]```的下一行就是文件列表,可以是下载地址、git仓库、文件路径、文件夹路径,且支持通配符\n","- 如果需要对下载的文件重命名,可以在下载链接前面写上文件名后加一个```:```分开文件名和下载地址\n","- 如果需要下载到其他目录,可以使用同样的格式写其他目录"]},{"cell_type":"code","execution_count":null,"metadata":{"trusted":true},"outputs":[],"source":["before_downloading = '''# 这个列表仅加载一次 且会等待加载完成再开始安装sd\n","[extensions] # 插件\n","https://github.com/dtlnor/stable-diffusion-webui-localization-zh_CN.git\n","https://github.com/AlUlkesh/stable-diffusion-webui-images-browser.git\n","https://github.com/DominikDoom/a1111-sd-webui-tagcomplete.git\n","https://github.com/Mikubill/sd-webui-controlnet.git\n","https://github.com/ilian6806/stable-diffusion-webui-state.git\n","https://github.com/pkuliyi2015/multidiffusion-upscaler-for-automatic1111.git\n","https://github.com/Bing-su/adetailer.git\n","https://github.com/zanllp/sd-webui-infinite-image-browsing.git\n","https://github.com/viyiviyi/stable-diffusion-webui-zoomimage.git\n","https://github.com/viyiviyi/prompts-filter.git zz_prompts-filter\n","https://github.com/viyiviyi/sd-encrypt-image.git # 图片加密插件,解决涩图封号问题,需要在参数里设置你的密码开启\n","https://github.com/nonnonstop/sd-webui-3d-open-pose-editor.git\n","https://github.com/jexom/sd-webui-depth-lib.git\n","https://github.com/Elldreth/loopback_scaler.git\n","https://github.com/hnmr293/sd-webui-cutoff.git\n","https://github.com/hako-mikan/sd-webui-lora-block-weight.git\n","https://github.com/viyiviyi/Stable-Diffusion-Webui-Civitai-Helper.git # 修改过的c站助手,下载的缩略图可以被加密插件加密\n","https://github.com/viyiviyi/sd-civitai-browser-plus.git\n","https://github.com/adieyal/sd-dynamic-prompts.git\n","https://github.com/hako-mikan/sd-webui-supermerger.git\n","https://github.com/thisjam/sd-webui-oldsix-prompt.git\n","https://github.com/NoCrypt/sd-fast-pnginfo.git\n","https://github.com/ArtVentureX/sd-webui-agent-scheduler.git\n","https://github.com/continue-revolution/sd-webui-animatediff.git animatediff\n","https://github.com/mcmonkeyprojects/sd-dynamic-thresholding.git\n","\n","# 如果你有模型文件需要在启动前加载,可以写在这个下面对应位置\n","\n","[models/Stable-diffusion] # 大模型列表\n","\n","[models/hypernetworks] # hypernetworks文件列表\n","\n","[models/embeddings] # embeddings文件列表\n","\n","[models/Lora] # Lora文件列表\n","\n","[models/VAE] # VAE文件列表\n","\n","[extensions/sd-webui-controlnet/models] # controlnet插件的模型列表\n","\n","# 通过这个功能安装一个ComfyUI\n","[{install_path}]\n","https://github.com/comfyanonymous/ComfyUI.git ComfyUI\n","\n","[{install_path}/ComfyUI/custom_nodes] # ComfyUI 节点模块\n","https://github.com/viyiviyi/comfyui-encrypt-image.git # 加密插件,安装后就会加密,默认密码123qwe,在utils下增加了一个预览和设置密码的节点\n","https://github.com/ltdrdata/ComfyUI-Manager.git\n","https://github.com/Suzie1/ComfyUI_Comfyroll_CustomNodes.git\n","https://github.com/cubiq/ComfyUI_IPAdapter_plus.git\n","https://github.com/jags111/efficiency-nodes-comfyui.git\n","https://github.com/twri/sdxl_prompt_styler.git\n","https://github.com/ssitu/ComfyUI_UltimateSDUpscale --recursive\n","https://github.com/ltdrdata/ComfyUI-Impact-Pack.git\n","https://github.com/ltdrdata/ComfyUI-Inspire-Pack.git\n","https://github.com/giriss/comfy-image-saver.git\n","https://github.com/Kosinkadink/ComfyUI-AnimateDiff-Evolved.git AnimateDiff\n","https://github.com/SLAPaper/ComfyUI-Image-Selector.git\n","https://github.com/Kosinkadink/ComfyUI-VideoHelperSuite.git\n","https://github.com/Fannovel16/comfyui_controlnet_aux.git\n","https://github.com/mav-rik/facerestore_cf.git\n","https://github.com/FizzleDorf/ComfyUI_FizzNodes.git\n","https://github.com/BadCafeCode/masquerade-nodes-comfyui.git\n","https://github.com/WASasquatch/was-node-suite-comfyui.git\n","https://github.com/YMC-GitHub/ymc-node-suite-comfyui.git\n","https://github.com/coreyryanhanson/ComfyQR.git\n","https://github.com/melMass/comfy_mtb.git\n","https://github.com/sipherxyz/comfyui-art-venture.git\n","https://github.com/cubiq/ComfyUI_essentials.git\n","https://github.com/Gourieff/comfyui-reactor-node.git\n","\n","[{install_path}/ComfyUI/web/extensions] # ComfyUI web插件\n","https://github.com/viyiviyi/comfyui-mobile.git\n","https://github.com/viyiviyi/comfyui-popup-image-prevew.git\n","\n","'''"]},{"cell_type":"markdown","metadata":{},"source":["## 普通文件列表\n","\n","- **这个列表仅加载一次 且不会等待加载完成**\n","- ```[]```内的是下载文件的目标目录,可以是相对目录也可以是觉得路径\n","- ```[]```的下一行就是文件列表,可以是下载地址、git仓库、文件路径、文件夹路径,且支持通配符\n","- 如果需要对下载的文件重命名,可以在下载链接前面写上文件名后加一个```:```分开文件名和下载地址\n","- 如果需要下载到其他目录,可以使用同样的格式写其他目录"]},{"cell_type":"code","execution_count":null,"metadata":{"trusted":true},"outputs":[],"source":["async_downloading='''# 这个列表仅加载一次 且不会等待加载完成\n","[extensions] # 插件 如果你没有使用ngrok或者frpc,请不要把插件放在这里加载,因为这里的文件可能在webui启动后才加载完成\n","\n","[models/ESRGAN]\n","https://huggingface.co/lokCX/4x-Ultrasharp/blob/main/4x-UltraSharp.pth\n","\n","[models/VAE] # VAE文件列表\n","{input_path}/vae-ft-ema-prunedsafetensors/vae-ft-ema-560000-ema-pruned.safetensors\n","{input_path}/vae-ft-ema-prunedsafetensors/vae-ft-mse-840000-ema-pruned.safetensors\n","sdxl_vae.safetensors:https://huggingface.co/madebyollin/sdxl-vae-fp16-fix/resolve/main/sdxl_vae.safetensors?download=true # sdxl模型需要sdxl的vae\n","\n","[models/Stable-diffusion] # 大模型列表\n","# https://civitai.com/api/download/models/293564\n","/kaggle/input/anime-xl/animagineXLV3_v30.safetensors\n","https://huggingface.co/KBlueLeaf/Kohaku-XL-Delta/resolve/main/kohaku-xl-delta-rev1.safetensors?download=true\n","\n","[models/hypernetworks] # hypernetworks文件列表\n","\n","[models/embeddings] # embeddings文件列表\n","\n","[models/Lora] # Lora文件列表\n","https://civitai.com/api/download/models/116970\n","https://civitai.com/api/download/models/117151 # Clothing +/- Adjuster 衣物增/减 LoRA\n","https://civitai.com/api/download/models/62833 # Detail Tweaker LoRA (细节调整LoRA)\n","\n","\n","[extensions/sd-webui-controlnet/models] # controlnet插件的模型列表\n","# https://huggingface.co/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11e_sd15_ip2p_fp16.safetensors\n","# https://huggingface.co/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11e_sd15_shuffle_fp16.safetensors\n","# https://huggingface.co/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11f1e_sd15_tile_fp16.safetensors\n","# https://huggingface.co/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11f1p_sd15_depth_fp16.safetensors\n","https://huggingface.co/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11p_sd15_canny_fp16.safetensors\n","# https://huggingface.co/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11p_sd15_inpaint_fp16.safetensors\n","https://huggingface.co/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11p_sd15_lineart_fp16.safetensors\n","# https://huggingface.co/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11p_sd15_mlsd_fp16.safetensors\n","# https://huggingface.co/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11p_sd15_normalbae_fp16.safetensors\n","https://huggingface.co/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11p_sd15_openpose_fp16.safetensors\n","# https://huggingface.co/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11p_sd15_scribble_fp16.safetensors\n","# https://huggingface.co/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11p_sd15_seg_fp16.safetensors\n","# https://huggingface.co/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11p_sd15_softedge_fp16.safetensors\n","https://huggingface.co/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11p_sd15s2_lineart_anime_fp16.safetensors\n","# https://huggingface.co/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11u_sd15_tile_fp16.safetensors\n","\n","[extensions/animatediff/model] # animatediff 插件基本模型\n","# https://huggingface.co/guoyww/animatediff/resolve/cd71ae134a27ec6008b968d6419952b0c0494cf2/mm_sd_v15_v2.ckpt\n","\n","[models/Lora/animatediff] # animatediff lora模型\n","# https://huggingface.co/guoyww/animatediff/resolve/cd71ae134a27ec6008b968d6419952b0c0494cf2/v2_lora_PanLeft.ckpt\n","'''\n"]},{"cell_type":"markdown","metadata":{},"source":["## 按顺序加载的重要文件列表\n","\n","- **这个列表每次 run all 启动都会加载一次,且一定按照顺序加载后才启动webui**\n","- ```[]```内的是下载文件的目标目录,可以是相对目录也可以是觉得路径\n","- ```[]```的下一行就是文件列表,可以是下载地址、git仓库、文件路径、文件夹路径,且支持通配符\n","- 如果需要对下载的文件重命名,可以在下载链接前面写上文件名后加一个```:```分开文件名和下载地址\n","- 如果需要下载到其他目录,可以使用同样的格式写其他目录"]},{"cell_type":"code","execution_count":null,"metadata":{"trusted":true},"outputs":[],"source":["before_start_sync_downloading = ''' # 这个列表每次 run all 启动都会加载一次,且一定按照顺序加载\n","\n","# 如果你需要每次启动都加载一下文件,可以写在这。(比如测试路径是否正确的时候)\n","\n","[models/Stable-diffusion] # 大模型列表\n","\n","[models/hypernetworks] # hypernetworks文件列表\n","\n","[models/embeddings] # embeddings文件列表\n","\n","[models/Lora] # Lora文件列表\n","\n","[models/VAE] # VAE文件列表\n","\n","[extensions/sd-webui-controlnet/models] # controlnet插件的模型列表\n","\n","'''"]},{"cell_type":"markdown","metadata":{},"source":["## webui 启动参数\n","- 所有的参数都会在启动时传入\n","- 可以在前面加```#```来屏蔽某个参数\n","- 端口参数需要在下一个代码块的```webuiPort```处修改"]},{"cell_type":"code","execution_count":null,"metadata":{"trusted":true},"outputs":[],"source":["sd_start_args='''\n","# --ckpt=mg-Tender.safetensors # 默认模型名称,路径不能包含空格\n","--disable-safe-unpickle \n","--deepdanbooru \n","--no-hashing \n","--no-download-sd-model \n","--administrator\n","--skip-torch-cuda-test \n","--skip-version-check \n","--disable-nan-check\n","--opt-sdp-attention \n","--opt-sdp-no-mem-attention \n","--xformers-flash-attention\n","--xformers\n","--api \n","--listen\n","--lowram\n","#--no-gradio-queue\n","--encrypt-pass=123qwe # 图片加密插件的密码,如果要启用图片加密插件,删除这一行前面的#和将123qwe改成你的密码,也可以不改\n","# --share # 默认的内网穿透在kaggle和colab都已经不可用,请考虑其他方案\n","--disable-console-progressbars\n","--no-half-vae \n","# --no-half #关闭半精度\n","# --enable-console-prompts\n","# --nowebui # 如果只需要api服务,可以开启这个\n","# --api-auth=2333:6666 # api密码\n","# --gradio-auth=2333:6666 # webui密码\n","'''"]},{"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":["# 这个方法内的函数会在所有文件加载完成,准备启动前执行,可以放一些自定义的逻辑功能\n","def on_before_start():\n"," '''这是一个空的函数'''\n"," def get_folder_list(directory:str): \n"," folder_list = [] \n"," for item in os.listdir(directory): \n"," if os.path.isdir(os.path.join(directory, item)): \n"," folder_list.append(item) \n"," return folder_list \n"," # 启动 ComfyUI\n"," def start_comfyui():\n"," !rm -rf {install_path}/ComfyUI/models/checkpoints\n"," !ln -s -r {_install_path}/{_ui_dir_name}/models/Stable-diffusion {install_path}/ComfyUI/models/checkpoints\n"," !rm -rf {install_path}/ComfyUI/models/embeddings\n"," !ln -s -r {_install_path}/{_ui_dir_name}/embeddings {install_path}/ComfyUI/models/embeddings\n"," !rm -rf {install_path}/ComfyUI/models/loras\n"," !ln -s -r {_install_path}/{_ui_dir_name}/models/Lora {install_path}/ComfyUI/models/loras\n"," !rm -rf {install_path}/ComfyUI/models/vae\n"," !ln -s -r {_install_path}/{_ui_dir_name}/models/VAE {install_path}/ComfyUI/models/vae\n"," !rm -rf {install_path}/ComfyUI/models/hypernetworks\n"," !ln -s -r {_install_path}/{_ui_dir_name}/models/hypernetworks {install_path}/ComfyUI/models/hypernetworks\n"," !rm -rf {install_path}/ComfyUI/models/upscale_models\n"," !ln -s -r {_install_path}/{_ui_dir_name}/models/ESRGAN {install_path}/ComfyUI/models/upscale_models\n"," !rm -rf {install_path}/ComfyUI/models/controlnet\n"," !ln -s -r {_install_path}/{_ui_dir_name}/extensions/sd-webui-controlnet/models {install_path}/ComfyUI/models/controlnet\n"," !rm -rf {install_path}/ComfyUI/custom_nodes/AnimateDiff/models\n"," !ln -s -r {_install_path}/{_ui_dir_name}/extensions/animatediff/model {install_path}/ComfyUI/custom_nodes/AnimateDiff/models\n"," !rm -rf {install_path}/ComfyUI/custom_nodes/AnimateDiff/motion_lora\n"," !ln -s -r {_install_path}/{_ui_dir_name}/models/Lora/animatediff {install_path}/ComfyUI/custom_nodes/AnimateDiff/motion_lora\n"," _cwd = os.getcwd()\n"," \n"," def start(device:int):\n"," print(f'启动 comfyui {device}')\n"," %cd {install_path}/ComfyUI \n"," !{_install_path}/{_ui_dir_name}/venv/bin/python3 main.py --force-fp16 --cuda-device={device} --port={8188+device}\n"," %cd {_cwd}\n"," print(f'下载 comfyui 各节点的依赖')\n"," for node in get_folder_list(f'{install_path}/ComfyUI/custom_nodes'):\n"," print(os.path.join(f'{install_path}/ComfyUI/custom_nodes',node))\n"," if Path(os.path.join(f'{install_path}/ComfyUI/custom_nodes',node,'requirements.txt')).exists():\n"," run(f'{_install_path}/{_ui_dir_name}/venv/bin/python3 -s -m pip install -r requirements.txt',cwd=os.path.join(f'{install_path}/ComfyUI/custom_nodes',node))\n"," \n"," print(f'启动 comfyui')\n"," for device in range(torch.cuda.device_count() if _multi_case else 1):\n"," threading.Thread(target = start, daemon=True,args=([device]), name=f'solo_start_comfyui_{device}').start()\n"," \n"," threading.Thread(target = start_comfyui, daemon=True, name='solo_start_comfyui').start()\n"," \n"," # 安装一个文件浏览器 通过在访问地址后加 /fslist/ 访问\n"," def start_filebrower():\n"," !curl -fsSL https://raw.githubusercontent.com/filebrowser/get/master/get.sh | bash\n"," !filebrowser -p 8012 --username admin -b /fslist -r {install_path}\n"," \n"," threading.Thread(target = start_filebrower, daemon=True, name='solo_start_filebrower').start()\n"," ## 下面可以写更多自定义逻辑"]},{"cell_type":"code","execution_count":null,"metadata":{"trusted":true},"outputs":[],"source":["useGooglrDrive = True # 连接到谷歌云盘 在google colab环境才会生效\n","#Ngrok\n","useNgrok=True # 非必填 是否使用ngrok作为公网访问地址\n","#Frpc\n","useFrpc=True # 开启frp将不能启动\n","\n","#可以填写文件路径 或 直接填 token 内容\n","ngrok_config_or_file = '''\n","{input_path}/configs/ngrok_token.txt\n","'''\n","frp_config_or_file = '''\n","{input_path}/configs/frpc_koishi.ini\n","'''\n","frp_ssl_dir = '''\n","{input_path}/configs/koishi_ssl\n","'''\n","\n","# 配置启动参数\n","server_port=7860 # webui 默认端口\n","\n","# 仓库地址 这是修改过界面布局顺序的webui,不定期同步到官方版本\n","# 如果要使用官方版本,改成这个: https://github.com/AUTOMATIC1111/stable-diffusion-webui\n","sd_git_repo='https://github.com/viyiviyi/stable-diffusion-webui.git -b local' \n","# 配置文件,包括webui的设置和UI默认值,如果要自定义,fork这个仓库后修改并把地址替换这个地址\n","sd_config_git_repu = 'https://github.com/viyiviyi/sd-configs.git -b main-yiyiooo'\n","# 设置文件保存路径 当使用谷歌云盘时非常有用\n","setting_file = '{output_path}/configs/config.json'\n","ui_config_file = '{output_path}/configs/ui-config.json'\n","\n","# 这是配置文件夹同步的相关配置\n","# 需要在huggingface创建一个数据集(datasets) 然后把数据集的名称(在页面上有复制的按钮)填到 huggingface_repo \n","# 需要获取 token 填到 huggingface_token 获取的地址是: https://huggingface.co/settings/tokens\n","huggingface_token = '{input_path}/configs/huggingface_token.txt'\n","huggingface_repo = 'viyi/sdwui-log'\n","\n","# 自定义本地反向代理 这些配置将会成为nginx的反向代理配置,用于实现一个穿透访问多个实例\n","# 默认情况下 / 被代理到了webui;/1/ 被代理到了第二个webui\n","proxy_path={\n"," '/cui/':'http://127.0.0.1:8188/',\n"," '/cui2/':'http://127.0.0.1:8189/',\n"," '/fslist/':'http://127.0.0.1:8012/',\n","} # 增加一个comfyui的代理\n","\n","multi_case = True"]},{"cell_type":"code","execution_count":null,"metadata":{"trusted":true},"outputs":[],"source":["link_instead_of_copy = True # 下载或加载Input的文件时是使用链���还是复制的方式加载到目标目录\n","hidden_console_info = True # 是否隐藏大部分的控制台内容"]},{"cell_type":"code","execution_count":null,"metadata":{"trusted":true},"outputs":[],"source":["# 保存当前目录和启动时cd到之前保存的目录,可以减少sdwui-start-new.ipynb文件下载次数\n","import os\n","INIT_WORK_PATH = os.environ['HOME']\n","if os.getenv('INIT_WORK_PATH',''):\n"," INIT_WORK_PATH = os.getenv('INIT_WORK_PATH','')\n","else:\n"," os.environ['INIT_WORK_PATH'] = os.getcwd()\n","%cd {INIT_WORK_PATH}"]},{"cell_type":"code","execution_count":null,"metadata":{"trusted":true},"outputs":[],"source":["reLoad = True\n","# 如果需要重新安装,请注释下面这一行\n","reLoad = False"]},{"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":["import signal \n","import sys\n","\n","def auto_exit(signum,frame):\n"," print('自动结束运行')\n"," signal.alarm(0)\n"," sys.exit(0)\n","\n","signal.signal(signal.SIGALRM, auto_exit)\n","signal.alarm(3*60*60) # 定时关机时间,12小时 x 60分钟 x 60秒 当需要提前关机时可以修改数值"]},{"cell_type":"code","execution_count":null,"metadata":{"trusted":true},"outputs":[],"source":["if not os.path.exists('sdwui-start-util.ipynb'):\n"," !wget https://huggingface.co/viyi/sdwui/resolve/main/sdwui-start-util.ipynb -o log.log\n","%run sdwui-start-util.ipynb"]},{"cell_type":"code","execution_count":null,"metadata":{"trusted":true},"outputs":[],"source":["try:\n"," check_gpu() # 检查是否存在gpu\n"," main()\n"," signal.alarm(0)\n","except KeyboardInterrupt:\n"," stop_solo_threads() # 中断后自动停止后台线程 (有部分功能在后台线程中运行)\n"," signal.alarm(0)"]},{"cell_type":"code","execution_count":null,"metadata":{"trusted":true},"outputs":[],"source":["# 打包收藏文件夹 如果需要可以取消下面两行的注释\n","# zipPath('$install_path/sd_main_dir/log','log')\n","# !mv {output_path}/log.tar {output_path}/log.tar.bak\n","# createOrUpdateDataSet(f'{output_path}/log.tar.bak','sd-webui-log-bak')\n","\n","# 打包 这一行的结果是 压缩一个目录,并放在 output_path: /kaggle/working/ 目录下 名字是训练输出.tar\n","# zipPath('$install_path/sd_main_dir/textual_inversion','训练输出') \n","# zipPath('$install_path/sd_main_dir/outputs','outputs')\n","\n","# 打包venv并上传到数据集\n","# zipPath('$install_path/sd_main_dir/venv','venv')\n","# !mv {output_path}/venv.tar /kaggle/working/venv.tar.bak\n","# createOrUpdateDataSet('/kaggle/working/venv.tar.bak','sd-webui-venv')\n","\n","# 打包命令参考,--exclude 可以排除不需要打包的目录\n","# !tar -cf $output_path/webui.tar.bak --exclude=venv --exclude=extensions -C /sd_main_dir/ ."]}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.10.7"}},"nbformat":4,"nbformat_minor":4}
 
1
+ {"cells":[{"cell_type":"markdown","metadata":{},"source":["# NovelAi stable-diffusion-webui+api+sdxl\n","---\n","**version: 1.6.0  •  python: 3.10.6  •  torch: 2.0.1+cu118  •  xformers: 0.0.21  •  gradio: 3.41.2**\n","- 发布地址 [kaggle stable-diffusion-webui-novelai](https://www.kaggle.com/code/yiyiooo/stable-diffusion-webui-novelai)\n","- 这是一个用于快速体验ai绘画项目 [stable-diffusion-webui](https://github.com/AUTOMATIC1111/stable-diffusion-webui) 的笔记本,你可以直接启动就能在线体验ai绘图的乐趣。 \n","- kaggle和colab都是AI学习平台,请勿浪费计算资源,如果有需求,可以考虑AutoDL这类租用显卡的平台或者colab付费使用。\n","- 在保持可以免配置直接启动的情况下也提供了很多可自定义的配置,在下方的配置项里,请自行查看。 \n","- 同时也为新人提供了一份基础的帮助文档,包含了一些使用中可能遇到的问题,如果使用过程中有什么疑问,不妨先看看帮助文档。\n","- 如果你需要在此脚本上修改再发布,请随意,但请遵守相关法律法规,文明使用。\n","- 使用时如果遇到问题,尽可能通过帮助文档或者参考已有内容尝试自己解决。\n","- Q群 [816545732](http://qm.qq.com/cgi-bin/qm/qr?_wv=1027&k=OGQydingTPku9M_myV_cscWv6MVaCSde&authKey=RFadQ18FgReFkx7CRs8SNk4vHpxHz%2FD2ojHL3433MehuQOBlnG0hhWFIo8AX%2BFRU&noverify=0&group_code=816545732) ,这是我建的新群,如果有需要,可以进群,其实这个笔记已经非常简洁了,进群大概也不会有啥帮助。\n","- 使用前可以看一下最后的更新日志,可能有功能更新需要注意"]},{"cell_type":"markdown","metadata":{},"source":["## 重要文件列表\n","\n","- **这个列表仅加载一次 且会等待加载完成再开始安装sd**\n","- ```[]```内的是下载文件的目标目录,可以是相对目录也可��是觉得路径\n","- ```[]```的下一行就是文件列表,可以是下载地址、git仓库、文件路径、文件夹路径,且支持通配符\n","- 如果需要对下载的文件重命名,可以在下载链接前面写上文件名后加一个```:```分开文件名和下载地址\n","- 如果需要下载到其他目录,可以使用同样的格式写其他目录"]},{"cell_type":"code","execution_count":null,"metadata":{"trusted":true},"outputs":[],"source":["before_downloading = '''# 这个列表仅加载一次 且会等待加载完成再开始安装sd\n","[extensions] # 插件\n","https://github.com/dtlnor/stable-diffusion-webui-localization-zh_CN.git\n","https://github.com/AlUlkesh/stable-diffusion-webui-images-browser.git\n","https://github.com/DominikDoom/a1111-sd-webui-tagcomplete.git\n","https://github.com/Mikubill/sd-webui-controlnet.git\n","https://github.com/ilian6806/stable-diffusion-webui-state.git\n","https://github.com/pkuliyi2015/multidiffusion-upscaler-for-automatic1111.git\n","https://github.com/Bing-su/adetailer.git\n","https://github.com/zanllp/sd-webui-infinite-image-browsing.git\n","https://github.com/viyiviyi/stable-diffusion-webui-zoomimage.git\n","https://github.com/viyiviyi/prompts-filter.git zz_prompts-filter\n","https://github.com/viyiviyi/sd-encrypt-image.git # 图片加密插件,解决涩图封号问题,需要在参数里设置你的密码开启\n","https://github.com/nonnonstop/sd-webui-3d-open-pose-editor.git\n","https://github.com/jexom/sd-webui-depth-lib.git\n","https://github.com/Elldreth/loopback_scaler.git\n","https://github.com/hnmr293/sd-webui-cutoff.git\n","https://github.com/hako-mikan/sd-webui-lora-block-weight.git\n","https://github.com/viyiviyi/Stable-Diffusion-Webui-Civitai-Helper.git # 修改过的c站助手,下载的缩略图可以被加密插件加密\n","https://github.com/viyiviyi/sd-civitai-browser-plus.git\n","https://github.com/adieyal/sd-dynamic-prompts.git\n","https://github.com/hako-mikan/sd-webui-supermerger.git\n","https://github.com/thisjam/sd-webui-oldsix-prompt.git\n","https://github.com/NoCrypt/sd-fast-pnginfo.git\n","https://github.com/ArtVentureX/sd-webui-agent-scheduler.git\n","https://github.com/continue-revolution/sd-webui-animatediff.git animatediff\n","https://github.com/mcmonkeyprojects/sd-dynamic-thresholding.git\n","\n","# 如果你有模型文件需要在启动前加载,可以写在这个下面对应位置\n","\n","[models/Stable-diffusion] # 大模型列表\n","\n","[models/hypernetworks] # hypernetworks文件列表\n","\n","[models/embeddings] # embeddings文件列表\n","\n","[models/Lora] # Lora文件列表\n","\n","[models/VAE] # VAE文件列表\n","\n","[extensions/sd-webui-controlnet/models] # controlnet插件的模型列表\n","\n","# 通过这个功能安装一个ComfyUI\n","[{install_path}]\n","https://github.com/comfyanonymous/ComfyUI.git ComfyUI\n","\n","[{install_path}/ComfyUI/custom_nodes] # ComfyUI 节点模块\n","https://github.com/viyiviyi/comfyui-encrypt-image.git # 加密插件,安装后就会加密,默认密码123qwe,在utils下增加了一个预览和设置密码的节点\n","https://github.com/ltdrdata/ComfyUI-Manager.git\n","https://github.com/Suzie1/ComfyUI_Comfyroll_CustomNodes.git\n","https://github.com/cubiq/ComfyUI_IPAdapter_plus.git\n","https://github.com/jags111/efficiency-nodes-comfyui.git\n","https://github.com/twri/sdxl_prompt_styler.git\n","https://github.com/ssitu/ComfyUI_UltimateSDUpscale --recursive\n","https://github.com/ltdrdata/ComfyUI-Impact-Pack.git\n","https://github.com/ltdrdata/ComfyUI-Inspire-Pack.git\n","https://github.com/giriss/comfy-image-saver.git\n","https://github.com/Kosinkadink/ComfyUI-AnimateDiff-Evolved.git AnimateDiff\n","https://github.com/SLAPaper/ComfyUI-Image-Selector.git\n","https://github.com/Kosinkadink/ComfyUI-VideoHelperSuite.git\n","https://github.com/Fannovel16/comfyui_controlnet_aux.git\n","https://github.com/mav-rik/facerestore_cf.git\n","https://github.com/FizzleDorf/ComfyUI_FizzNodes.git\n","https://github.com/BadCafeCode/masquerade-nodes-comfyui.git\n","https://github.com/WASasquatch/was-node-suite-comfyui.git\n","https://github.com/YMC-GitHub/ymc-node-suite-comfyui.git\n","https://github.com/coreyryanhanson/ComfyQR.git\n","https://github.com/melMass/comfy_mtb.git\n","https://github.com/sipherxyz/comfyui-art-venture.git\n","https://github.com/cubiq/ComfyUI_essentials.git\n","https://github.com/Gourieff/comfyui-reactor-node.git\n","\n","[{install_path}/ComfyUI/web/extensions] # ComfyUI web插件\n","https://github.com/viyiviyi/comfyui-mobile.git\n","https://github.com/viyiviyi/comfyui-popup-image-prevew.git\n","\n","'''"]},{"cell_type":"markdown","metadata":{},"source":["## 普通文件列表\n","\n","- **这个列表仅加载一次 且不会等待加载完成**\n","- ```[]```内的是下载文件的目标目录,可以是相对目录也可以是觉得路径\n","- ```[]```的下一行就是文件列表,可以是下载地址、git仓库、文件���径、文件夹路径,且支持通配符\n","- 如果需要对下载的文件重命名,可以在下载链接前面写上文件名后加一个```:```分开文件名和下载地址\n","- 如果需要下载到其他目录,可以使用同样的格式写其他目录"]},{"cell_type":"code","execution_count":null,"metadata":{"trusted":true},"outputs":[],"source":["async_downloading='''# 这个列表仅加载一次 且不会等待加载完成\n","[extensions] # 插件 如果你没有使用ngrok或者frpc,请不要把插件放在这里加载,因为这里的文件可能在webui启动后才加载完成\n","\n","[models/ESRGAN]\n","https://huggingface.co/lokCX/4x-Ultrasharp/blob/main/4x-UltraSharp.pth\n","\n","[models/VAE] # VAE文件列表\n","{input_path}/vae-ft-ema-prunedsafetensors/vae-ft-ema-560000-ema-pruned.safetensors\n","{input_path}/vae-ft-ema-prunedsafetensors/vae-ft-mse-840000-ema-pruned.safetensors\n","sdxl_vae.safetensors:https://huggingface.co/madebyollin/sdxl-vae-fp16-fix/resolve/main/sdxl_vae.safetensors?download=true # sdxl模型需要sdxl的vae\n","\n","[models/Stable-diffusion] # 大模型列表\n","# https://civitai.com/api/download/models/293564\n","/kaggle/input/anime-xl/animagineXLV3_v30.safetensors\n","/kaggle/input/kohakuxl/kohaku-xl-delta-rev.safetensors\n","\n","[models/hypernetworks] # hypernetworks文件列表\n","\n","[models/embeddings] # embeddings文件列表\n","\n","[models/Lora] # Lora文件列表\n","https://civitai.com/api/download/models/116970\n","https://civitai.com/api/download/models/117151 # Clothing +/- Adjuster 衣物增/减 LoRA\n","https://civitai.com/api/download/models/62833 # Detail Tweaker LoRA (细节调整LoRA)\n","\n","\n","[extensions/sd-webui-controlnet/models] # controlnet插件的模型列表\n","# https://huggingface.co/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11e_sd15_ip2p_fp16.safetensors\n","# https://huggingface.co/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11e_sd15_shuffle_fp16.safetensors\n","# https://huggingface.co/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11f1e_sd15_tile_fp16.safetensors\n","# https://huggingface.co/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11f1p_sd15_depth_fp16.safetensors\n","https://huggingface.co/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11p_sd15_canny_fp16.safetensors\n","# https://huggingface.co/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11p_sd15_inpaint_fp16.safetensors\n","https://huggingface.co/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11p_sd15_lineart_fp16.safetensors\n","# https://huggingface.co/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11p_sd15_mlsd_fp16.safetensors\n","# https://huggingface.co/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11p_sd15_normalbae_fp16.safetensors\n","https://huggingface.co/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11p_sd15_openpose_fp16.safetensors\n","# https://huggingface.co/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11p_sd15_scribble_fp16.safetensors\n","# https://huggingface.co/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11p_sd15_seg_fp16.safetensors\n","# https://huggingface.co/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11p_sd15_softedge_fp16.safetensors\n","https://huggingface.co/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11p_sd15s2_lineart_anime_fp16.safetensors\n","# https://huggingface.co/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11u_sd15_tile_fp16.safetensors\n","\n","[extensions/animatediff/model] # animatediff 插件基本模型\n","# https://huggingface.co/guoyww/animatediff/resolve/cd71ae134a27ec6008b968d6419952b0c0494cf2/mm_sd_v15_v2.ckpt\n","\n","[models/Lora/animatediff] # animatediff lora模型\n","# https://huggingface.co/guoyww/animatediff/resolve/cd71ae134a27ec6008b968d6419952b0c0494cf2/v2_lora_PanLeft.ckpt\n","'''\n"]},{"cell_type":"markdown","metadata":{},"source":["## 按顺序加载的重要文件列表\n","\n","- **这个列表每次 run all 启动都会加载一次,且一定按照顺序加载后才启动webui**\n","- ```[]```内的是下载文件的目标目录,可以是相对目录也可以是觉得路径\n","- ```[]```的下一行就是文件列表,可以是下载地址、git仓库、文件路径、文件夹路径,且支持通配符\n","- 如果需要对下载的文件重命名,可以在下载链接前面写上文件名后加一个```:```分开文件名和下载地址\n","- 如果需要下载到其他目录,可以使用同样的格式写其他目录"]},{"cell_type":"code","execution_count":null,"metadata":{"trusted":true},"outputs":[],"source":["before_start_sync_downloading = ''' # 这个列表每次 run all 启动都会加载一次,且一定按���顺序加载\n","\n","# 如果你需要每次启动都加载一下文件,可以写在这。(比如测试路径是否正确的时候)\n","\n","[models/Stable-diffusion] # 大模型列表\n","\n","[models/hypernetworks] # hypernetworks文件列表\n","\n","[models/embeddings] # embeddings文件列表\n","\n","[models/Lora] # Lora文件列表\n","\n","[models/VAE] # VAE文件列表\n","\n","[extensions/sd-webui-controlnet/models] # controlnet插件的模型列表\n","\n","'''"]},{"cell_type":"markdown","metadata":{},"source":["## webui 启动参数\n","- 所有的参数都会在启动时传入\n","- 可以在前面加```#```来屏蔽某个参数\n","- 端口参数需要在下一个代码块的```webuiPort```处修改"]},{"cell_type":"code","execution_count":null,"metadata":{"trusted":true},"outputs":[],"source":["sd_start_args='''\n","# --ckpt=mg-Tender.safetensors # 默认模型名称,路径不能包含空格\n","--disable-safe-unpickle \n","--deepdanbooru \n","--no-hashing \n","--no-download-sd-model \n","--administrator\n","--skip-torch-cuda-test \n","--skip-version-check \n","--disable-nan-check\n","--opt-sdp-attention \n","--opt-sdp-no-mem-attention \n","--xformers-flash-attention\n","--xformers\n","--api \n","--listen\n","--lowram\n","#--no-gradio-queue\n","--encrypt-pass=123qwe # 图片加密插件的密码,如果要启用图片加密插件,删除这一行前面的#和将123qwe改成你的密码,也可以不改\n","# --share # 默认的内网穿透在kaggle和colab都已经不可用,请考虑其他方案\n","--disable-console-progressbars\n","--no-half-vae \n","# --no-half #关闭半精度\n","# --enable-console-prompts\n","# --nowebui # 如果只需要api服务,可以开启这个\n","# --api-auth=2333:6666 # api密码\n","# --gradio-auth=2333:6666 # webui密码\n","'''"]},{"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":["# 这个方法内的函数会在所有文件加载完成,准备启动前执行,可以放一些自定义的逻辑功能\n","def on_before_start():\n"," '''这是一个空的函数'''\n"," def get_folder_list(directory:str): \n"," folder_list = [] \n"," for item in os.listdir(directory): \n"," if os.path.isdir(os.path.join(directory, item)): \n"," folder_list.append(item) \n"," return folder_list \n"," # 启动 ComfyUI\n"," def start_comfyui():\n"," !rm -rf {install_path}/ComfyUI/models/checkpoints\n"," !ln -s -r {_install_path}/{_ui_dir_name}/models/Stable-diffusion {install_path}/ComfyUI/models/checkpoints\n"," !rm -rf {install_path}/ComfyUI/models/embeddings\n"," !ln -s -r {_install_path}/{_ui_dir_name}/embeddings {install_path}/ComfyUI/models/embeddings\n"," !rm -rf {install_path}/ComfyUI/models/loras\n"," !ln -s -r {_install_path}/{_ui_dir_name}/models/Lora {install_path}/ComfyUI/models/loras\n"," !rm -rf {install_path}/ComfyUI/models/vae\n"," !ln -s -r {_install_path}/{_ui_dir_name}/models/VAE {install_path}/ComfyUI/models/vae\n"," !rm -rf {install_path}/ComfyUI/models/hypernetworks\n"," !ln -s -r {_install_path}/{_ui_dir_name}/models/hypernetworks {install_path}/ComfyUI/models/hypernetworks\n"," !rm -rf {install_path}/ComfyUI/models/upscale_models\n"," !ln -s -r {_install_path}/{_ui_dir_name}/models/ESRGAN {install_path}/ComfyUI/models/upscale_models\n"," !rm -rf {install_path}/ComfyUI/models/controlnet\n"," !ln -s -r {_install_path}/{_ui_dir_name}/extensions/sd-webui-controlnet/models {install_path}/ComfyUI/models/controlnet\n"," !rm -rf {install_path}/ComfyUI/custom_nodes/AnimateDiff/models\n"," !ln -s -r {_install_path}/{_ui_dir_name}/extensions/animatediff/model {install_path}/ComfyUI/custom_nodes/AnimateDiff/models\n"," !rm -rf {install_path}/ComfyUI/custom_nodes/AnimateDiff/motion_lora\n"," !ln -s -r {_install_path}/{_ui_dir_name}/models/Lora/animatediff {install_path}/ComfyUI/custom_nodes/AnimateDiff/motion_lora\n"," _cwd = os.getcwd()\n"," \n"," def start(device:int):\n"," print(f'启动 comfyui {device}')\n"," %cd {install_path}/ComfyUI \n"," !{_install_path}/{_ui_dir_name}/venv/bin/python3 main.py --force-fp16 --cuda-device={device} --port={8188+device}\n"," %cd {_cwd}\n"," print(f'下载 comfyui 各节点的依赖')\n"," for node in get_folder_list(f'{install_path}/ComfyUI/custom_nodes'):\n"," print(os.path.join(f'{install_path}/ComfyUI/custom_nodes',node))\n"," if Path(os.path.join(f'{install_path}/ComfyUI/custom_nodes',node,'requirements.txt')).exists():\n"," run(f'{_install_path}/{_ui_dir_name}/venv/bin/python3 -s -m pip install -r requirements.txt',cwd=os.path.join(f'{install_path}/ComfyUI/custom_nodes',node))\n"," \n"," print(f'启动 comfyui')\n"," for device in range(torch.cuda.device_count() if _multi_case else 1):\n"," threading.Thread(target = start, daemon=True,args=([device]), name=f'solo_start_comfyui_{device}').start()\n"," \n"," threading.Thread(target = start_comfyui, daemon=True, name='solo_start_comfyui').start()\n"," \n"," # 安装一个文件浏览器 通过在访问地址后加 /fslist/ 访问\n"," def start_filebrower():\n"," !curl -fsSL https://raw.githubusercontent.com/filebrowser/get/master/get.sh | bash\n"," !filebrowser -p 8012 --username admin -b /fslist -r {install_path}\n"," \n"," threading.Thread(target = start_filebrower, daemon=True, name='solo_start_filebrower').start()\n"," ## 下面可以写更多自定义逻辑"]},{"cell_type":"code","execution_count":null,"metadata":{"trusted":true},"outputs":[],"source":["useGooglrDrive = True # 连接到谷歌云盘 在google colab环境才会生效\n","#Ngrok\n","useNgrok=True # 非必填 是否使用ngrok作为公网访问地址\n","#Frpc\n","useFrpc=True # 开启frp将不能启动\n","\n","#可以填写文件路径 或 直接填 token 内容\n","ngrok_config_or_file = '''\n","{input_path}/configs/ngrok_token.txt\n","'''\n","frp_config_or_file = '''\n","{input_path}/configs/frpc_koishi.ini\n","'''\n","frp_ssl_dir = '''\n","{input_path}/configs/koishi_ssl\n","'''\n","\n","# 配置启动参数\n","server_port=7860 # webui 默认端口\n","\n","# 仓库地址 这是修改过界面布局顺序的webui,不定期同步到官方版本\n","# 如果要使用官方版本,改成这个: https://github.com/AUTOMATIC1111/stable-diffusion-webui\n","sd_git_repo='https://github.com/viyiviyi/stable-diffusion-webui.git -b local' \n","# 配置文件,包括webui的设置和UI默认值,如果要自定义,fork这个仓库后修改并把地址替换这个地址\n","sd_config_git_repu = 'https://github.com/viyiviyi/sd-configs.git -b main-yiyiooo'\n","# 设置文件保存路径 当使用谷歌云盘时非常有用\n","setting_file = '{output_path}/configs/config.json'\n","ui_config_file = '{output_path}/configs/ui-config.json'\n","\n","# 这是配置文件夹同步的相关配置\n","# 需要在huggingface创建一个数据集(datasets) 然后把数据集的名称(在页面上有复制的按钮)填到 huggingface_repo \n","# 需要获取 token 填到 huggingface_token 获取的地址是: https://huggingface.co/settings/tokens\n","huggingface_token = '{input_path}/configs/huggingface_token.txt'\n","huggingface_repo = 'viyi/sdwui-log'\n","\n","# 自定义本地反向代理 这些配置将会成为nginx的反向代理配置,用于实现一个穿透访问多个实例\n","# 默认情况下 / 被代理到了webui;/1/ 被代理到了第二个webui\n","proxy_path={\n"," '/cui/':'http://127.0.0.1:8188/',\n"," '/cui2/':'http://127.0.0.1:8189/',\n"," '/fslist/':'http://127.0.0.1:8012/',\n","} # 增加一个comfyui的代理\n","\n","multi_case = True"]},{"cell_type":"code","execution_count":null,"metadata":{"trusted":true},"outputs":[],"source":["link_instead_of_copy = True # 下载或加载Input的文件时是使用链接还是复制的方式加载到目标目录\n","hidden_console_info = True # 是否隐藏大部分的控制台内容"]},{"cell_type":"code","execution_count":null,"metadata":{"trusted":true},"outputs":[],"source":["# 保存当前目录和启动时cd到之前保存的目录,可以减少sdwui-start-new.ipynb文件下载次数\n","import os\n","INIT_WORK_PATH = os.environ['HOME']\n","if os.getenv('INIT_WORK_PATH',''):\n"," INIT_WORK_PATH = os.getenv('INIT_WORK_PATH','')\n","else:\n"," os.environ['INIT_WORK_PATH'] = os.getcwd()\n","%cd {INIT_WORK_PATH}"]},{"cell_type":"code","execution_count":null,"metadata":{"trusted":true},"outputs":[],"source":["reLoad = True\n","# 如果需要重新安装,请注释下面这一行\n","reLoad = False"]},{"cell_type":"code","execution_count":null,"metadata":{},"outputs":[],"source":["import signal \n","import sys\n","\n","def auto_exit(signum,frame):\n"," print('自动结束运行')\n"," signal.alarm(0)\n"," sys.exit(0)\n","\n","signal.signal(signal.SIGALRM, auto_exit)\n","signal.alarm(3*60*60) # 定时关机时间,12小时 x 60分钟 x 60秒 当需要提前关机时可以修改数值"]},{"cell_type":"code","execution_count":null,"metadata":{"trusted":true},"outputs":[],"source":["if not os.path.exists('sdwui-start-util.ipynb'):\n"," !wget https://huggingface.co/viyi/sdwui/resolve/main/sdwui-start-util.ipynb -o log.log\n","%run sdwui-start-util.ipynb"]},{"cell_type":"code","execution_count":null,"metadata":{"trusted":true},"outputs":[],"source":["try:\n"," check_gpu() # 检查是否存在gpu\n"," main()\n"," signal.alarm(0)\n","except KeyboardInterrupt:\n"," stop_solo_threads() # 中断后自动停止后台线程 (有部分功能在后台线程中运行)\n"," signal.alarm(0)"]},{"cell_type":"code","execution_count":null,"metadata":{"trusted":true},"outputs":[],"source":["# 打包收藏文件夹 如果需要可以取消下面两行的注释\n","# zipPath('$install_path/sd_main_dir/log','log')\n","# !mv {output_path}/log.tar {output_path}/log.tar.bak\n","# createOrUpdateDataSet(f'{output_path}/log.tar.bak','sd-webui-log-bak')\n","\n","# 打包 这一行的结果是 压缩一个目录,并放在 output_path: /kaggle/working/ 目录下 名字是训练输出.tar\n","# zipPath('$install_path/sd_main_dir/textual_inversion','训练输出') \n","# zipPath('$install_path/sd_main_dir/outputs','outputs')\n","\n","# 打包venv并上传到数据集\n","# zipPath('$install_path/sd_main_dir/venv','venv')\n","# !mv {output_path}/venv.tar /kaggle/working/venv.tar.bak\n","# createOrUpdateDataSet('/kaggle/working/venv.tar.bak','sd-webui-venv')\n","\n","# 打包命令参考,--exclude 可以排除不需要打包的目录\n","# !tar -cf $output_path/webui.tar.bak --exclude=venv --exclude=extensions -C /sd_main_dir/ ."]}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.10.7"}},"nbformat":4,"nbformat_minor":4}