File size: 21,829 Bytes
2dee4dc
1
2
{"cells":[{"cell_type":"markdown","metadata":{},"source":["# NovelAi stable-diffusion-webui+api\n","---\n","**env版本: torch: 2.0+cu117  •  xformers: 0.0.19**\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","- 在保持可以免配置直接启动的情况下也提供了很多可自定义的配置,在下方的配置项里,请自行查看。 \n","- 同时也为新人提供了一份基础的帮助文档,包含了一些使用中可能遇到的问题,如果使用过程中有什么疑问,不妨先看看帮助文档。\n","- 如果你需要在此脚本上修改再发布,请随意,但请遵守相关法律法规,文明使用。\n","- 交流群632428790 这是 [qq2575044704](https://www.kaggle.com/qq2575044704) 的群,感谢他为这个笔记做了一些宣传。\n"]},{"cell_type":"code","execution_count":null,"metadata":{"trusted":true},"outputs":[],"source":["# 文件列表 一行一个 可以填文件 文件夹 和下载地址,如果需要自定义文件名,在url前写上文件名加:\n","重要文件列表 = '''# 这个列表仅加载一次 且会等待加载完成\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/KohakuBlueleaf/a1111-sd-webui-lycoris.git\n","https://github.com/LianZiZhou/sd-webui-pixink-console.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/civitai/sd_civitai_extension.git\n","https://github.com/zanllp/sd-webui-infinite-image-browsing.git\n","https://github.com/viyiviyi/stable-diffusion-webui-zoomimage.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/LyCORIS]                         # LyCORIS文件列表\n","\n","[models/VAE]                             # VAE文件列表\n","\n","[extensions/sd-webui-controlnet/models] # controlnet插件的模型列表\n","\n","'''\n","\n","普通文件列表='''# 这个列表仅加载一次 且不会等待加载完成\n","[extensions] # 插件 如果你没有使用ngrok或者frpc,请不要把插件放在这里加载,因为这里的文件可能在webui启动后才加载完成\n","\n","[models/Stable-diffusion]                # 大模型列表\n","mg-Tender.safetensors:https://civitai.com/api/download/models/75587\n","\n","[models/hypernetworks]                   # hypernetworks文件列表\n","\n","[models/embeddings]                      # embeddings文件列表\n","\n","[models/Lora]                            # Lora文件列表\n","Genshin_Impact_all-in-one.safetensors:https://civitai.com/api/download/models/116970\n","\n","[models/LyCORIS]                         # LyCORIS文件列表\n","\n","\n","[models/VAE]                             # VAE文件列表\n","https://huggingface.co/stabilityai/sd-vae-ft-ema-original/resolve/main/vae-ft-ema-560000-ema-pruned.safetensors\n","https://huggingface.co/stabilityai/sd-vae-ft-mse-original/resolve/main/vae-ft-mse-840000-ema-pruned.safetensors\n","https://huggingface.co/WarriorMama777/OrangeMixs/resolve/main/VAEs/orangemix.vae.pt\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","\n","按顺序加载的重要文件列表 = ''' # 这个列表每次 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/LyCORIS]                         # LyCORIS文件列表\n","\n","[models/VAE]                             # VAE文件列表\n","\n","[extensions/sd-webui-controlnet/models] # controlnet插件的模型列表\n","\n","'''\n","\n","参数列表='''\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","--share\n","--disable-console-progressbars\n","--no-half\n","# --enable-console-prompts\n","# --nowebui\n","# --no-half-vae\n","# --api-auth=2333:6666 --gradio-auth=2333:6666\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","#文件或直接填配置\n","ngrok配置或文件地址='''\n","{input_path}/configs/ngrok_token.txt\n","'''\n","frp配置文件或配置='''\n","{input_path}/configs/frpc_koishi.ini\n","'''\n","frpSSL文件='''\n","{input_path}/configs/koishi_ssl\n","'''\n","\n","# 配置启动参数\n","webuiPort=7860 # webui默认端口\n","\n","# 仓库地址 这是修改过界面布局顺序的webui,不定期同步到官方版本\n","# 如果要使用官方版本,改成这个: https://github.com/AUTOMATIC1111/stable-diffusion-webui\n","webui_git_repo='https://github.com/viyiviyi/stable-diffusion-webui.git -b local' \n","# 配置文件,包括webui的设置和UI默认值,如果要自定义,fork这个仓库后修改并把地址替换这个地址\n","webui_config_git_repu = 'https://github.com/viyiviyi/sd-configs.git'\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"]},{"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":["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":{"trusted":true},"outputs":[],"source":["if not os.path.exists('sdwui-start-new.ipynb'):\n","    !wget https://huggingface.co/viyi/sdwui/resolve/main/sdwui-start-new.ipynb -o log.log\n","%run sdwui-start-new.ipynb"]},{"cell_type":"code","execution_count":null,"metadata":{"trusted":true},"outputs":[],"source":["\n","# 打包收藏文件夹 如果需要可以取消下面两行的注释\n","# zipPath('$install_path/stable-diffusion-webui/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/stable-diffusion-webui/textual_inversion','训练输出') \n","# zipPath('$install_path/stable-diffusion-webui/outputs','outputs')\n","# zipPath('$install_path/stable-diffusion-webui/venv','venv')\n","# !mv {output_path}/venv.tar /kaggle/working/venv.tar.bak\n","# createOrUpdateDataSet('/kaggle/working/venv.tar.bak','sd-webui-venv')\n","# !tar -cf $output_path/webui.tar.bak --exclude=venv --exclude=extensions -C /kaggle/stable-diffusion-webui/ ."]},{"cell_type":"markdown","metadata":{},"source":["# 使用帮助\n","---\n","**代码块不能删除也不能调换顺序,如果出现变量未定义,请检查是否按顺序执行了代码块**\n","\n","---\n","\n","## kaggle账号\n","- 注册账号需要手机号,国内手机号也行,如果点击注册后没反应,估计是需要梯子,用于人机验证\n","- 注册后点此笔记的 **Copy & Edit** 按钮就进到编辑界面\n","\n","## 准备工作\n","1. 右侧面板 **Settings/ACCELERATOR** 需要选择GPU **T4x2**出图更快,且会自动开启两个webui\n","2. 右侧面板 **Settings/LANGUAGE** 需要选择Python\n","2. 右侧面板 **Settings/PERSISTENCE** 建议选择 Files only **作用是保存Outpot目录内的文件**\n","3. 右侧面板 **Settings/ENVIRONMENT** 建议不改这个配置,使用当前默认值就行\n","4. 右侧面板 **Settings/INTERNET** 需要打开 用于联网,没网跑不起来的啊\n","\n","## 启动\n","#### 启动方式一  **直接点击页面上边的 RunAll**\n","- 在没有关闭电源的情况下,后几次点击RunAll的输出在页面上端 (其实没有必要了,之前不知道代码块可以收起,很烦滚动到页面底端才能看见输出)\n","- 手机端可能会出现页面上边的工具栏不显示的情况,左侧菜单按钮里也有相关的操作\n","- 长时间不操作页面会导致脚本停止 (应该是40分钟吧)\n","\n","#### 启动方式二  **使用页面上边的 Save Version 后台运行**\n","- 后台运行不用担心长时间不操作脚本停止\n","- Version Type 选择 **Save & Run All**\n","- 在Save Version弹窗里需要选择使用**GPU**环境 (Advanced Settings 里最后一个选项)\n","- 后台运行的输出的图片可以在运行结束后下载(但是保存时间有限制,我就经常下不到,不够问题不大,喜欢的图在生成后就下载了)\n","- 如果你需要下载运行后的图片,请不要把安装目录修改到 /kaggle/working 这个目录下,因为没有写打包功能,下载只能下载整个输出目录,也就是 /kaggle/working 目录\n","\n","## 访问\n","- 如果你使用了ngrok或者frpc,可以访问你这两对应的地址\n","- 如果你不知道你的ngrok或者frpc的地址可以在控制台(页面最下方Console)的输出里面查看\n","- 使用Run All方式启动,控制台在启动完成后会输出访问网址,网址内容包含**gradio.live**,可以在页面中搜索快速找到\n","- 如果使用Save Verson的方式启动,点击左下角的**View Active Events**点击刚刚启动的脚步,在**Log**里找访问网址\n","- 一般情况下第一次启动此脚本需要等待kaggle下载模型文件,进度在页面上方\n","- 第二次及以后(不增加新的文件)需要3到5分钟\n","\n","## 增加模型\n","1. 先创建数据集,也就是dataset\n","2. 创建时需要添加文件,选择自己的模型文件就行\n","3. 同类型文件放相同的数据集里面,一个数据集也不要太大\n","4. 可以在dataset搜索其他人上传的模型\n","5. 通过右侧的 **Add Data** 按钮选择已经上传的模型文件或者别人上传的模型文件\n","    - input 下面的列表就是模型文件,可以点击名称后面的复制按钮复制路径\n","6. 将模型路径放在配置里的对应配置里即可,支持文件夹和文件路径,参考 **modelDirs**\n","    - 如果目录里还有子目录也是需要加载的,可以用*表示子目录 例子:比如Loras目录下还有角色、画风、涩涩的文件夹,那路径里写成 '/kaggle/input/Loras/*'就可以加载子目录里面的文件了\n","    - 模型加载使用的文件链接方式,如果你融模型的时候新模型名字和原有模型名字一样,会出现不能修改只读文件的错误\n","    - 同理,直接对模型做编辑的工具可能也会出现相同的错误\n","    \n","  \n","- **为了提高启动速度,导致切换模型过程较慢,点击切换模型后进度条大概率会一直存在,但模型在1分半左右基本能加载完。** \n","- **受到kaggle内存大小的影响,切换多个模型后大概率爆内存导致停止运行**\n","    \n","**下边的配置项都写了对应配置的作用和使用说明,不理解的话也不用改,用默认的就好**\n","\n","## 下载文件\n","#### 方式一\n","- 在浏览器直接下 比如你需要下载的文件路径在 /kaggle/stable-diffusion-webui/models/Lora/dow_a.safetensors\n","    - 比如你需要下载的文件路径在 /kaggle/stable-diffusion-webui/models/Lora/dow_a.safetensors\n","    - 你的访问地址是 https://123123123.gradio.live\n","    - 则可以在浏览器输入 https://123123123.gradio.live/file=/kaggle/stable-diffusion-webui/models/Lora/dow_a.safetensors 下载你的文件\n","    \n","#### 方式二\n","- 复制到Output目录下载 仅支持使用Run All方式运行的\n","    - 比如你需要下载的文件路径在 /kaggle/stable-diffusion-webui/models/Lora/dow_a.safetensors\n","    - 先停止笔记本(不是关机,是停止)\n","    - 然后新建一个代码块,在里面输入 !cp -f /kaggle/stable-diffusion-webui/models/Lora/dow_a.safetensors /kaggle/working/\n","    - 或者 新建一个代码块,在里面输入 !cp -f \\$install_path/stable-diffusion-webui/models/Lora/dow_a.safetensors /kaggle/working/\n","    - 你可能需要拼接路径 如果是在webui里面看到的路径,且路径里面没有带**stable-diffusion-webui**\n","        - 拼接方式是 **\\$install_path/stable-diffusion-webui** + **文件路径** 拼成类似前一条的样子\n","    - 就可以在右侧列表的Output目录看见复制出来的文件,点击下载即可\n","    \n","#### 方式三\n","- 开启链接输出目录的配置 (配置在第二个代码块,通过搜索**配置文件链接**快速查找)\n","    - 此方法会把已知的三个训练输出目录链接到Output目录下,直接去下载即可(两种启动方式都可以用)\n","    - 如果有新的目录需要链接,可以参考着自己写或者联系我\n","    \n","#### 方式四\n","- 将安装目录改到输出目录(配置在第二个代码块,通过搜索**安装目录**快速查找)\n","    - 此方式会把所有文件都放在安装目录,找到并下载即可\n","    - 如果使用这个方式,右侧的设置里**PERSISTENCE**这个设置项建议选No pensistence。如果选其他项,可能会出现关机特别慢的情况,因为需要上传输出目录的文件。\n","\n","## **一些可能没用的说明**\n","- 配置说明 **True或者False**表示布尔值 **True**表示“**是**” **False**表示“**否**” 只有这两个值\n","- 配置说明 **[]** 表示数组,里面可以存放内容,每个内容需要用**英语(半角)逗号**隔开\n","- 配置说明 **''或者\"\"** 英语(半角)的双引号或者单引号包裹的内容是**字符串**,比如放在数组里面的路径就需要是一个字符串\n","- 配置说明 **#** **#** 后面的内容是**注释**,是帮助性内容,对整个代码的执行不会有影响\n"]},{"cell_type":"markdown","metadata":{},"source":["# 更新记录\n","#### 230726 v170\n","- 更新了整个配置,可以更加自由的下载和加载文件\n","- 删除了大部分参数\n","\n","#### 230726 v169\n","- 增加了一个文件加载配置,可以自定义把文件或下载地址加载到指定目录,配置方式见 [ 其他文件列表 ]\n","- 增加了一个配置,可以隐藏部分控制台输出,但隐藏不完全,没啥用\n","\n","#### 230719 v168\n","- 增加了同步收藏文件夹到 huggingface 数据集的功能,仅同步收藏文件夹,如果同步所有图片也太浪费资源了\n","\n","#### 230716 v167\n","- 账号解封了\n","- 已经更新为精简自动更新版,主要逻辑分离存放到 [huggingface](https://huggingface.co/viyi/sdwui),这边基本上不再需要更新\n","- 如果增加了新功能需要新的配置,可以在输出内容的最前面查看到(暂定)\n","\n","#### 230302 v165\n","- 可以修改disableShared=True来使用pm2启动,做到爆内存自动重启(需要使用frpc或者ngrok代理,否则无法访问界面)\n","\n","#### 230228 v156\n","- 移除了koishi的相关功能 如需使用,可查看 [sd-webui-koishi](https://www.kaggle.com/code/yiyiooo/sd-webui-koishi)\n","\n","#### 230227 v147\n","- 增加了nginx做反向代理,现在可以使用一个ngrok地址访问多个服务了 功能在版本156移除\n","\n","#### 230225 v139\n","- 可以加载ssl证书,启动https的隧道了\n","\n","#### 230224 v134\n","- 可以自动修改frp的本地端口\n","\n","#### 230224 v128\n","- 修复默认模型文件不存在时不能启动的问题\n","- 修复了多线程导致依赖等内容安装位置错乱的问题\n","- 修复了第一次启动会更新koishi数据对应的数据集问题\n","- 增加了配置检查功能,对一些配置项做了提示\n","- 增加了可配置webui端口功能,现在可以配置webui、froc、ngrok的端口了\n","\n","#### 230223 v126\n","- 修复了仅适用koishi数据目录无法启动koishi的问题\n","- 修改了部分文档\n","\n","#### 230223 v124\n","- 修复使用多线程后出现的文件安装下载目录失败的问题\n","- 修复使用多线程后文件目录错乱问题\n","\n","#### 230222 v123\n","- 使用多线程进行安装,节省安装时间\n","\n","#### 230222 v122\n","- 更改了默认配置,现在训练的输出可以在Output下面查看了\n","\n","#### 230222 v118\n","- 增加了自动上传koishi的数据到数据集且能自动下载的功能\n","    - 自动上传的数据集优先级高于手动上传的\n","    - 上一个版本的数据集与当前版本的目录结构有差异,如果更新后需要修改配置\n","    \n","#### 230121 v111\n","- 增加了koishi的部署相关功能  功能在版本156移除\n","\n","#### 230220 v110\n","- 增加了ControlNet插件的一些说明\n","\n","#### 230220 v109\n","- 修复第二次Run all时不能切换到新的frpc配置问题\n","- 增加更新记录,用于记录每次更新 "]}],"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.12"}},"nbformat":4,"nbformat_minor":4}