{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.10.10","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"## NovelAi sd-webui AI绘画项目 修复版(完全免费,无需任何配置!)\n**torch: 2.0.0+cu118  •  xformers: 0.0.19**\n\n# 有问题请加qq群632428790 (691/2000)\n### 急需一名宣传人员,无偿,会做B站视频就行","metadata":{}},{"cell_type":"markdown","source":"## 使用教程:https://www.kaggle.com/code/at2020dead/novelai-stable-diffusion/notebook ","metadata":{}},{"cell_type":"markdown","source":"
\n 📌 2023年3月5日更新:现在支持通过下载链接上传模型了,省去了下载模型后再上传后的麻烦.()\n
\n
\n 📌 2023年5月15日更新:现在可以双开webui了,可以双线程跑图(GPU请选择 T4 x2 , 将use2设置为True)\n
","metadata":{}},{"cell_type":"markdown","source":"# 注意事项/WARNING:\n- ### 1.将设置中的PERSISTENCE改为Files Only方便下次打开提高启动速度,第一次启动后下载Python环境包就不用下载第二次了\n- ### 2.检测到出现涩图会容易导致封号现象,建议到webui设置里把'始终保存所有生成的图像'和‘始终保存所有生成的宫格图’关了\n- ### 3.如果不能启动,请新建一个notebook并且重新导入","metadata":{}},{"cell_type":"markdown","source":"## Ai绘画模型下载站:\n#### [Civitai](http://civitai.com)\n \n#### [huggingface](http://huggingface.co)\n \n#### [pix.ink](http://pix.ink) ","metadata":{}},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"code","source":"# 安装目录\ninstall_path=\"/kaggle/working\" #或者/kaggle\nupdata_webui = False #是否开机自动更新webui\n\n# 重置变量 会删掉sd_webui重新安装\nreLoad = False\nupdata_webui = False\n\n#清理和打包生成的图片\nzip_output=True\nclear_output=True\n\n# 使用huggingface保存和载入webui配置文件\nhuggingface_use = True\nhuggingface_token_file = '/kaggle/input/hugfacetoken/hugfacetoken.txt'\nhuggiingface_repo_id = 'ACCA225/sdconfig'\n# 将会同步的文件\nyun_files = ['ui-config.json','config.json','styles.csv']","metadata":{"execution":{"iopub.status.busy":"2023-05-20T07:30:21.846234Z","iopub.execute_input":"2023-05-20T07:30:21.847196Z","iopub.status.idle":"2023-05-20T07:30:21.855338Z","shell.execute_reply.started":"2023-05-20T07:30:21.847158Z","shell.execute_reply":"2023-05-20T07:30:21.853675Z"},"trusted":true},"execution_count":16,"outputs":[]},{"cell_type":"code","source":"#模型和插件\n\n# 插件列表: git仓库地址\n# 不需要的插件在前面加 # ,插件地址之间需要用英语逗号隔开\nextensions = [\n 'https://github.com/Elldreth/loopback_scaler',\n 'https://github.com/jexom/sd-webui-depth-lib',\n 'https://github.com/AlUlkesh/stable-diffusion-webui-images-browser',\n 'https://github.com/camenduru/sd-civitai-browser',\n 'https://github.com/Mikubill/sd-webui-controlnet',\n 'https://github.com/nonnonstop/sd-webui-3d-open-pose-editor',\n 'https://github.com/dtlnor/stable-diffusion-webui-localization-zh_CN',\n 'https://github.com/opparco/stable-diffusion-webui-two-shot',\n #'https://github.com/minicacas/stable-diffusion-webui-composable-lora',\n 'https://github.com/DominikDoom/a1111-sd-webui-tagcomplete',\n 'https://github.com/pkuliyi2015/multidiffusion-upscaler-for-automatic1111',\n 'https://github.com/KohakuBlueleaf/a1111-sd-webui-locon',\n 'https://github.com/hnmr293/sd-webui-cutoff',\n 'https://github.com/hako-mikan/sd-webui-lora-block-weight',\n 'https://github.com/butaixianran/Stable-Diffusion-Webui-Civitai-Helper',\n 'https://github.com/catppuccin/stable-diffusion-webui',\n #'https://github.com/Nevysha/Cozy-Nest',\n 'https://github.com/Scholar01/sd-webui-mov2mov',\n 'https://github.com/toriato/stable-diffusion-webui-wd14-tagger',\n 'https://github.com/Physton/sd-webui-prompt-all-in-one'\n]\n\n# Stable Diffusion模型请放在这里(不用填模型的文件名,只填模型的目录即可)\nsd_model = [\n#'/kaggle/input/cetus-mix/',\n#'/kaggle/input/aom3ackpt',\n'/kaggle/input/9527-fp16',\n#'/kaggle/input/dalcefo-painting',\n ]\n# Stable Diffusion模型下载链接放这里\nsd_model_urls=[\n#Counterfeit-V3.0\n'https://civitai.com/api/download/models/57618',\n'https://huggingface.co/datasets/sukaka/sd_models_fp16/resolve/main/cetusMix_Coda2.safetensors',\n'https://huggingface.co/datasets/sukaka/sd_models_fp16/resolve/main/cetusMix_Version35.safetensors',\n\n]\n\n# VAE模型请放在这里(不用填模型的文件名,只填模型的目录即可)\nvae_model = []\n#VAE模型下载链接放这里\nvae_model_urls=[\n'https://huggingface.co/datasets/sukaka/sd_models_fp16/resolve/main/clearvae.vae.pt',\n]\n\n# Lora模型的数据集路径请写在这里:\nlora_model = [\n#'/kaggle/input/lora-1',\n] \n# Lora模型下载链接放这里\nlora_model_urls=[\n#墨心\n'https://civitai.com/api/download/models/14856',\n#山楂糕\n'https://civitai.com/api/download/models/41580',\n]\n\n# ControlNet模型data请放在这里:\ncn_model = [\n]\n# controlnet模型下载链接放这里\ncn_model_urls = [\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_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_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# Hypernetworks超网络模型路径请放在这里:\nhypernetworks_model = []\n#Hypernetworks超网络模型下载链接请放在这里\nhypernetworks_model_urls = []\n\n#放大算法路径请放在这里\nESRGAN = []\n#放大算法链接请放在这里\nESRGAN_urls = [\n'https://huggingface.co/FacehugmanIII/4x_foolhardy_Remacri/resolve/main/4x_foolhardy_Remacri.pth',\n'https://huggingface.co/konohashinobi4/4xAnimesharp/resolve/main/4x-AnimeSharp.pth',\n'https://huggingface.co/lokCX/4x-Ultrasharp/resolve/main/4x-UltraSharp.pth',\n]\n\n# embeddings(pt文件)请放在这里:\nembeddings_model = [\n'/kaggle/input/bad-embedding',\n] \n# embeddings(pt文件)下载链接请放在这里:\nembeddings_model_urls=[\n'https://huggingface.co/datasets/sukaka/sd_configs/resolve/main/%E4%BA%BA%E4%BD%93%E4%BF%AE%E6%AD%A3/EasyNegative.pt',\n'https://huggingface.co/datasets/sukaka/sd_configs/resolve/main/%E4%BA%BA%E4%BD%93%E4%BF%AE%E6%AD%A3/bad-artist-anime.pt',\n'https://huggingface.co/datasets/sukaka/sd_configs/resolve/main/%E4%BA%BA%E4%BD%93%E4%BF%AE%E6%AD%A3/bad-hands-5.pt',\n'https://huggingface.co/datasets/sukaka/sd_configs/resolve/main/%E4%BA%BA%E4%BD%93%E4%BF%AE%E6%AD%A3/bad_prompt_version2.pt',\n'https://huggingface.co/datasets/sukaka/sd_configs/resolve/main/%E4%BA%BA%E4%BD%93%E4%BF%AE%E6%AD%A3/bad-image-v2-39000.pt',\n]\n\n#script文件导入\nscripts = []\n#script文件下载链接导入\nscripts_urls = [\n'https://huggingface.co/datasets/sukaka/sd_configs/resolve/main/repositories/k-diffusion/k_diffusion/sampling.py'\n]\n\n#tag词库文件导入\ntags = []\n","metadata":{"execution":{"iopub.status.busy":"2023-05-20T07:30:21.857785Z","iopub.execute_input":"2023-05-20T07:30:21.858580Z","iopub.status.idle":"2023-05-20T07:30:21.872782Z","shell.execute_reply.started":"2023-05-20T07:30:21.858546Z","shell.execute_reply":"2023-05-20T07:30:21.871584Z"},"trusted":true},"execution_count":17,"outputs":[]},{"cell_type":"code","source":"# 是否使用pm2启动\nusepm2 = False\n# 使用pm2启动可以爆内存时自动重启,用于测试,非必要别开\n# 开启后需使用frp或者ngrok做内网穿透","metadata":{"execution":{"iopub.status.busy":"2023-05-20T07:30:21.873790Z","iopub.execute_input":"2023-05-20T07:30:21.874065Z","iopub.status.idle":"2023-05-20T07:30:21.894336Z","shell.execute_reply.started":"2023-05-20T07:30:21.874027Z","shell.execute_reply":"2023-05-20T07:30:21.893313Z"},"trusted":true},"execution_count":18,"outputs":[]},{"cell_type":"code","source":"#ngrok穿透\nngrok_use = False\nngrokTokenFile='/kaggle/input/ngroktoken/Authtoken.txt' # 非必填 存放ngrokToken的文件的路径\n#Frp 内网穿透\nuse_frpc = False\nfrpconfigfile = '/kaggle/input/testfrpc/frpc_8215127.ini' # 非必填 frp 配置文件,本地端口 7860\n\n# 启动时默认加载的模型名称 填模型名称,名称建议带上文件名后缀\nusedCkpt = 'cetusMix_Coda2.safetensors'\n\n#启动参数\nargs = [\n '--share',\n '--xformers',\n '--lowram',\n '--no-hashing',\n '--disable-nan-check',\n '--enable-insecure-extension-access',\n '--disable-console-progressbars',\n '--enable-console-prompts',\n '--disable-safe-unpickle',\n '--no-gradio-queue',\n '--no-half-vae',\n '--api'\n]","metadata":{"execution":{"iopub.status.busy":"2023-05-20T07:30:21.897399Z","iopub.execute_input":"2023-05-20T07:30:21.897756Z","iopub.status.idle":"2023-05-20T07:30:21.906315Z","shell.execute_reply.started":"2023-05-20T07:30:21.897723Z","shell.execute_reply":"2023-05-20T07:30:21.905406Z"},"trusted":true},"execution_count":19,"outputs":[]},{"cell_type":"code","source":"use2 = False#是否开启两个webui\n#ngrok穿透\nngrok_use1 = False\nngrokTokenFile1='/kaggle/input/ngroktoken/Authtoken1.txt' # 非必填 存放ngrokToken的文件的路径\n#Frp 内网穿透\nuse_frpc1 = True\nfrpconfigfile1 = '/kaggle/input/testfrpc1/frpc_8217098.ini' # 非必填 frp 配置文件,本地端口 7861\n\n#第二个webui使用的模型\nusedCkpt1 = 'cetusMix_Coda2.safetensors'\n\n#启动参数\nargs1 = [\n '--share',\n '--xformers',\n '--lowram',\n '--no-hashing',\n '--disable-nan-check',\n '--enable-insecure-extension-access',\n '--disable-console-progressbars',\n '--enable-console-prompts',\n '--disable-safe-unpickle',\n '--no-gradio-queue',\n '--no-half-vae',\n '--api'\n]","metadata":{"execution":{"iopub.status.busy":"2023-05-20T07:30:21.907369Z","iopub.execute_input":"2023-05-20T07:30:21.907689Z","iopub.status.idle":"2023-05-20T07:30:21.928847Z","shell.execute_reply.started":"2023-05-20T07:30:21.907663Z","shell.execute_reply":"2023-05-20T07:30:21.927866Z"},"trusted":true},"execution_count":20,"outputs":[]},{"cell_type":"code","source":"#使用的库\nfrom pathlib import Path\nimport subprocess\nimport pandas as pd\nimport shutil\nimport os\nimport time\nimport re\nimport gc\nimport requests\nfrom concurrent.futures import ProcessPoolExecutor\nos.environ['install_path'] = install_path","metadata":{"execution":{"iopub.status.busy":"2023-05-20T07:30:21.930433Z","iopub.execute_input":"2023-05-20T07:30:21.931165Z","iopub.status.idle":"2023-05-20T07:30:21.941753Z","shell.execute_reply.started":"2023-05-20T07:30:21.931131Z","shell.execute_reply":"2023-05-20T07:30:21.940790Z"},"trusted":true},"execution_count":21,"outputs":[]},{"cell_type":"code","source":"#功能函数,内存优化\ndef libtcmalloc():\n if os.path.exists('/kaggle/temp'):\n os.chdir('/kaggle')\n os.chdir('temp')\n os.environ[\"LD_PRELOAD\"] = \"libtcmalloc.so\"\n print('内存优化已安装')\n else:\n \n if use_frpc:\n !aria2c --console-log-level=error -c -x 16 -s 16 -k 1M https://huggingface.co/datasets/ACCA225/Frp/resolve/main/frpc -d /kaggle/working/frpc -o frpc\n os.system('pip install -q pyngrok ')\n os.chdir('/kaggle')\n os.makedirs('temp', exist_ok=True)\n os.chdir('temp')\n os.system('wget -qq http://launchpadlibrarian.net/367274644/libgoogle-perftools-dev_2.5-2.2ubuntu3_amd64.deb')\n os.system('wget -qq https://launchpad.net/ubuntu/+source/google-perftools/2.5-2.2ubuntu3/+build/14795286/+files/google-perftools_2.5-2.2ubuntu3_all.deb')\n os.system('wget -qq https://launchpad.net/ubuntu/+source/google-perftools/2.5-2.2ubuntu3/+build/14795286/+files/libtcmalloc-minimal4_2.5-2.2ubuntu3_amd64.deb')\n os.system('wget -qq https://launchpad.net/ubuntu/+source/google-perftools/2.5-2.2ubuntu3/+build/14795286/+files/libgoogle-perftools4_2.5-2.2ubuntu3_amd64.deb')\n os.system('apt install -qq libunwind8-dev -y')\n !dpkg -i *.deb\n os.environ[\"LD_PRELOAD\"] = \"libtcmalloc.so\"\n !rm *.deb\n print('内存优化已安装')","metadata":{"execution":{"iopub.status.busy":"2023-05-20T07:30:21.995559Z","iopub.execute_input":"2023-05-20T07:30:21.996305Z","iopub.status.idle":"2023-05-20T07:30:22.014131Z","shell.execute_reply.started":"2023-05-20T07:30:21.996270Z","shell.execute_reply":"2023-05-20T07:30:22.013234Z"},"trusted":true},"execution_count":22,"outputs":[]},{"cell_type":"code","source":"#功能函数,环境和sd_webui安装\ndef webui_config_download(yun_files, huggiingface_repo_id):\n %cd $install_path/stable-diffusion-webui/\n for yun_file in yun_files:\n url = f'https://huggingface.co/datasets/{huggiingface_repo_id}/resolve/main/{yun_file}'\n response = requests.head(url)\n if response.status_code == 200:\n result = subprocess.run(['wget', '-O', yun_file, url, '-q'], capture_output=True)\n if result.returncode != 0:\n print(f'Error: Failed to download {yun_file} from {url}')\n else:\n print(f'Error: Invalid URL {url}')\n \ndef venv_install():\n %cd /opt/conda/envs\n if os.path.exists('venv'):\n print('环境已安装')\n else:\n %cd /kaggle/working/\n if not os.path.exists('venv.tar.gz'):\n print('环境包下载中')\n !wget https://huggingface.co/datasets/sukaka/venv_ai_drow/resolve/main/sd_webui_torch2_cu118_xf19.tar.gz -O venv.tar.gz\n print('环境包已下载')\n %cd /opt/conda/envs/\n !mkdir venv\n %cd venv\n print('环境安装中')\n !tar -xzf /kaggle/working/venv.tar.gz\n !source /opt/conda/bin/activate venv\n print('环境安装完毕')\n\n#安装webui\ndef install_webui():\n %cd $install_path\n if reLoad:\n !rm -rf stable-diffusion-webui\n if Path(\"stable-diffusion-webui\").exists():\n if updata_webui:\n %cd $install_path/stable-diffusion-webui/\n !git pull\n print('stable-diffusion-webui已安装')\n else:\n print('stable-diffusion-webui安装中')\n #Download Automatic1111's Stable Diffusion Web UI\n !git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui\n %cd $install_path/stable-diffusion-webui/\n #Use lastest version\n !git checkout 5ab7f213bec2f816f9c5644becb32eb72c8ffb89\n with open('launch.py', 'r') as f:\n content = f.read()\n with open('launch.py', 'w') as f:\n f.write('import ssl\\n')\n f.write('ssl._create_default_https_context = ssl._create_unverified_context\\n')\n f.write(content)\n print('stable-diffusion-webui已安装')\n if huggingface_use:\n webui_config_download(yun_files, huggiingface_repo_id)\n install_extensions(install_path, extensions)\n download_model()\n link_models()","metadata":{"execution":{"iopub.status.busy":"2023-05-20T07:30:22.016461Z","iopub.execute_input":"2023-05-20T07:30:22.017099Z","iopub.status.idle":"2023-05-20T07:30:22.122797Z","shell.execute_reply.started":"2023-05-20T07:30:22.017064Z","shell.execute_reply":"2023-05-20T07:30:22.121924Z"},"trusted":true},"execution_count":23,"outputs":[]},{"cell_type":"code","source":"def pm2():\n if usepm2:\n !npm i -g pm2\n ","metadata":{"execution":{"iopub.status.busy":"2023-05-20T07:30:22.125915Z","iopub.execute_input":"2023-05-20T07:30:22.126788Z","iopub.status.idle":"2023-05-20T07:30:22.140521Z","shell.execute_reply.started":"2023-05-20T07:30:22.126753Z","shell.execute_reply":"2023-05-20T07:30:22.139630Z"},"trusted":true},"execution_count":24,"outputs":[]},{"cell_type":"code","source":"from concurrent.futures import ThreadPoolExecutor\n# 安装插件,下载和同步模型\ndef install_extensions(install_path, extensions):\n print('安装插件,此处出现红条是正常的')\n os.chdir(os.path.join(install_path, 'stable-diffusion-webui'))\n os.makedirs('extensions', exist_ok=True)\n os.chdir('extensions')\n for ex in extensions:\n repo_name = ex.split('/')[-1]\n if not os.path.exists(repo_name):\n os.system('git clone ' + ex)\n \ndef download_link(link, target_folder):\n if link.startswith('https://huggingface.co/'):\n filename = re.search(r'[^/]+$', link).group(0)\n return f'aria2c --console-log-level=error -q -c -x 16 -s 16 -k 1M -d \"{target_folder}\" -o \"{filename}\" \"{link}\"'\n else:\n return f'aria2c --console-log-level=error -q -c -x 16 -s 16 -k 1M --remote-time -d \"{target_folder}\" \"{link}\"'\n\ndef download_links(links, target_folder):\n tasks = []\n for link in links:\n tasks.append(download_link(link, target_folder))\n return tasks\n\ndef download_links_all(tasks):\n with ThreadPoolExecutor(max_workers=5) as executor:\n for task in tasks:\n executor.submit(os.system, task)\n \n# 下载模型文件\ndef download_model():\n os.chdir('/kaggle')\n os.makedirs('models', exist_ok=True)\n os.chdir('models')\n os.makedirs('VAE', exist_ok=True)\n os.makedirs('Stable-diffusion', exist_ok=True)\n os.makedirs('Lora', exist_ok=True)\n os.makedirs('cn-model', exist_ok=True)\n os.makedirs('hypernetworks', exist_ok=True)\n os.makedirs('ESRGAN', exist_ok=True)\n tasks = []\n tasks.extend(download_links(vae_model_urls, 'VAE'))\n tasks.extend(download_links(sd_model_urls, 'Stable-diffusion'))\n tasks.extend(download_links(lora_model_urls, 'Lora'))\n tasks.extend(download_links(cn_model_urls, 'cn-model'))\n tasks.extend(download_links(hypernetworks_model_urls, 'hypernetworks'))\n tasks.extend(download_links(ESRGAN_urls, 'ESRGAN'))\n tasks.extend(download_links(embeddings_model_urls, f'{install_path}/stable-diffusion-webui/embeddings'))\n tasks.extend(download_links(scripts_urls, f'{install_path}/stable-diffusion-webui/scripts'))\n download_links_all(tasks)\n\ndef create_symlinks(folder_paths, target_dir):\n # Create target directory if it doesn't exist\n if not os.path.exists(target_dir):\n os.makedirs(target_dir)\n # Remove broken symlinks in target directory\n for filename in os.listdir(target_dir):\n target_path = os.path.join(target_dir, filename)\n if os.path.islink(target_path) and not os.path.exists(target_path):\n os.unlink(target_path)\n # Create new symlinks\n for source_path in folder_paths:\n if not os.path.exists(source_path):\n continue\n if os.path.isdir(source_path):\n for filename in os.listdir(source_path):\n source_file_path = os.path.join(source_path, filename)\n target_file_path = os.path.join(target_dir, filename)\n if not os.path.exists(target_file_path):\n os.symlink(source_file_path, target_file_path)\n print(f'Created symlink for {filename} in {target_dir}')\n else:\n filename = os.path.basename(source_path)\n target_file_path = os.path.join(target_dir, filename)\n if not os.path.exists(target_file_path):\n os.symlink(source_path, target_file_path)\n print(f'Created symlink for {filename} in {target_dir}')\n\n# 链接模型文件\ndef link_models():\n cn_model.append('/kaggle/models/cn-model')\n vae_model.append('/kaggle/models/VAE')\n sd_model.append('/kaggle/models/Stable-diffusion')\n lora_model.append('/kaggle/models/Lora')\n hypernetworks_model.append('/kaggle/models/hypernetworks')\n ESRGAN.append('/kaggle/models/ESRGAN')\n \n create_symlinks(vae_model,f'{install_path}/stable-diffusion-webui/models/VAE')\n create_symlinks(sd_model,f'{install_path}/stable-diffusion-webui/models/Stable-diffusion')\n create_symlinks(lora_model,f'{install_path}/stable-diffusion-webui/models/Lora')\n create_symlinks(cn_model,f'{install_path}/stable-diffusion-webui/extensions/sd-webui-controlnet/models')\n create_symlinks(embeddings_model,f'{install_path}/stable-diffusion-webui/embeddings')\n create_symlinks(hypernetworks_model,f'{install_path}/stable-diffusion-webui/models/hypernetworks')\n create_symlinks(ESRGAN,f'{install_path}/stable-diffusion-webui/models/ESRGAN')\n create_symlinks(tags,f'{install_path}/stable-diffusion-webui/extensions/a1111-sd-webui-tagcomplete/tags')\n create_symlinks(scripts,f'{install_path}/stable-diffusion-webui/scripts')\n","metadata":{"execution":{"iopub.status.busy":"2023-05-20T07:30:22.144877Z","iopub.execute_input":"2023-05-20T07:30:22.145214Z","iopub.status.idle":"2023-05-20T07:30:22.168255Z","shell.execute_reply.started":"2023-05-20T07:30:22.145180Z","shell.execute_reply":"2023-05-20T07:30:22.167371Z"},"trusted":true},"execution_count":25,"outputs":[]},{"cell_type":"code","source":"# 功能函数:内网穿透\n#ngrok\ndef ngrok_start(ngrokTokenFile: str, port: int, address_name: str, should_run: bool):\n if not should_run:\n print('Skipping ngrok start')\n return\n if Path(ngrokTokenFile).exists():\n with open(ngrokTokenFile, encoding=\"utf-8\") as nkfile:\n ngrokToken = nkfile.readline()\n print('use nrgok')\n from pyngrok import conf, ngrok\n conf.get_default().auth_token = ngrokToken\n conf.get_default().monitor_thread = False\n ssh_tunnels = ngrok.get_tunnels(conf.get_default())\n if len(ssh_tunnels) == 0:\n ssh_tunnel = ngrok.connect(port, bind_tls=True)\n print(f'{address_name}:' + ssh_tunnel.public_url)\n else:\n print(f'{address_name}:' + ssh_tunnels[0].public_url)\n else:\n print('skip start ngrok')\n\n#Frp内网穿透 \nimport subprocess\n\ndef install_Frpc(port, frpconfigfile, use_frpc):\n if use_frpc:\n subprocess.run(['chmod', '+x', '/kaggle/working/frpc/frpc'], check=True)\n print(f'正在启动frp ,端口{port}')\n subprocess.Popen(['/kaggle/working/frpc/frpc', '-c', frpconfigfile])\n","metadata":{"execution":{"iopub.status.busy":"2023-05-20T07:30:22.171517Z","iopub.execute_input":"2023-05-20T07:30:22.171817Z","iopub.status.idle":"2023-05-20T07:30:22.184129Z","shell.execute_reply.started":"2023-05-20T07:30:22.171793Z","shell.execute_reply":"2023-05-20T07:30:22.183313Z"},"trusted":true},"execution_count":26,"outputs":[]},{"cell_type":"code","source":"#sd_webui启动\ndef start_webui1():\n if use2:\n install_Frpc('7861',frpconfigfile1,use_frpc1)\n ngrok_start(ngrokTokenFile1,7861,'第二个webui',ngrok_use1)\n !sleep 90\n %cd $install_path/stable-diffusion-webui\n args1.append(f'--ckpt=models/Stable-diffusion/{usedCkpt1}')\n if usepm2:\n !pm2 del webui_main\n !pm2 flush webui_main\n !pm2 start /opt/conda/envs/venv/bin/python3 -n webui_main -- launch.py {' '.join(args)}\n else:\n !/opt/conda/envs/venv/bin/python3 launch.py {' '.join(args)}\n pass\n\ndef start_webui():\n install_Frpc('7860',frpconfigfile,use_frpc)\n ngrok_start(ngrokTokenFile,7860,'第一个webui',ngrok_use)\n %cd $install_path/stable-diffusion-webui\n args.append(f'--ckpt=models/Stable-diffusion/{usedCkpt}')\n if usepm2:\n !pm2 del webui_main1\n !pm2 flush webui_main1\n !pm2 start /opt/conda/envs/venv/bin/python3 -n webui_main1 -- launch.py {' '.join(args)}\n else:\n !/opt/conda/envs/venv/bin/python3 launch.py {' '.join(args)}","metadata":{"execution":{"iopub.status.busy":"2023-05-20T07:30:22.186567Z","iopub.execute_input":"2023-05-20T07:30:22.187252Z","iopub.status.idle":"2023-05-20T07:30:22.230997Z","shell.execute_reply.started":"2023-05-20T07:30:22.187218Z","shell.execute_reply":"2023-05-20T07:30:22.230110Z"},"trusted":true},"execution_count":27,"outputs":[]},{"cell_type":"code","source":"def main():\n startTicks = time.time()\n os.system('apt -y install -qq aria2')\n with ProcessPoolExecutor() as executor:\n futures = []\n for func in [pm2, install_webui, venv_install,libtcmalloc]:\n futures.append(executor.submit(func))\n time.sleep(0.5)\n for future in futures:\n future.result()\n libtcmalloc()\n ticks = time.time()\n print(\"加载耗时:\",(ticks - startTicks),\"s\")\n with ProcessPoolExecutor() as executor:\n futures = []\n for func in [start_webui, start_webui1]:\n futures.append(executor.submit(func))\n time.sleep(1)\n for future in futures:\n future.result()","metadata":{"execution":{"iopub.status.busy":"2023-05-20T07:30:22.233099Z","iopub.execute_input":"2023-05-20T07:30:22.233824Z","iopub.status.idle":"2023-05-20T07:30:22.247843Z","shell.execute_reply.started":"2023-05-20T07:30:22.233791Z","shell.execute_reply":"2023-05-20T07:30:22.247015Z"},"trusted":true},"execution_count":28,"outputs":[]},{"cell_type":"code","source":"#功能函数,清理打包上传\nfrom pathlib import Path\nfrom huggingface_hub import HfApi, login\n\ndef hugface_upload(huggingface_token_file, yun_files, repo_id):\n if Path(huggingface_token_file).exists():\n with open(huggingface_token_file, encoding=\"utf-8\") as nkfile:\n hugToken = nkfile.readline()\n if hugToken != '':\n # 使用您的 Hugging Face 访问令牌登录\n login(token=hugToken)\n # 实例化 HfApi 类\n api = HfApi()\n print(\"HfApi 类已实例化\")\n %cd $install_path/stable-diffusion-webui\n # 使用 upload_file() 函数上传文件\n print(\"开始上传文件...\")\n for yun_file in yun_files:\n if Path(yun_file).exists():\n response = api.upload_file(\n path_or_fileobj=yun_file,\n path_in_repo=yun_file,\n repo_id=repo_id,\n repo_type=\"dataset\"\n )\n print(\"文件上传完成\")\n print(f\"响应: {response}\")\n else:\n print(f'Error: File {yun_file} does not exist')\n else:\n print(f'Error: File {huggingface_token_file} does not exist')\n\ndef clean_folder(folder_path):\n if not os.path.exists(folder_path):\n return\n for filename in os.listdir(folder_path):\n file_path = os.path.join(folder_path, filename)\n if os.path.isfile(file_path):\n os.remove(file_path)\n elif os.path.isdir(file_path):\n shutil.rmtree(file_path)\n\ndef zip_clear_updata():\n if zip_output:\n output_folder = f'{install_path}/stable-diffusion-webui/outputs/'\n if os.path.exists(output_folder):\n shutil.make_archive('/kaggle/working/图片', 'zip', output_folder)\n print('图片已压缩到output')\n else:\n print(f'文件夹 {output_folder} 不存在,跳过压缩操作')\n if clear_output:\n %cd $install_path/stable-diffusion-webui/outputs/\n clean_folder('img2img-images')\n clean_folder('txt2img-images')\n clean_folder('img2img-grids')\n clean_folder('txt2img-grids')\n clean_folder('extras-images')\n print('清理完毕')\n if huggingface_use == True:\n hugface_upload(huggingface_token_file,yun_files,huggiingface_repo_id)","metadata":{"execution":{"iopub.status.busy":"2023-05-20T07:30:22.249368Z","iopub.execute_input":"2023-05-20T07:30:22.249814Z","iopub.status.idle":"2023-05-20T07:30:22.274003Z","shell.execute_reply.started":"2023-05-20T07:30:22.249781Z","shell.execute_reply":"2023-05-20T07:30:22.273180Z"},"trusted":true},"execution_count":29,"outputs":[]},{"cell_type":"code","source":"# start\nmain()\n!pm2 log","metadata":{"_kg_hide-input":true,"_kg_hide-output":false,"execution":{"iopub.status.busy":"2023-05-20T07:30:22.277082Z","iopub.execute_input":"2023-05-20T07:30:22.277474Z"},"trusted":true},"execution_count":null,"outputs":[{"name":"stderr","text":"\nWARNING: apt does not have a stable CLI interface. Use with caution in scripts.\n\n","output_type":"stream"},{"name":"stdout","text":"aria2 is already the newest version (1.35.0-1build1).\n0 upgraded, 0 newly installed, 0 to remove and 27 not upgraded.\n/kaggle/working\nstable-diffusion-webui已安装\n/kaggle/working/stable-diffusion-webui\n安装插件,此处出现红条是正常的\n/opt/conda/envs\n环境已安装\n内存优化已安装\n\u001b[K\u001b[?25h\u001b[37;40mnpm\u001b[0m \u001b[0m\u001b[30;43mWARN\u001b[0m \u001b[0m\u001b[35mdeprecated\u001b[0m uuid@3.4.0: Please upgrade to version 7 or higher. Older versions may use Math.random() in certain circumstances, which is known to be problematic. See https://v8.dev/blog/math-random for details.\n\u001b[K\u001b[?25hm##################\u001b[0m) ⠋ reify:lodash: \u001b[32;40mhttp\u001b[0m \u001b[35mfetch\u001b[0m GET 200 https://registry.npmjs.\u001b[0m\u001b[Knpmjs.\u001b[0m\u001b[K[0m\u001b[K\nadded 184 packages, and audited 185 packages in 8s\n\n12 packages are looking for funding\n run `npm fund` for details\n\nfound \u001b[32m\u001b[1m0\u001b[22m\u001b[39m vulnerabilities\n\u001b[37;40mnpm\u001b[0m \u001b[0m\u001b[36;40mnotice\u001b[0m\u001b[35m\u001b[0m \n\u001b[0m\u001b[37;40mnpm\u001b[0m \u001b[0m\u001b[36;40mnotice\u001b[0m\u001b[35m\u001b[0m New \u001b[31mmajor\u001b[39m version of npm available! \u001b[31m8.19.3\u001b[39m -> \u001b[32m9.6.7\u001b[39m\n\u001b[0m\u001b[37;40mnpm\u001b[0m \u001b[0m\u001b[36;40mnotice\u001b[0m\u001b[35m\u001b[0m Changelog: \u001b[36mhttps://github.com/npm/cli/releases/tag/v9.6.7\u001b[39m\n\u001b[0m\u001b[37;40mnpm\u001b[0m \u001b[0m\u001b[36;40mnotice\u001b[0m\u001b[35m\u001b[0m Run \u001b[32mnpm install -g npm@9.6.7\u001b[39m to update!\n\u001b[0m\u001b[37;40mnpm\u001b[0m \u001b[0m\u001b[36;40mnotice\u001b[0m\u001b[35m\u001b[0m \n\u001b[0m内存优化已安装\n加载耗时: 12.937358379364014 s\n正在启动frp ,端口7860\nSkipping ngrok start\n/kaggle/working/stable-diffusion-webui\n2023/05/20 07:30:35 [I] 检查更新中\n正在启动frp ,端口7861\nSkipping ngrok start\n2023/05/20 07:30:36 [I] 发现新版本 [0.45.0-sakura-4], 发布于 [2023-05-15 05:40:49 +0000 UTC]\n更新日志:[-] 修复 API 被 DNS 污染导致隧道无法启动的问题\n\n2023/05/20 07:30:36 [I] 自动更新未启用, 请添加 --update 参数启用自动更新, 或于 https://nyat-static.globalslb.net/natfrp/client/0.45.0-sakura-4/frpc_linux_386 手动下载\n\n2023/05/20 07:30:36 [I] frpc version: 0.45.0-sakura-2.3 (built: 2023-01-28 16:59)\n2023/05/20 07:30:36 [I] 正在连接节点 [frp-day.top, tcp]\n2023/05/20 07:30:36 [I] 检查更新中\n2023/05/20 07:30:36 [I] [57/625110/caa1] 连接节点成功, 获得 run ID [bsn**kxz-caa163ce]\n2023/05/20 07:30:36 [I] [57/625110/caa1] 隧道连接中: [bsn**kxz.BXMV2B80]\n2023/05/20 07:30:36 [I] [57/625110/caa1] 限速已更新: 36 Mibit/s\n2023/05/20 07:30:36 [I] 发现新版本 [0.45.0-sakura-4], 发布于 [2023-05-15 05:40:49 +0000 UTC]\n更新日志:[-] 修复 API 被 DNS 污染导致隧道无法启动的问题\n\n2023/05/20 07:30:36 [I] 自动更新未启用, 请添加 --update 参数启用自动更新, 或于 https://nyat-static.globalslb.net/natfrp/client/0.45.0-sakura-4/frpc_linux_386 手动下载\n\n2023/05/20 07:30:36 [I] frpc version: 0.45.0-sakura-2.3 (built: 2023-01-28 16:59)\n2023/05/20 07:30:36 [I] 正在连接节点 [frp-day.top, tcp]\nTCP 类型隧道启动成功\n使用 [frp-day.top:10528] 来连接到你的隧道\n或使用 IP 地址连接(不推荐):[104.160.18.141:10528]\n2023/05/20 07:30:36 [I] [57/625110/caa1] [bsn**kxz.BXMV2B80] start proxy success\n\n -------------\n\n__/\\\\\\\\\\\\\\\\\\\\\\\\\\____/\\\\\\\\____________/\\\\\\\\____/\\\\\\\\\\\\\\\\\\_____\n _\\/\\\\\\/////////\\\\\\_\\/\\\\\\\\\\\\________/\\\\\\\\\\\\__/\\\\\\///////\\\\\\___\n _\\/\\\\\\_______\\/\\\\\\_\\/\\\\\\//\\\\\\____/\\\\\\//\\\\\\_\\///______\\//\\\\\\__\n _\\/\\\\\\\\\\\\\\\\\\\\\\\\\\/__\\/\\\\\\\\///\\\\\\/\\\\\\/_\\/\\\\\\___________/\\\\\\/___\n _\\/\\\\\\/////////____\\/\\\\\\__\\///\\\\\\/___\\/\\\\\\________/\\\\\\//_____\n _\\/\\\\\\_____________\\/\\\\\\____\\///_____\\/\\\\\\_____/\\\\\\//________\n _\\/\\\\\\_____________\\/\\\\\\_____________\\/\\\\\\___/\\\\\\/___________\n _\\/\\\\\\_____________\\/\\\\\\_____________\\/\\\\\\__/\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\_\n _\\///______________\\///______________\\///__\\///////////////__\n\n\n Runtime Edition\n\n PM2 is a Production Process Manager for Node.js applications\n with a built-in Load Balancer.\n\n Start and Daemonize any application:\n $ pm2 start app.js\n\n Load Balance 4 instances of api.js:\n $ pm2 start api.js -i 4\n\n Monitor in production:\n $ pm2 monitor\n\n Make pm2 auto-boot at server restart:\n $ pm2 startup\n\n To go further checkout:\n http://pm2.io/\n\n\n -------------\n\n\u001b[32m[PM2] \u001b[39mSpawning PM2 daemon with pm2_home=/root/.pm2\n2023/05/20 07:30:37 [I] [57/625110/e5bf] 连接节点成功, 获得 run ID [bsn**kxz-e5bfb7bf]\n2023/05/20 07:30:37 [I] [57/625110/e5bf] 隧道连接中: [bsn**kxz.8VIUV9ZW]\n2023/05/20 07:30:37 [I] [57/625110/e5bf] 限速已更新: 36 Mibit/s\nTCP 类型隧道启动成功\n使用 [frp-day.top:38663] 来连接到你的隧道\n或使用 IP 地址连接(不推荐):[104.160.18.141:38663]\n2023/05/20 07:30:37 [I] [57/625110/e5bf] [bsn**kxz.8VIUV9ZW] start proxy success\n\u001b[32m[PM2] \u001b[39mPM2 Successfully daemonized\n\u001b[31m[PM2][ERROR] \u001b[39mProcess or Namespace webui_main1 not found\n\u001b[32m[PM2] \u001b[39mLogs flushed\n\u001b[32m[PM2] \u001b[39mStarting /opt/conda/envs/venv/bin/python3 in fork_mode (1 instance)\n\u001b[32m[PM2] \u001b[39mDone.\n\u001b[90m┌────┬────────────────────┬──────────┬──────┬───────────┬──────────┬──────────┐\u001b[39m\n\u001b[90m│\u001b[39m\u001b[1m\u001b[36m id \u001b[39m\u001b[22m\u001b[90m│\u001b[39m\u001b[1m\u001b[36m name \u001b[39m\u001b[22m\u001b[90m│\u001b[39m\u001b[1m\u001b[36m mode \u001b[39m\u001b[22m\u001b[90m│\u001b[39m\u001b[1m\u001b[36m ↺ \u001b[39m\u001b[22m\u001b[90m│\u001b[39m\u001b[1m\u001b[36m status \u001b[39m\u001b[22m\u001b[90m│\u001b[39m\u001b[1m\u001b[36m cpu \u001b[39m\u001b[22m\u001b[90m│\u001b[39m\u001b[1m\u001b[36m memory \u001b[39m\u001b[22m\u001b[90m│\u001b[39m\n\u001b[90m├────┼────────────────────┼──────────┼──────┼───────────┼──────────┼──────────┤\u001b[39m\n\u001b[90m│\u001b[39m\u001b[1m\u001b[36m \u001b[1m\u001b[36m0\u001b[39m\u001b[36m\u001b[22m\u001b[1m \u001b[39m\u001b[22m\u001b[90m│\u001b[39m webui_main1 \u001b[90m│\u001b[39m \u001b[7m\u001b[1mfork\u001b[22m\u001b[27m \u001b[90m│\u001b[39m 0 \u001b[90m│\u001b[39m \u001b[32m\u001b[1monline\u001b[22m\u001b[39m \u001b[90m│\u001b[39m 0% \u001b[90m│\u001b[39m 11.3mb \u001b[90m│\u001b[39m\n\u001b[90m└────┴────────────────────┴──────────┴──────┴───────────┴──────────┴──────────┘\u001b[39m\n/kaggle/working/stable-diffusion-webui\n\u001b[31m[PM2][ERROR] \u001b[39mProcess or Namespace webui_main not found\n\u001b[32m[PM2] \u001b[39mLogs flushed\n\u001b[32m[PM2] \u001b[39mStarting /opt/conda/envs/venv/bin/python3 in fork_mode (1 instance)\n\u001b[32m[PM2] \u001b[39mDone.\n\u001b[90m┌────┬────────────────────┬──────────┬──────┬───────────┬──────────┬──────────┐\u001b[39m\n\u001b[90m│\u001b[39m\u001b[1m\u001b[36m id \u001b[39m\u001b[22m\u001b[90m│\u001b[39m\u001b[1m\u001b[36m name \u001b[39m\u001b[22m\u001b[90m│\u001b[39m\u001b[1m\u001b[36m mode \u001b[39m\u001b[22m\u001b[90m│\u001b[39m\u001b[1m\u001b[36m ↺ \u001b[39m\u001b[22m\u001b[90m│\u001b[39m\u001b[1m\u001b[36m status \u001b[39m\u001b[22m\u001b[90m│\u001b[39m\u001b[1m\u001b[36m cpu \u001b[39m\u001b[22m\u001b[90m│\u001b[39m\u001b[1m\u001b[36m memory \u001b[39m\u001b[22m\u001b[90m│\u001b[39m\n\u001b[90m├────┼────────────────────┼──────────┼──────┼───────────┼──────────┼──────────┤\u001b[39m\n\u001b[90m│\u001b[39m\u001b[1m\u001b[36m \u001b[1m\u001b[36m1\u001b[39m\u001b[36m\u001b[22m\u001b[1m \u001b[39m\u001b[22m\u001b[90m│\u001b[39m webui_main \u001b[90m│\u001b[39m \u001b[7m\u001b[1mfork\u001b[22m\u001b[27m \u001b[90m│\u001b[39m 0 \u001b[90m│\u001b[39m \u001b[32m\u001b[1monline\u001b[22m\u001b[39m \u001b[90m│\u001b[39m 0% \u001b[90m│\u001b[39m 2.2mb \u001b[90m│\u001b[39m\n\u001b[90m│\u001b[39m\u001b[1m\u001b[36m \u001b[1m\u001b[36m0\u001b[39m\u001b[36m\u001b[22m\u001b[1m \u001b[39m\u001b[22m\u001b[90m│\u001b[39m webui_main1 \u001b[90m│\u001b[39m \u001b[7m\u001b[1mfork\u001b[22m\u001b[27m \u001b[90m│\u001b[39m 0 \u001b[90m│\u001b[39m \u001b[32m\u001b[1monline\u001b[22m\u001b[39m \u001b[90m│\u001b[39m 0% \u001b[90m│\u001b[39m 6.3gb \u001b[90m│\u001b[39m\n\u001b[90m└────┴────────────────────┴──────────┴──────┴───────────┴──────────┴──────────┘\u001b[39m\n\u001b[1m\u001b[90m[TAILING] Tailing last 15 lines for [all] processes (change the value with --lines option)\u001b[39m\u001b[22m\n\u001b[90m/root/.pm2/pm2.log last 15 lines:\u001b[39m\n\u001b[34mPM2 | \u001b[39m2023-05-20T07:30:37: PM2 log: Current arch : x64\n\u001b[34mPM2 | \u001b[39m2023-05-20T07:30:37: PM2 log: PM2 home : /root/.pm2\n\u001b[34mPM2 | \u001b[39m2023-05-20T07:30:37: PM2 log: PM2 PID file : /root/.pm2/pm2.pid\n\u001b[34mPM2 | \u001b[39m2023-05-20T07:30:37: PM2 log: RPC socket file : /root/.pm2/rpc.sock\n\u001b[34mPM2 | \u001b[39m2023-05-20T07:30:37: PM2 log: BUS socket file : /root/.pm2/pub.sock\n\u001b[34mPM2 | \u001b[39m2023-05-20T07:30:37: PM2 log: Application log path : /root/.pm2/logs\n\u001b[34mPM2 | \u001b[39m2023-05-20T07:30:37: PM2 log: Worker Interval : 30000\n\u001b[34mPM2 | \u001b[39m2023-05-20T07:30:37: PM2 log: Process dump file : /root/.pm2/dump.pm2\n\u001b[34mPM2 | \u001b[39m2023-05-20T07:30:37: PM2 log: Concurrent actions : 2\n\u001b[34mPM2 | \u001b[39m2023-05-20T07:30:37: PM2 log: SIGTERM timeout : 1600\n\u001b[34mPM2 | \u001b[39m2023-05-20T07:30:37: PM2 log: ===============================================================================\n\u001b[34mPM2 | \u001b[39m2023-05-20T07:30:40: PM2 log: App [webui_main1:0] starting in -fork mode-\n\u001b[34mPM2 | \u001b[39m2023-05-20T07:30:40: PM2 log: App [webui_main1:0] online\n\u001b[34mPM2 | \u001b[39m2023-05-20T07:32:11: PM2 log: App [webui_main:1] starting in -fork mode-\n\u001b[34mPM2 | \u001b[39m2023-05-20T07:32:11: PM2 log: App [webui_main:1] online\n\n\u001b[90m/root/.pm2/logs/webui-main1-out.log last 15 lines:\u001b[39m\n\u001b[32m0|webui_ma | \u001b[39m\n\u001b[32m0|webui_ma | \u001b[39mLaunching Web UI with arguments: --share --xformers --lowram --no-hashing --disable-nan-check --enable-insecure-extension-access --disable-console-progressbars --enable-console-prompts --disable-safe-unpickle --no-gradio-queue --no-half-vae --api --ckpt=models/Stable-diffusion/cetusMix_Coda2.safetensors\n\u001b[32m0|webui_ma | \u001b[39mCivitai Helper: Get Custom Model Folder\n\u001b[32m0|webui_ma | \u001b[39mCivitai Helper: Load setting from: /kaggle/working/stable-diffusion-webui/extensions/Stable-Diffusion-Webui-Civitai-Helper/setting.json\n\u001b[32m0|webui_ma | \u001b[39mCivitai Helper: No setting file, use default\n\u001b[32m0|webui_ma | \u001b[39mAdditional Network extension not installed, Only hijack built-in lora\n\u001b[32m0|webui_ma | \u001b[39mLoCon Extension hijack built-in lora successfully\n\u001b[32m0|webui_ma | \u001b[39mControlNet v1.1.180\n\u001b[32m0|webui_ma | \u001b[39mControlNet v1.1.180\n\u001b[32m0|webui_ma | \u001b[39msd-webui-prompt-all-in-one background API service started successfully.\n\u001b[32m0|webui_ma | \u001b[39mImage Browser: ImageReward is not installed, cannot be used.\n\u001b[32m0|webui_ma | \u001b[39mLoading weights [None] from /kaggle/working/stable-diffusion-webui/models/Stable-diffusion/cetusMix_Coda2.safetensors\n\u001b[32m0|webui_ma | \u001b[39mCreating model from config: /kaggle/working/stable-diffusion-webui/configs/v1-inference.yaml\n\u001b[32m0|webui_ma | \u001b[39mLatentDiffusion: Running in eps-prediction mode\n\u001b[32m0|webui_ma | \u001b[39mDiffusionWrapper has 859.52 M params.\n\n\u001b[90m/root/.pm2/logs/webui-main1-error.log last 15 lines:\u001b[39m\n\u001b[31m0|webui_ma | \u001b[39m File \"/kaggle/working/stable-diffusion-webui/modules/scripts.py\", line 256, in load_scripts\n\u001b[31m0|webui_ma | \u001b[39m script_module = script_loading.load_module(scriptfile.path)\n\u001b[31m0|webui_ma | \u001b[39m File \"/kaggle/working/stable-diffusion-webui/modules/script_loading.py\", line 11, in load_module\n\u001b[31m0|webui_ma | \u001b[39m module_spec.loader.exec_module(module)\n\u001b[31m0|webui_ma | \u001b[39m File \"\", line 883, in exec_module\n\u001b[31m0|webui_ma | \u001b[39m File \"\", line 241, in _call_with_frames_removed\n\u001b[31m0|webui_ma | \u001b[39m File \"/kaggle/working/stable-diffusion-webui/scripts/sampling.py\", line 10, in \n\u001b[31m0|webui_ma | \u001b[39m from . import utils\n\u001b[31m0|webui_ma | \u001b[39mModuleNotFoundError: No module named 'sampling'\n\u001b[31m0|webui_ma | \u001b[39m\nDownloading (…)olve/main/vocab.json: 100%|██████████| 961k/961k [00:00<00:00, 17.2MB/s]\nDownloading (…)olve/main/merges.txt: 100%|██████████| 525k/525k [00:00<00:00, 124MB/s]\nDownloading (…)cial_tokens_map.json: 100%|██████████| 389/389 [00:00<00:00, 2.52MB/s]\nDownloading (…)okenizer_config.json: 100%|██████████| 905/905 [00:00<00:00, 5.34MB/s]\nDownloading (…)lve/main/config.json: 100%|██████████| 4.52k/4.52k [00:00<00:00, 21.2MB/s]\n\n\u001b[90m/root/.pm2/logs/webui-main-out.log last 15 lines:\u001b[39m\n\u001b[90m/root/.pm2/logs/webui-main-error.log last 15 lines:\u001b[39m\n\u001b[31m1|webui_main | \u001b[39mError loading script: sampling.py\n\u001b[31m1|webui_main | \u001b[39mTraceback (most recent call last):\n\u001b[31m1|webui_main | \u001b[39m File \"/kaggle/working/stable-diffusion-webui/modules/scripts.py\", line 256, in load_scripts\n\u001b[31m1|webui_main | \u001b[39m script_module = script_loading.load_module(scriptfile.path)\n\u001b[31m1|webui_main | \u001b[39m File \"/kaggle/working/stable-diffusion-webui/modules/script_loading.py\", line 11, in load_module\n\u001b[31m1|webui_main | \u001b[39m module_spec.loader.exec_module(module)\n\u001b[31m1|webui_main | \u001b[39m File \"\", line 883, in exec_module\n\u001b[31m1|webui_main | \u001b[39m File \"\", line 241, in _call_with_frames_removed\n\u001b[31m1|webui_main | \u001b[39m File \"/kaggle/working/stable-diffusion-webui/scripts/sampling.py\", line 10, in \n\u001b[31m1|webui_main | \u001b[39m from . import utils\n\u001b[31m1|webui_main | \u001b[39mModuleNotFoundError: No module named 'sampling'\n","output_type":"stream"}]},{"cell_type":"code","source":"#跑图结束,手动执行,清理图片并打包到output方便下载,同时同步配置文件\nzip_clear_updata()","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#模型下载器,手动执行后出现一个交互式表格\nimport os\ninstall_path=\"/kaggle/working\" \nos.environ['install_path'] = install_path\ndef model_down_tool():\n import ipywidgets as widgets\n from IPython.display import display\n import subprocess\n def download_with_aria2(link, file_path):\n # 设置aria2c命令行参数\n cmd = ['aria2c','--console-log-level=error', link, '-o', file_path, '-x', '16', '-s', '16', '-k', '1M']\n # 调用aria2c下载文件\n try:\n subprocess.run(cmd, check=True)\n print(f\"文件已保存到: {file_path}\")\n except subprocess.CalledProcessError as e:\n print(f\"下载失败: {e}\")\n def sdmodel_down(link, model_name):\n # 设置模型保存的文件夹路径\n %cd $install_path\n save_dir = 'stable-diffusion-webui/models/Stable-diffusion'\n if not os.path.exists(save_dir):\n os.makedirs(save_dir)\n \n # 设置模型保存的文件名\n file_name = f\"{model_name}\"\n file_path = os.path.join(save_dir, file_name)\n \n # 下载模型\n download_with_aria2(link, file_path)\n \n print(f\"模型已保存到: {file_path}\")\n\n def vae_down(link, model_name):\n # 设置模型保存的文件夹路径\n %cd $install_path\n save_dir = 'stable-diffusion-webui/models/VAE'\n if not os.path.exists(save_dir):\n os.makedirs(save_dir)\n\n # 设置模型保存的文件名\n file_name = f\"{model_name}\"\n file_path = os.path.join(save_dir, file_name)\n\n # 下载模型\n cmd = ['aria2c','--console-log-level=error', link, '-o', file_path, '-x', '16', '-s', '16', '-k', '1M']\n\n print(f\"模型已保存到: {file_path}\")\n\n def vae_down(link, model_name):\n # 设置模型保存的文件夹路径\n %cd $install_path\n save_dir = 'stable-diffusion-webui/models/Lora'\n if not os.path.exists(save_dir):\n os.makedirs(save_dir)\n\n # 设置模型保存的文件名\n file_name = f\"{model_name}\"\n file_path = os.path.join(save_dir, file_name)\n\n # 下载模型\n cmd = ['aria2c','--console-log-level=error', link, '-o', file_path, '-x', '16', '-s', '16', '-k', '1M']\n\n print(f\"模型已保存到: {file_path}\")\n \n model_type = widgets.Dropdown(\n options=['sd大模型', 'vae模型', 'Lora模型'],\n description='模型类型:',\n disabled=False,\n )\n\n link = widgets.Text(\n value='',\n placeholder='输入链接',\n description='链接:',\n disabled=False\n )\n\n model_name = widgets.Text(\n value='',\n placeholder='输入模型名称',\n description='模型名:',\n disabled=False\n )\n\n def on_submit(btn):\n if model_type.value == 'sd大模型':\n sdmodel_down(link.value, model_name.value)\n elif model_type.value == 'vae模型':\n vae_down(link.value, model_name.value)\n else:\n lora_down(link.value, model_name.value)\n\n submit = widgets.Button(description=\"提交\")\n submit.on_click(on_submit)\n\n display(model_type, link, model_name, submit)\n#模型下载器\nmodel_down_tool()\n#safetensors","metadata":{"trusted":true},"execution_count":null,"outputs":[]}]}