Upload 2 files
Browse files
sdwui-start-util.ipynb
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"cells":[{"cell_type":"code","execution_count":null,"metadata":{"trusted":true},"outputs":[],"source":[]},{"cell_type":"code","execution_count":null,"metadata":{"trusted":true},"outputs":[],"source":["update_desc = '''\n","欢迎使用 stable-diffusion-webui 便捷启动工具\n","\n","此脚本理论上可以在任何jupyter环境运行,但仅在 google colab 和 kaggle 测试。 已经无法在 google colab 免费实例上运行。\n","此脚本的【前置脚本】发布地址 https://www.kaggle.com/code/yiyiooo/stable-diffusion-webui-novelai-sdxl。\n","此脚本需配合 【前置脚本】 的脚本附带的配置项才能正常启动。\n","此脚本的内容会自动更新,你无需更新【前置脚本】就能获取到最新的功能。\n","增加一个说明:为解决加密图片的解密和浏览的问题,开发了一个独立应用,可以在这里下载 https://github.com/viyiviyi/encrypt_gallery/releases/\n","加密插件可解决生成nsfw图片后被平台封号问题\n","\n","路径说明\n","* 为了解决平台差异,所有的安装目录和文件输出目录都被重新指定,如果你需要在配置中访问这些目录,请查看以下说明\n","*\n","* 可以使用 $install_path 或 {install_path} 来访问安装目录,写在字符串内也会生效\n","* $output_path 或 {output_path} 可以访问输出目录\n","* 如果你需要安装在自定义目录,也可以设置这些值 如: install_path = '新的路径'\n","* 可自定义方法 on_before_start 并在方法内写上启动前需要的逻辑来实现在webui启动前执行自定义逻辑\n","* 可以增加配置 multi_case = True 来控制是否使用多卡\n","* 如果需要显示更多控制台输出 需配置 hidden_console_info = False\n","\n","********* 特别提示 *********\n","* huggingface 的下载链接需要增加 ?download=true 参数才能正确下载到文件,如果你需要的文件里的下载链接没有这个参数,请自行增加。\n","'''"]},{"cell_type":"code","execution_count":null,"metadata":{"trusted":true},"outputs":[],"source":["from pathlib import Path\n","import os\n","import time\n","import re\n","import subprocess\n","import threading\n","import sys\n","import socket\n","import torch\n","from typing import List\n","import uuid\n","import asyncio\n","from urllib import request"]},{"cell_type":"code","execution_count":null,"metadata":{"trusted":true},"outputs":[],"source":["# 内置参数默认值,当上下文有参数时可覆盖默认值\n","_runing = False\n","_useFrpc = locals().get('useFrpc') or globals().get('useFrpc') or True\n","\n","_useNgrok = locals().get('useNgrok') or globals().get('useNgrok') or True\n","\n","_reLoad = locals().get('reLoad') or globals().get('reLoad') or False\n"," \n","_before_downloading = locals().get('before_downloading') or globals().get('before_downloading') or ''\n","\n","_async_downloading = locals().get('async_downloading') or globals().get('async_downloading') or ''\n","\n","_before_start_sync_downloading = locals().get('before_start_sync_downloading') or globals().get('before_start_sync_downloading') or ''\n","\n","_server_port = locals().get('server_port') or globals().get('server_port') or 7860\n"," \n","_sd_git_repo = locals().get('sd_git_repo') or globals().get('sd_git_repo') or 'https://github.com/viyiviyi/stable-diffusion-webui.git -b local' \n","_sd_git_repo = _sd_git_repo\\\n"," .replace('{sdwui}','stable-diffusion-webui')\\\n"," .replace('{wui}',\"webui\")\n"," \n","_sd_config_git_repu = locals().get('sd_config_git_repu') or globals().get('sd_config_git_repu') or 'https://github.com/viyiviyi/sd-configs.git'\n","_sd_config_git_repu = _sd_config_git_repu\\\n"," .replace('{sdwui}','stable-diffusion-webui')\\\n"," .replace('{wui}',\"webui\")\n"," \n"," \n","_huggingface_token = locals().get('huggingface_token') or globals().get('huggingface_token') or '{input_path}/configs/huggingface_token.txt'\n","_huggingface_token = _huggingface_token\\\n"," .replace('{sdwui}','stable-diffusion-webui')\\\n"," .replace('{wui}',\"webui\")\n"," \n","_huggingface_repo = locals().get('huggingface_repo') or globals().get('huggingface_repo') or ''\n","_huggingface_repo = _huggingface_repo\\\n"," .replace('{sdwui}','stable-diffusion-webui')\\\n"," .replace('{wui}',\"webui\")\n","\n","_link_instead_of_copy = locals().get('link_instead_of_copy') or globals().get('link_instead_of_copy') or True\n"," \n","show_shell_info = locals().get('hidden_console_info') or globals().get('hidden_console_info')\n","if show_shell_info is None: show_shell_info = False\n","\n","_multi_case = locals().get('multi_case') or globals().get('multi_case') or False\n"," \n","_skip_start = locals().get('skip_start') or globals().get('skip_start') or True\n","\n","def before_start():\n"," pass\n","\n","def main_start():\n"," pass\n","\n","_on_before_start = locals().get('on_before_start') or globals().get('on_before_start') or before_start \n","_skip_webui = locals().get('skip_webui') or globals().get('skip_webui') or False\n"," \n","run_by_none_device = False\n","\n","_proxy_path = locals().get('proxy_path') or globals().get('proxy_path') or {}\n","\n","_sub_path = locals().get('sub_path') or globals().get('sub_path') or ['/','/1/']\n","if len(_sub_path) != 2:\n"," _sub_path = ['/','/1/']\n"," \n","_config_args:dict[str, str] = locals().get('config_args') or globals().get('config_args') or {}"]},{"cell_type":"code","execution_count":null,"metadata":{"trusted":true},"outputs":[],"source":["\n","def run(command, cwd=None, desc=None, errdesc=None, custom_env=None,try_error:bool=True) -> str:\n"," global show_shell_info\n"," if desc is not None:\n"," print(desc)\n","\n"," run_kwargs = {\n"," \"args\": command,\n"," \"shell\": True,\n"," \"cwd\": cwd,\n"," \"env\": os.environ if custom_env is None else custom_env,\n"," \"encoding\": 'utf8',\n"," \"errors\": 'ignore',\n"," }\n","\n"," if not show_shell_info:\n"," run_kwargs[\"stdout\"] = run_kwargs[\"stderr\"] = subprocess.PIPE\n","\n"," result = subprocess.run(**run_kwargs)\n","\n"," if result.returncode != 0:\n"," error_bits = [\n"," f\"{errdesc or 'Error running command'}.\",\n"," f\"Command: {command}\",\n"," f\"Error code: {result.returncode}\",\n"," ]\n"," if result.stdout:\n"," error_bits.append(f\"stdout: {result.stdout}\")\n"," if result.stderr:\n"," error_bits.append(f\"stderr: {result.stderr}\")\n"," if try_error:\n"," print((RuntimeError(\"\\n\".join(error_bits))))\n"," else:\n"," raise RuntimeError(\"\\n\".join(error_bits))\n","\n"," if show_shell_info:\n"," print((result.stdout or \"\"))\n"," return (result.stdout or \"\")\n","\n","def mkdirs(path, exist_ok=True):\n"," if path and not Path(path).exists():\n"," os.makedirs(path,exist_ok=exist_ok)\n","\n","\n","# 检查网络\n","def check_service(host, port):\n"," try:\n"," socket.create_connection((host, port), timeout=5)\n"," return True\n"," except socket.error:\n"," return False\n","\n","\n","# 检查gpu是否存在\n","def check_gpu():\n"," if not run_by_none_device and torch.cuda.device_count() == 0:\n"," raise Exception('当前环境没有GPU')\n","\n","\n","def echoToFile(content:str,path:str):\n"," if path.find('/') >= 0:\n"," _path = '/'.join(path.split('/')[:-1])\n"," run(f'''mkdir -p {_path}''')\n"," with open(path,'w') as sh:\n"," sh.write(content)\n"," \n","def get_freefrp_confog(local_port):\n"," rd_str = uuid.uuid1()\n"," return (f'''\n","[common]\n","server_addr = frp.freefrp.net\n","server_port = 7000\n","token = freefrp.net\n","\n","[{rd_str}_http]\n","type = http\n","local_ip = 127.0.0.1\n","local_port = {local_port}\n","custom_domains = {rd_str}.frp.eaias.com\n","''',f'http://{rd_str}.frp.eaias.com')"]},{"cell_type":"code","execution_count":null,"metadata":{"trusted":true},"outputs":[],"source":["\n","_install_path = f\"/kaggle\" if os.path.exists('/kaggle/') else f\"{os.environ['HOME']}/sd_webui\" # 安装目录\n","_output_path = '/kaggle/working' if os.path.exists('/kaggle/working/') else f\"{os.environ['HOME']}/.sdwui/Output\" # 输出目录 如果使用google云盘 会在google云盘增加sdwebui/Output\n","_input_path = '/kaggle/input' # 输入目录\n","_ui_dir_name = 'sd_main_dir'\n","\n","_install_path = locals().get('install_path') or globals().get('install_path') or _install_path\n","_output_path = locals().get('output_path') or globals().get('output_path') or _output_path\n","_input_path = locals().get('input_path') or globals().get('input_path') or _input_path\n","_ui_dir_name = locals().get('ui_dir_name') or globals().get('ui_dir_name') or _ui_dir_name\n","\n","install_path = _install_path\n","output_path = _output_path\n","input_path = _input_path\n","ui_dir_name = _ui_dir_name\n"," \n","google_drive = '' \n","\n","\n","_useGooglrDrive = locals().get('useGooglrDrive') or globals().get('useGooglrDrive') or True\n","\n","# 连接谷歌云\n","try:\n"," if _useGooglrDrive:\n"," from google.colab import drive\n"," drive.mount(f'~/google_drive')\n"," google_drive = f\"{os.environ['HOME']}/google_drive/MyDrive\"\n"," _output_path = f'{google_drive}/sdwebui/Output'\n"," _input_path = f'{google_drive}/sdwebui/Input'\n"," run(f'''mkdir -p {_input_path}''')\n"," print('''\n","已经链接到谷歌云盘\n","已在云盘创建Input和Output目录\n"," ''')\n","except:\n"," _useGooglrDrive = False\n","\n","run(f'''mkdir -p {_install_path}''')\n","run(f'''mkdir -p {_output_path}''')\n","\n","\n","os.environ['install_path'] = _install_path\n","os.environ['output_path'] = _output_path\n","os.environ['google_drive'] = google_drive\n","os.environ['input_path'] = _input_path\n","\n","def replace_path(input_str:str):\n"," if not input_str: return ''\n"," for key in _config_args:\n"," input_str = input_str.replace(key,_config_args[key])\n"," \n"," if not (locals().get('use_comfyui') or globals().get('use_comfyui') or False):\n"," input_str = input_str.replace('https://github.com/comfyanonymous/ComfyUI.git','https://github.com/comfyanonymous/ComfyUI.git')\n"," \n"," return input_str.replace('$install_path',_install_path)\\\n"," .replace('{install_path}',_install_path)\\\n"," .replace('$input_path',_input_path)\\\n"," .replace('{input_path}',_input_path)\\\n"," .replace('$output_path',_output_path)\\\n"," .replace('{output_path}',_output_path)\\\n"," .replace('{sdwui}','stable-diffusion-webui')\\\n"," .replace('{wui}',\"webui\")\n","\n","space_string = ' \\n\\r\\t\\'\\\",'\n","\n","def config_reader(conf:str):\n"," args = [replace_path(item.split('#')[0].strip(space_string)) for item in conf.split('\\n') if item.strip(space_string)]\n"," return [item.strip() for item in args if item.strip()]\n"]},{"cell_type":"code","execution_count":1,"metadata":{},"outputs":[{"ename":"NameError","evalue":"name 'os' is not defined","output_type":"error","traceback":["\u001b[1;31m---------------------------------------------------------------------------\u001b[0m","\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)","Cell \u001b[1;32mIn[1], line 3\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[38;5;66;03m# ... existing code ...\u001b[39;00m\n\u001b[1;32m----> 3\u001b[0m _install_path \u001b[38;5;241m=\u001b[39m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m/kaggle\u001b[39m\u001b[38;5;124m\"\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m \u001b[43mos\u001b[49m\u001b[38;5;241m.\u001b[39mpath\u001b[38;5;241m.\u001b[39mexists(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m/kaggle/\u001b[39m\u001b[38;5;124m'\u001b[39m) \u001b[38;5;28;01melse\u001b[39;00m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mos\u001b[38;5;241m.\u001b[39menviron[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mHOME\u001b[39m\u001b[38;5;124m'\u001b[39m]\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m/sd_webui\u001b[39m\u001b[38;5;124m\"\u001b[39m \u001b[38;5;66;03m# 安装目录\u001b[39;00m\n\u001b[0;32m 4\u001b[0m _output_path \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124m/kaggle/working\u001b[39m\u001b[38;5;124m'\u001b[39m \u001b[38;5;28;01mif\u001b[39;00m os\u001b[38;5;241m.\u001b[39mpath\u001b[38;5;241m.\u001b[39mexists(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m/kaggle/working/\u001b[39m\u001b[38;5;124m'\u001b[39m) \u001b[38;5;28;01melse\u001b[39;00m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mos\u001b[38;5;241m.\u001b[39menviron[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mHOME\u001b[39m\u001b[38;5;124m'\u001b[39m]\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m/.sdwui/Output\u001b[39m\u001b[38;5;124m\"\u001b[39m \u001b[38;5;66;03m# 输出目录 \u001b[39;00m\n\u001b[0;32m 5\u001b[0m _input_path \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124m/kaggle/input\u001b[39m\u001b[38;5;124m'\u001b[39m \u001b[38;5;66;03m# 输入目录\u001b[39;00m\n","\u001b[1;31mNameError\u001b[0m: name 'os' is not defined"]}],"source":["# ... existing code ...\n","\n","_install_path = f\"/kaggle\" if os.path.exists('/kaggle/') else f\"{os.environ['HOME']}/sd_webui\" # 安装目录\n","_output_path = '/kaggle/working' if os.path.exists('/kaggle/working/') else f\"{os.environ['HOME']}/.sdwui/Output\" # 输出目录 \n","_input_path = '/kaggle/input' # 输入目录\n","_ui_dir_name = 'sd_main_dir'\n","\n","_install_path = locals().get('install_path') or globals().get('install_path') or _install_path\n","_output_path = locals().get('output_path') or globals().get('output_path') or _output_path\n","_input_path = locals().get('input_path') or globals().get('input_path') or _input_path\n","_ui_dir_name = locals().get('ui_dir_name') or globals().get('ui_dir_name') or _ui_dir_name\n","\n","install_path = _install_path\n","output_path = _output_path\n","input_path = _input_path\n","ui_dir_name = _ui_dir_name\n","\n","google_drive = '' \n","\n","# 连接谷歌云相关代码,已注释\n","# _useGooglrDrive = locals().get('useGooglrDrive') or globals().get('useGooglrDrive') or True\n","\n","# # 连接谷歌云\n","# try:\n","# if _useGooglrDrive:\n","# from google.colab import drive\n","# drive.mount(f'~/google_drive')\n","# google_drive = f\"{os.environ['HOME']}/google_drive/MyDrive\"\n","# _output_path = f'{google_drive}/sdwebui/Output'\n","# _input_path = f'{google_drive}/sdwebui/Input'\n","# run(f'''mkdir -p {_input_path}''')\n","# print('''\n","# 已经链接到谷歌云盘\n","# 已在云盘创建Input和Output目录\n","# ''')\n","# except:\n","# _useGooglrDrive = False\n","\n","run(f'''mkdir -p {_install_path}''')\n","run(f'''mkdir -p {_output_path}''')\n","\n","os.environ['install_path'] = _install_path\n","os.environ['output_path'] = _output_path\n","os.environ['google_drive'] = google_drive\n","os.environ['input_path'] = _input_path\n","\n","# ... existing code ..."]},{"cell_type":"code","execution_count":2,"metadata":{},"outputs":[],"source":["# 入口函数部分修改\n","def main():\n"," global envInstalled\n"," global huggingface_is_init\n"," global _runing\n"," stop_solo_threads()\n"," print('启动...')\n"," startTicks = time.time()\n"," time.sleep(5)\n"," _runing = True\n"," isInstall = True if os.getenv('IsInstall','False') == 'True' else False\n"," _proxy_path[_sub_path[0]] = f'http://127.0.0.1:{_server_port+1}/'\n"," _proxy_path[_sub_path[1]] = f'http://127.0.0.1:{_server_port+2}/'\n"," proxy_thread = threading.Thread(target = startProxy, daemon=True, name='solo_startProxy')\n"," proxy_thread.start()\n"," if isInstall is False or _reLoad: \n"," print('安装运行环境')\n"," install()\n"," link_dir()\n"," # init_huggingface() # 注释掉初始化huggingface\n"," install_optimizing()\n"," if not _skip_webui:\n"," threading.Thread(target = install_dependencies,daemon=True,name='solo_install_dependencies').start()\n"," else: \n"," envInstalled = True\n"," link_or_download_flie(replace_path(_async_downloading), _link_instead_of_copy=_link_instead_of_copy,\n"," base_path=f'{_install_path}/{_ui_dir_name}')\n"," \n"," # 注释掉huggingface同步相关代码\n"," # if huggingface_is_init:\n"," # threading.Thread(target = download__huggingface_repo,daemon=True,\n"," # args=([_huggingface_repo]),\n"," # kwargs={\"callback\":copy_last_log_to_images},\n"," # name='solo_download__huggingface_repo').start()\n"," \n"," link_or_download_flie(replace_path(_before_downloading), _link_instead_of_copy=_link_instead_of_copy,\n"," base_path=f'{_install_path}/{_ui_dir_name}',is_await=True,sync=True)\n"," t = 0\n"," while _runing and not envInstalled:\n"," if t%10==0:\n"," print('等待python环境安装...')\n"," t = t+1\n"," time.sleep(1)\n"," use_config()\n"," os.environ['IsInstall'] = 'True'\n"," else:\n"," envInstalled = True\n"," localProxy()\n"," link_or_download_flie(replace_path(_before_start_sync_downloading), _link_instead_of_copy=_link_instead_of_copy,\n"," base_path=f'{_install_path}/{_ui_dir_name}',sync=True)\n"," \n"," # 注释掉启动huggingface同步\n"," # if init_huggingface():\n"," # start_sync_log_to_huggingface(_huggingface_repo)\n"," \n"," ticks = time.time()\n"," _on_before_start()\n"," print(\"加载耗时:\",(ticks - startTicks),\"秒\")\n"," if _skip_webui:\n"," print('跳过webui启动')\n"," proxy_thread.join()\n"," else:\n"," start()"]},{"cell_type":"code","execution_count":3,"metadata":{},"outputs":[],"source":["# 入口函数部分修改\n","def main():\n"," global envInstalled\n"," global huggingface_is_init\n"," global _runing\n"," stop_solo_threads()\n"," print('启动...')\n"," startTicks = time.time()\n"," time.sleep(5)\n"," _runing = True\n"," isInstall = True if os.getenv('IsInstall','False') == 'True' else False\n"," _proxy_path[_sub_path[0]] = f'http://127.0.0.1:{_server_port+1}/'\n"," _proxy_path[_sub_path[1]] = f'http://127.0.0.1:{_server_port+2}/'\n"," proxy_thread = threading.Thread(target = startProxy, daemon=True, name='solo_startProxy')\n"," proxy_thread.start()\n"," if isInstall is False or _reLoad: \n"," print('安装运行环境')\n"," install()\n"," link_dir()\n"," # init_huggingface() # 注释掉初始化huggingface\n"," install_optimizing()\n"," if not _skip_webui:\n"," threading.Thread(target = install_dependencies,daemon=True,name='solo_install_dependencies').start()\n"," else: \n"," envInstalled = True\n"," link_or_download_flie(replace_path(_async_downloading), _link_instead_of_copy=_link_instead_of_copy,\n"," base_path=f'{_install_path}/{_ui_dir_name}')\n"," \n"," # 注释掉huggingface同步相关代码\n"," # if huggingface_is_init:\n"," # threading.Thread(target = download__huggingface_repo,daemon=True,\n"," # args=([_huggingface_repo]),\n"," # kwargs={\"callback\":copy_last_log_to_images},\n"," # name='solo_download__huggingface_repo').start()\n"," \n"," link_or_download_flie(replace_path(_before_downloading), _link_instead_of_copy=_link_instead_of_copy,\n"," base_path=f'{_install_path}/{_ui_dir_name}',is_await=True,sync=True)\n"," t = 0\n"," while _runing and not envInstalled:\n"," if t%10==0:\n"," print('等待python环境安装...')\n"," t = t+1\n"," time.sleep(1)\n"," use_config()\n"," os.environ['IsInstall'] = 'True'\n"," else:\n"," envInstalled = True\n"," localProxy()\n"," link_or_download_flie(replace_path(_before_start_sync_downloading), _link_instead_of_copy=_link_instead_of_copy,\n"," base_path=f'{_install_path}/{_ui_dir_name}',sync=True)\n"," \n"," # 注释掉启动huggingface同步\n"," # if init_huggingface():\n"," # start_sync_log_to_huggingface(_huggingface_repo)\n"," \n"," ticks = time.time()\n"," _on_before_start()\n"," print(\"加载耗时:\",(ticks - startTicks),\"秒\")\n"," if _skip_webui:\n"," print('跳过webui启动')\n"," proxy_thread.join()\n"," else:\n"," start()"]},{"cell_type":"code","execution_count":null,"metadata":{"_kg_hide-input":true,"id":"i3LhnwYHLCtC","trusted":true},"outputs":[],"source":["ngrokTokenFile = os.path.join(_input_path,'configs/ngrok_token.txt') # 非必填 存放ngrokToken的文件的路径\n","frpcConfigFile = os.path.join(_input_path,'configs/frpc_koishi.ini') # 非必填 frp 配置文件\n","# ss证书目录 下载nginx的版本,把pem格式改成crt格式\n","frpcSSLFFlies = [os.path.join(_input_path,'configs/koishi_ssl')]\n","if 'frp_ssl_dir' in locals() or 'frp_ssl_dir' in globals():\n"," frpcSSLFFlies = frpcSSLFFlies + config_reader(locals().get('frp_ssl_dir') or globals().get('frp_ssl_dir'))\n","# frpc 文件目录 如果目录不存在,会自动下载,也可以在数据集搜索 viyiviyi/utils 添加\n","frpcExePath = os.path.join(_input_path,'utils-tools/frpc')\n","# 其他需要加载的webui启动参数 写到【参数列表】这个配置去\n","otherArgs = '--xformers'\n","if 'sd_start_args' in locals() or 'sd_start_args' in globals():\n"," otherArgs = ' '.join([item for item in config_reader(locals().get('sd_start_args') or globals().get('sd_start_args')) if item != '--no-gradio-queue'])\n","venvPath = os.path.join(_input_path,'sd-webui-venv/venv.tar.bak') # 安装好的python环境 sd-webui-venv是一个公开是数据集 可以搜索添加\n","\n","# 用于使用kaggle api的token文件 参考 https://www.kaggle.com/docs/api\n","# 此文件用于自动上传koishi的相关配置 也可以用于保存重要的输出文件\n","kaggleApiTokenFile = os.path.join(_input_path,'configs/kaggle.json')\n","\n","requirements = []\n"]},{"cell_type":"code","execution_count":null,"metadata":{"_kg_hide-input":true,"id":"a_GtG2ayLCtD","trusted":true},"outputs":[],"source":["# 这下面的是用于初始化一些值或者环境变量的,轻易别改\n","_setting_file = replace_path(locals().get('setting_file') or globals().get('setting_file') or 'config.json')\n","\n","_ui_config_file = replace_path(locals().get('ui_config_file') or globals().get('ui_config_file') or 'ui-config.json')\n","\n","# 设置文件路径\n","if Path(f\"{os.environ['HOME']}/google_drive/MyDrive\").exists():\n"," if _setting_file == '/kaggle/working/configs/config.json':\n"," _setting_file = os.path.join(_output_path,'configs/config.json')\n"," if _ui_config_file == '/kaggle/working/configs/ui-config.json':\n"," _ui_config_file = os.path.join(_output_path,'configs/ui-config.json')\n"," \n","frpcStartArg = ''\n","freefrp_url = ''\n","_frp_temp_config_file = ''\n","_frp_config_or_file = replace_path(locals().get('frp_config_or_file') or globals().get('frp_config_or_file')) or frpcConfigFile\n","run(f'''mkdir -p {_install_path}/configFiles''')\n","if _frp_config_or_file:\n"," if '[common]' in _frp_config_or_file:\n"," echoToFile(_frp_config_or_file,f'{_install_path}/configFiles/temp_frpc_webui.ini')\n"," _frp_temp_config_file = f'{_install_path}/configFiles/temp_frpc_webui.ini'\n"," elif '.ini' in _frp_config_or_file:\n"," _frp_temp_config_file = _frp_config_or_file.strip()\n"," \n"," if _frp_temp_config_file:\n"," if Path(_frp_temp_config_file).exists():\n"," run(f'''cp -f {_frp_temp_config_file} {_install_path}/configFiles/frpc_webui.ini''')\n"," run(f'''sed -i \"s/local_port = .*/local_port = {_server_port}/g\" {_install_path}/configFiles/frpc_webui.ini''')\n"," frpcStartArg = f' -c {_install_path}/configFiles/frpc_webui.ini'\n"," elif _frp_config_or_file.strip().startswith('-f'):\n"," frpcStartArg = _frp_config_or_file.strip()\n"," \n","if not frpcStartArg:\n"," conf,url = get_freefrp_confog(_server_port)\n"," echoToFile(conf,f'{_install_path}/configFiles/frpc_webui.ini')\n"," freefrp_url = url\n"," frpcStartArg = f' -c {_install_path}/configFiles/frpc_webui.ini'\n","\n","ngrokToken=''\n","_ngrok_config_or_file = replace_path(locals().get('ngrok_config_or_file') or globals().get('ngrok_config_or_file')) or ngrokTokenFile\n","if _ngrok_config_or_file:\n"," if Path(_ngrok_config_or_file.strip()).exists():\n"," ngrokTokenFile = _ngrok_config_or_file.strip()\n"," if Path(ngrokTokenFile).exists():\n"," with open(ngrokTokenFile,encoding = \"utf-8\") as nkfile:\n"," ngrokToken = nkfile.readline()\n"," elif not _ngrok_config_or_file.strip().startswith('/'):\n"," ngrokToken=_ngrok_config_or_file.strip()\n"," \n","if not Path(venvPath).exists():\n"," venvPath = os.path.join(_input_path,'sd-webui-venv/venv.zip')\n"," \n","huggingface_headers:dict = None "]},{"cell_type":"markdown","metadata":{},"source":["## 文件下载工具\n","\n","---\n","\n","link_or_download_flie(config:str, skip_url:bool=False, _link_instead_of_copy:bool=True, base_path:str = '',sync:bool=False,thread_num:int=None)"]},{"cell_type":"code","execution_count":null,"metadata":{"trusted":true},"outputs":[],"source":["import concurrent.futures\n","import importlib\n","import os\n","import pprint\n","import re\n","from pathlib import Path\n","from typing import List\n","\n","import requests\n","\n","show_shell_info = False\n","\n","def is_installed(package):\n"," try:\n"," spec = importlib.util.find_spec(package)\n"," except ModuleNotFoundError:\n"," return False\n","\n"," return spec is not None\n","\n","def download_file(url:str, filename:str, dist_path:str, cache_path = '',_link_instead_of_copy:bool=True,headers={}):\n"," startTicks = time.time()\n"," # 获取文件的真实文件名\n"," if not filename:\n"," with requests.get(url, stream=True,headers=headers) as r:\n"," if 'Content-Disposition' in r.headers:\n"," filename = r.headers['Content-Disposition'].split('filename=')[1].strip('\"')\n"," r.close()\n"," if not filename and re.search(r'/[^/]+\\.[^/]+$',url):\n"," filename = url.split('/')[-1].split('?')[0]\n"," \n"," filename = re.sub(r'[\\\\/:*?\"<>|;]', '', filename)\n"," filename = re.sub(r'[\\s\\t]+', '_', filename)\n"," \n"," print(f'下载 {filename} url: {url} --> {dist_path}')\n"," \n"," # 创建目录\n"," if cache_path and not Path(cache_path).exists():\n"," os.makedirs(cache_path,exist_ok=True)\n"," if dist_path and not Path(dist_path).exists():\n"," os.makedirs(dist_path,exist_ok=True)\n"," \n"," # 拼接文件的完整路径\n"," filepath = os.path.join(dist_path, filename)\n","\n"," if cache_path:\n"," cache_path = os.path.join(cache_path, filename)\n"," \n"," # 判断文件是否已存在\n"," if Path(filepath).exists():\n"," print(f'文件 {filename} 已存在 {dist_path}')\n"," return\n"," \n"," if cache_path and Path(cache_path).exists():\n"," run(f'cp -n -r -f {\"-s\" if _link_instead_of_copy else \"\"} {cache_path} {dist_path}')\n"," print(f'文件缓存 {cache_path} --> {dist_path}')\n"," return\n"," # 下载文件\n"," size = 0\n"," with requests.get(url, stream=True, headers=headers) as r:\n"," r.raise_for_status()\n"," with open(cache_path or filepath, 'wb') as f:\n"," for chunk in r.iter_content(chunk_size=1024*1024):\n"," if chunk:\n"," size += len(chunk)\n"," f.write(chunk)\n"," # 如果使用了缓存目录 需要复制或链接文件到目标目录\n"," if cache_path:\n"," run(f'cp -n -r -f {\"-s\" if _link_instead_of_copy else \"\"} {cache_path} {dist_path}')\n"," ticks = time.time()\n"," print(f'下载完成 {filename} --> {dist_path} 大小{round(size/1024/1024,2)}M 耗时:{round(ticks - startTicks,2)}秒')\n"," \n","def download_git(url, dist_path, cache_path = '',_link_instead_of_copy:bool=True):\n"," if not Path(dist_path).exists():\n"," os.makedirs(dist_path,exist_ok=True)\n"," if show_shell_info:\n"," print(f'git 下载 {url} --> {dist_path}')\n"," if cache_path and not Path(cache_path).exists():\n"," os.makedirs(cache_path,exist_ok=True)\n"," run(f'git clone {url}',cwd = cache_path)\n"," if cache_path:\n"," run(f'cp -n -r -f {cache_path}/* {dist_path}')\n"," else:\n"," run(f'git clone {url}',cwd = dist_path)\n"," if show_shell_info:\n"," print(f'git 下载完成 {url} --> {dist_path}')\n"," \n"," \n","def download_huggingface(url:str, filename:str, dist_path, cache_path = '',_link_instead_of_copy:bool=True):\n"," fileReg = r'^https:\\/\\/huggingface.co(\\/([^\\/]+\\/)?[^\\/]+\\/[^\\/]+\\/(resolve|blob)\\/[^\\/]+\\/|[^\\.]+\\.[^\\.]+$|download=true)'\n"," def isFile(url:str):\n"," if re.match(fileReg,url):\n"," return True\n"," return False\n"," if isFile(url):\n"," download_file(url,filename,dist_path,cache_path,_link_instead_of_copy,headers=huggingface_headers)\n"," else:\n"," download_git(url,dist_path,cache_path,_link_instead_of_copy)\n"," \n","# 加入文件到下载列表\n","def pause_url(url:str,dist_path:str):\n"," file_name = ''\n"," if re.match(r'^[^:]+:(https?|ftps?)://', url, flags=0):\n"," file_name = re.findall(r'^[^:]+:',url)[0][:-1]\n"," url = url[len(file_name)+1:]\n"," if not re.match(r'^(https?|ftps?)://',url):\n"," return\n"," file_name = re.sub(r'\\s+','_',file_name or '')\n"," path_hash = str(hash(url)).replace('-','')\n"," \n"," return {'file_name':file_name,'path_hash':path_hash,'url':url,'dist_path':dist_path}\n","\n","def download_urls(download_list:List[dict],sync:bool=False,thread_num:int=5, \n"," cache_path:str=os.path.join(os.environ['HOME'],'.cache','download_util'),\n"," _link_instead_of_copy:bool=True,is_await:bool=False):\n"," if sync:\n"," for conf in download_list:\n"," cache_dir = os.path.join(cache_path,conf['path_hash'])\n"," if conf['url'].startswith('https://github.com'):\n"," try:\n"," download_git(conf['url'],conf['dist_path'],cache_path=cache_dir,_link_instead_of_copy=_link_instead_of_copy)\n"," except:\n"," pass\n"," continue\n"," if conf['url'].startswith('https://huggingface.co'):\n"," try:\n"," download_huggingface(conf['url'],conf['file_name'],conf['dist_path'],cache_path=cache_dir,_link_instead_of_copy=_link_instead_of_copy)\n"," except:\n"," pass\n"," continue\n"," if conf['url'].startswith('https://civitai.com'):\n"," if not re.search(r'token=.+', conf['url']):\n"," if conf['url'].find('?') == -1:\n"," conf['url'] = conf['url']+'?token=fee8bb78b75566eddfd04d061996185c'\n"," else:\n"," conf['url'] = conf['url']+'&token=fee8bb78b75566eddfd04d061996185c'\n"," try:\n"," download_file(conf['url'],conf['file_name'],conf['dist_path'],cache_path=cache_dir,_link_instead_of_copy=_link_instead_of_copy)\n"," except:\n"," pass\n"," else:\n"," executor = concurrent.futures.ThreadPoolExecutor(max_workers=thread_num)\n"," futures = []\n"," for conf in download_list:\n"," cache_dir = os.path.join(cache_path,conf['path_hash'])\n"," if conf['url'].startswith('https://github.com'):\n"," futures.append(executor.submit(download_git, conf['url'],conf['dist_path'],\n"," cache_path=cache_dir,_link_instead_of_copy=_link_instead_of_copy))\n"," continue\n"," if conf['url'].startswith('https://huggingface.co'):\n"," futures.append(executor.submit(download_huggingface,conf['url'],conf['file_name'],conf['dist_path'],cache_path=cache_dir,_link_instead_of_copy=_link_instead_of_copy))\n"," continue\n"," if conf['url'].startswith('https://civitai.com'):\n"," if not re.search(r'token=.+', conf['url']):\n"," if conf['url'].find('?') == -1:\n"," conf['url'] = conf['url']+'?token=fee8bb78b75566eddfd04d061996185c'\n"," else:\n"," conf['url'] = conf['url']+'&token=fee8bb78b75566eddfd04d061996185c'\n"," futures.append(executor.submit(download_file, conf['url'],conf['file_name'],conf['dist_path'],\n"," cache_path=cache_dir,_link_instead_of_copy=_link_instead_of_copy))\n"," if is_await:\n"," concurrent.futures.wait(futures)\n"," \n"," \n","def parse_config(config:str):\n"," space_string = ' \\n\\r\\t\\'\\\",'\n"," other_flie_list = [item.split('#')[0].strip(space_string) for item in config.split('\\n') if item.strip(space_string)]\n"," other_flie_list = [item.strip() for item in other_flie_list if item.strip()]\n"," other_flie_list_store = {}\n"," other_flie_list_store_name='default'\n"," other_flie_list_store_list_cache=[]\n"," \n"," for item in other_flie_list:\n"," if item.startswith('[') and item.endswith(']'):\n"," if not other_flie_list_store_name == 'default':\n"," other_flie_list_store[other_flie_list_store_name]=other_flie_list_store_list_cache\n"," other_flie_list_store_list_cache = []\n"," other_flie_list_store_name = item[1:-1]\n"," else:\n"," other_flie_list_store_list_cache.append(item)\n"," other_flie_list_store[other_flie_list_store_name]=other_flie_list_store_list_cache\n"," \n"," return other_flie_list_store\n","\n","\n","def link_or_download_flie(config:str, skip_url:bool=False, _link_instead_of_copy:bool=True, base_path:str = '',\n"," sync:bool=False,thread_num:int=None, is_await:bool=False):\n"," store:dict[str,List[str]] = parse_config(config)\n"," download_list = []\n"," for dist_dir in store.keys():\n"," dist_path = os.path.join(base_path,dist_dir)\n"," os.makedirs(dist_path,exist_ok=True)\n"," for path in store[dist_dir]:\n"," if 'https://' in path or 'http://' in path:\n"," if skip_url:\n"," continue\n"," if sync:\n"," try:\n"," download_urls([pause_url(path,dist_path)],_link_instead_of_copy = _link_instead_of_copy, sync=sync)\n"," except:\n"," pass\n"," continue\n"," download_list.append(pause_url(path,dist_path))\n"," else:\n"," run(f'cp -n -r -f {\"-s\" if _link_instead_of_copy else \"\"} {path} {dist_path}')\n"," if show_shell_info:\n"," print(f'{\"链接\" if _link_instead_of_copy else \"复制\"} {path} --> {dist_path}')\n"," run(f'rm -f {dist_path}/\\*.* ')\n"," if not skip_url:\n"," if show_shell_info:\n"," pprint.pprint(download_list)\n"," try:\n"," download_urls(download_list,_link_instead_of_copy = _link_instead_of_copy, sync=sync, thread_num=thread_num or 3,is_await=is_await)\n"," except:\n"," pass"]},{"cell_type":"markdown","metadata":{"id":"p0uS-BLULCtD"},"source":["## kaggle public API\n","\n","**不能使用%cd这种会改变当前工作目录的命令,会导致和其他线程冲突**\n","\n","---"]},{"cell_type":"code","execution_count":null,"metadata":{"_kg_hide-input":true,"id":"m8FJi4j0LCtD","trusted":true},"outputs":[],"source":["# 安装kaggle的api token文件\n","def initKaggleConfig():\n"," if Path('~/.kaggle/kaggle.json').exists():\n"," return True\n"," if Path(kaggleApiTokenFile).exists():\n"," run(f'''mkdir -p ~/.kaggle/''')\n"," run('cp '+kaggleApiTokenFile+' ~/.kaggle/kaggle.json')\n"," run(f'''chmod 600 ~/.kaggle/kaggle.json''')\n"," return True\n"," print('缺少kaggle的apiToken文件,访问:https://www.kaggle.com/你的kaggle用户名/account 获取')\n"," return False\n","\n","def getUserName():\n"," if not initKaggleConfig(): return\n"," import kaggle\n"," return kaggle.KaggleApi().read_config_file()['username']\n","\n","def createOrUpdateDataSet(path:str,datasetName:str):\n"," if not initKaggleConfig(): return\n"," print('创建或更新数据集 '+datasetName)\n"," import kaggle\n"," run(f'mkdir -p {_install_path}/kaggle_cache')\n"," run(f'rm -rf {_install_path}/kaggle_cache/*')\n"," datasetDirPath = _install_path+'/kaggle_cache/'+datasetName\n"," run('mkdir -p '+datasetDirPath)\n"," run('cp -f '+path+' '+datasetDirPath+'/')\n"," username = getUserName()\n"," print(\"kaggle username:\"+username)\n"," datasetPath = username+'/'+datasetName\n"," datasetList = kaggle.api.dataset_list(mine=True,search=datasetPath)\n"," print(datasetList)\n"," if len(datasetList) == 0 or datasetPath not in [str(d) for d in datasetList]: # 创建 create\n"," run('kaggle datasets init -p' + datasetDirPath)\n"," metadataFile = datasetDirPath+'/dataset-metadata.json'\n"," run('sed -i s/INSERT_TITLE_HERE/'+ datasetName + '/g ' + metadataFile)\n"," run('sed -i s/INSERT_SLUG_HERE/'+ datasetName + '/g ' + metadataFile)\n"," run('cat '+metadataFile)\n"," run('kaggle datasets create -p '+datasetDirPath)\n"," print('create database done')\n"," else:\n"," kaggle.api.dataset_metadata(datasetPath,datasetDirPath)\n"," kaggle.api.dataset_create_version(datasetDirPath, 'auto update',dir_mode='zip')\n"," print('upload database done')\n","\n","def downloadDatasetFiles(datasetName:str,outputPath:str):\n"," if not initKaggleConfig(): return\n"," print('下载数据集文件 '+datasetName)\n"," import kaggle\n"," username = getUserName()\n"," datasetPath = username+'/'+datasetName\n"," datasetList = kaggle.api.dataset_list(mine=True,search=datasetPath)\n"," if datasetPath not in [str(d) for d in datasetList]:\n"," return False\n"," run('mkdir -p '+outputPath)\n"," kaggle.api.dataset_download_files(datasetPath,path=outputPath,unzip=True)\n"," return True\n","\n"]},{"cell_type":"markdown","metadata":{},"source":["## 同步文件夹到 huggingface\n","\n","---"]},{"cell_type":"code","execution_count":4,"metadata":{},"outputs":[],"source":["def run(command, cwd=None, desc=None, errdesc=None, custom_env=None, try_error:bool=True) -> str:\n"," try:\n"," if desc:\n"," print(desc)\n"," \n"," result = subprocess.run(\n"," command,\n"," shell=True,\n"," cwd=cwd,\n"," env=os.environ if custom_env is None else custom_env,\n"," encoding='utf8',\n"," errors='ignore',\n"," stdout=subprocess.PIPE if not show_shell_info else None,\n"," stderr=subprocess.PIPE if not show_shell_info else None\n"," )\n"," \n"," if result.returncode != 0:\n"," raise RuntimeError(f\"\"\"\n"," {errdesc or 'Error running command'}.\n"," Command: {command}\n"," Error code: {result.returncode}\n"," stdout: {result.stdout or ''}\n"," stderr: {result.stderr or ''}\n"," \"\"\")\n"," \n"," return result.stdout or \"\"\n"," \n"," except Exception as e:\n"," if try_error:\n"," print(str(e))\n"," return \"\"\n"," raise"]},{"cell_type":"code","execution_count":5,"metadata":{},"outputs":[],"source":["def run(command, cwd=None, desc=None, errdesc=None, custom_env=None, try_error:bool=True) -> str:\n"," try:\n"," if desc:\n"," print(desc)\n"," \n"," result = subprocess.run(\n"," command,\n"," shell=True,\n"," cwd=cwd,\n"," env=os.environ if custom_env is None else custom_env,\n"," encoding='utf8',\n"," errors='ignore',\n"," stdout=subprocess.PIPE if not show_shell_info else None,\n"," stderr=subprocess.PIPE if not show_shell_info else None\n"," )\n"," \n"," if result.returncode != 0:\n"," raise RuntimeError(f\"\"\"\n"," {errdesc or 'Error running command'}.\n"," Command: {command}\n"," Error code: {result.returncode}\n"," stdout: {result.stdout or ''}\n"," stderr: {result.stderr or ''}\n"," \"\"\")\n"," \n"," return result.stdout or \"\"\n"," \n"," except Exception as e:\n"," if try_error:\n"," print(str(e))\n"," return \"\"\n"," raise"]},{"cell_type":"code","execution_count":6,"metadata":{},"outputs":[],"source":["class ThreadManager:\n"," _threads = []\n"," \n"," @classmethod\n"," def add_thread(cls, thread):\n"," if thread.name.startswith('solo_'):\n"," cls._threads.append(thread)\n"," \n"," @classmethod\n"," def stop_all(cls):\n"," for thread in cls._threads:\n"," try:\n"," stop_thread(thread)\n"," print(f'结束线程:{thread.name}')\n"," except Exception as e:\n"," print(f'结束线程:{thread.name} 执行失败: {str(e)}')\n"," cls._threads.clear()"]},{"cell_type":"code","execution_count":7,"metadata":{},"outputs":[],"source":["def get_path_manager():\n"," class PathManager:\n"," def __init__(self):\n"," self.install_path = Config.get('install_path')\n"," self.output_path = Config.get('output_path') \n"," self.input_path = Config.get('input_path')\n"," \n"," def ensure_dirs(self):\n"," \"\"\"确保所有必要的目录存在\"\"\"\n"," for path in [self.install_path, self.output_path]:\n"," os.makedirs(path, exist_ok=True)\n"," \n"," def get_webui_path(self):\n"," \"\"\"获取webui安装路径\"\"\"\n"," return os.path.join(self.install_path, Config.get('ui_dir_name'))\n"," \n"," def setup_env_vars(self):\n"," \"\"\"设置环境变量\"\"\"\n"," os.environ.update({\n"," 'install_path': self.install_path,\n"," 'output_path': self.output_path,\n"," 'input_path': self.input_path\n"," })\n"," \n"," return PathManager()"]},{"cell_type":"code","execution_count":8,"metadata":{},"outputs":[],"source":["class WebUIStarter:\n"," def __init__(self):\n"," self.path_manager = get_path_manager()\n"," self.running = False\n"," \n"," def pre_start_check(self):\n"," \"\"\"启动前检查\"\"\"\n"," check_gpu()\n"," self.path_manager.ensure_dirs()\n"," \n"," def start(self):\n"," \"\"\"启动主流程\"\"\"\n"," try:\n"," self.pre_start_check()\n"," self.running = True\n"," \n"," # 启动代理\n"," proxy_thread = threading.Thread(\n"," target=startProxy,\n"," daemon=True,\n"," name='solo_startProxy'\n"," )\n"," ThreadManager.add_thread(proxy_thread)\n"," proxy_thread.start()\n"," \n"," # 安装环境\n"," if not os.getenv('IsInstall') == 'True' or Config.get('reload'):\n"," self.install_environment()\n"," \n"," # 启动WebUI\n"," if not Config.get('skip_webui'):\n"," self.start_webui()\n"," \n"," except KeyboardInterrupt:\n"," self.stop()\n"," \n"," def stop(self):\n"," \"\"\"停止所有进程\"\"\"\n"," self.running = False\n"," ThreadManager.stop_all()"]},{"cell_type":"code","execution_count":9,"metadata":{},"outputs":[{"ename":"NameError","evalue":"name 'Config' is not defined","output_type":"error","traceback":["\u001b[1;31m---------------------------------------------------------------------------\u001b[0m","\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)","Cell \u001b[1;32mIn[9], line 10\u001b[0m\n\u001b[0;32m 4\u001b[0m logging\u001b[38;5;241m.\u001b[39mbasicConfig(\n\u001b[0;32m 5\u001b[0m level\u001b[38;5;241m=\u001b[39mlogging\u001b[38;5;241m.\u001b[39mINFO \u001b[38;5;28;01mif\u001b[39;00m Config\u001b[38;5;241m.\u001b[39mget(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mshow_shell_info\u001b[39m\u001b[38;5;124m'\u001b[39m) \u001b[38;5;28;01melse\u001b[39;00m logging\u001b[38;5;241m.\u001b[39mWARNING,\n\u001b[0;32m 6\u001b[0m \u001b[38;5;28mformat\u001b[39m\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;132;01m%(asctime)s\u001b[39;00m\u001b[38;5;124m - \u001b[39m\u001b[38;5;132;01m%(name)s\u001b[39;00m\u001b[38;5;124m - \u001b[39m\u001b[38;5;132;01m%(levelname)s\u001b[39;00m\u001b[38;5;124m - \u001b[39m\u001b[38;5;132;01m%(message)s\u001b[39;00m\u001b[38;5;124m'\u001b[39m\n\u001b[0;32m 7\u001b[0m )\n\u001b[0;32m 8\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m logging\u001b[38;5;241m.\u001b[39mgetLogger(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mwebui\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[1;32m---> 10\u001b[0m logger \u001b[38;5;241m=\u001b[39m \u001b[43msetup_logging\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n","Cell \u001b[1;32mIn[9], line 5\u001b[0m, in \u001b[0;36msetup_logging\u001b[1;34m()\u001b[0m\n\u001b[0;32m 3\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21msetup_logging\u001b[39m():\n\u001b[0;32m 4\u001b[0m logging\u001b[38;5;241m.\u001b[39mbasicConfig(\n\u001b[1;32m----> 5\u001b[0m level\u001b[38;5;241m=\u001b[39mlogging\u001b[38;5;241m.\u001b[39mINFO \u001b[38;5;28;01mif\u001b[39;00m \u001b[43mConfig\u001b[49m\u001b[38;5;241m.\u001b[39mget(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mshow_shell_info\u001b[39m\u001b[38;5;124m'\u001b[39m) \u001b[38;5;28;01melse\u001b[39;00m logging\u001b[38;5;241m.\u001b[39mWARNING,\n\u001b[0;32m 6\u001b[0m \u001b[38;5;28mformat\u001b[39m\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;132;01m%(asctime)s\u001b[39;00m\u001b[38;5;124m - \u001b[39m\u001b[38;5;132;01m%(name)s\u001b[39;00m\u001b[38;5;124m - \u001b[39m\u001b[38;5;132;01m%(levelname)s\u001b[39;00m\u001b[38;5;124m - \u001b[39m\u001b[38;5;132;01m%(message)s\u001b[39;00m\u001b[38;5;124m'\u001b[39m\n\u001b[0;32m 7\u001b[0m )\n\u001b[0;32m 8\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m logging\u001b[38;5;241m.\u001b[39mgetLogger(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mwebui\u001b[39m\u001b[38;5;124m'\u001b[39m)\n","\u001b[1;31mNameError\u001b[0m: name 'Config' is not defined"]}],"source":["import logging\n","\n","def setup_logging():\n"," logging.basicConfig(\n"," level=logging.INFO if Config.get('show_shell_info') else logging.WARNING,\n"," format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'\n"," )\n"," return logging.getLogger('webui')\n","\n","logger = setup_logging()"]},{"cell_type":"markdown","metadata":{"id":"sswa04veLCtE"},"source":["## 工具函数\n","**不能使用%cd这种会改变当前工作目录的命令,会导致和其他线程冲突**\n","\n","---"]},{"cell_type":"code","execution_count":null,"metadata":{"_kg_hide-input":true,"trusted":true},"outputs":[],"source":["\n","def zipPath(path:str,zipName:str,format='tar'):\n"," if path.startswith('$install_path'):\n"," path = path.replace('$install_path',_install_path)\n"," if path.startswith('$output_path'):\n"," path = path.replace('$install_path',_output_path)\n"," if not path.startswith('/'):\n"," path = f'{_install_path}/{_ui_dir_name}/{path}'\n"," if Path(path).exists():\n"," if 'tar' == format:\n"," run(f'tar -cf {_output_path}/'+ zipName +'.tar -C '+ path +' . ')\n"," elif 'gz' == format:\n"," run(f'tar -czf {_output_path}/'+ zipName +'.tar.gz -C '+ path +' . ')\n"," return\n"," print('指定的目录不存在:'+path)\n"]},{"cell_type":"markdown","metadata":{},"source":["## 内网穿透\n","\n","---"]},{"cell_type":"code","execution_count":null,"metadata":{"_kg_hide-input":true,"_kg_hide-output":true,"id":"coqQvTSLLCtE","trusted":true},"outputs":[],"source":["def printUrl(url,name=''):\n"," print(f'{name} 访问地址:{url}')\n"," for key in sorted(_proxy_path.keys(), key=len)[::-1]:\n"," print(f'{name} 本地服务:{_proxy_path[key]} 访问地址:{url}{key}')\n","# ngrok\n","def startNgrok(ngrokToken:str,ngrokLocalPort:int):\n"," if not is_installed('pyngrok'):\n"," run('pip install pyngrok')\n"," from pyngrok import conf, ngrok\n"," try:\n"," conf.get_default().auth_token = ngrokToken\n"," conf.get_default().monitor_thread = False\n"," ssh_tunnels = ngrok.get_tunnels(conf.get_default())\n"," url = ''\n"," if len(ssh_tunnels) == 0:\n"," ssh_tunnel = ngrok.connect(ngrokLocalPort)\n"," url = ssh_tunnel.public_url\n"," print('ngrok 访问地址:'+ssh_tunnel.public_url)\n"," else:\n"," print('ngrok 访问地址:'+ssh_tunnels[0].public_url)\n"," url = ssh_tunnels[0].public_url\n"," printUrl(url,'ngrok')\n"," def auto_request_ngrok():\n"," if url:\n"," while(_runing):\n"," time.sleep(60*1)\n"," try:\n"," res = requests.get(url+'/',headers={\"ngrok-skip-browser-warning\" : \"1\"},timeout=10)\n"," except:\n"," ''\n"," # print('自动调用ngrok链接以保存链接不会断开',res.status_code)\n","\n"," # threading.Thread(target = auto_request_ngrok,daemon=True,name='solo_auto_request_ngrok').start()\n"," except:\n"," print('启动ngrok出错')\n"," \n","def startFrpc(name,configFile):\n"," if not Path(f'{_install_path}/frpc/frpc').exists():\n"," installFrpExe()\n"," if freefrp_url:\n"," printUrl(freefrp_url,'freefrp')\n"," echoToFile(f'''\n","cd {_install_path}/frpc/\n","{_install_path}/frpc/frpc {configFile}\n","''',f'{_install_path}/frpc/start.sh')\n"," get_ipython().system(f'''bash {_install_path}/frpc/start.sh''')\n"," \n","def installFrpExe():\n"," if _useFrpc:\n"," print('安装frpc')\n"," run(f'mkdir -p {_install_path}/frpc')\n"," if Path(frpcExePath).exists():\n"," run(f'cp -f -n {frpcExePath} {_install_path}/frpc/frpc')\n"," else:\n"," run(f'wget \"https://huggingface.co/datasets/ACCA225/Frp/resolve/main/frpc\" -O {_install_path}/frpc/frpc')\n"," \n"," for ssl in frpcSSLFFlies:\n"," if Path(ssl).exists():\n"," run(f'cp -f -n {ssl}/* {_install_path}/frpc/')\n"," run(f'chmod +x {_install_path}/frpc/frpc')\n"," run(f'{_install_path}/frpc/frpc -v')\n","\n","def startProxy():\n"," if _useNgrok:\n"," startNgrok(ngrokToken,_server_port)\n"," if _useFrpc:\n"," startFrpc('frpc_proxy',frpcStartArg)"]},{"cell_type":"markdown","metadata":{},"source":["## NGINX 反向代理\n","\n","---"]},{"cell_type":"code","execution_count":null,"metadata":{"_kg_hide-input":true,"_kg_hide-output":true,"trusted":true},"outputs":[],"source":["\n","# nginx 反向代理配置文件\n","def localProxy():\n"," def getProxyLocation(subPath:str, localServer:str):\n"," return '''\n"," location '''+ subPath +'''\n"," {\n"," proxy_pass '''+ localServer +''';\n"," proxy_set_header REMOTE-HOST $remote_addr;\n"," proxy_buffering off;\n"," proxy_redirect off;\n"," proxy_connect_timeout 10m;\n"," proxy_read_timeout 10m;\n"," proxy_http_version 1.1;\n"," proxy_set_header Upgrade $http_upgrade;\n"," proxy_set_header Connection \"upgrade\";\n"," proxy_set_header Host $host;\n"," proxy_set_header X-Forwarded-Host $host;\n"," proxy_set_header X-Forwarded-Proto $scheme;\n"," proxy_set_header X-Real-IP $remote_addr;\n"," proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n"," }\n"," \n"," '''\n"," \n"," conf = '''\n","server\n","{\n"," listen '''+str(_server_port)+''';\n"," listen [::]:'''+str(_server_port)+''';\n"," server_name 127.0.0.1 localhost 0.0.0.0 \"\";\n"," \n"," if ($request_method = OPTIONS) {\n"," return 200;\n"," }\n"," fastcgi_send_timeout 10m;\n"," fastcgi_read_timeout 10m;\n"," fastcgi_connect_timeout 10m;\n"," \n"," '''+ ''.join([getProxyLocation(key,_proxy_path[key]) for key in sorted(_proxy_path.keys(), key=len)[::-1]]) +'''\n","}\n","'''\n"," echoToFile(conf,'/etc/nginx/conf.d/proxy_nginx.conf')\n"," if not check_service('localhost',_server_port):\n"," run(f'''nginx -c /etc/nginx/nginx.conf''')\n"," run(f'''nginx -s reload''')"]},{"cell_type":"markdown","metadata":{},"source":["## 线程清理工具\n","\n","---\n","\n","清理线程名以 solo_ 开头的所有线程"]},{"cell_type":"code","execution_count":null,"metadata":{"_kg_hide-input":true,"trusted":true},"outputs":[],"source":["import inspect\n","import ctypes\n","\n","def _async_raise(tid, exctype):\n"," \"\"\"raises the exception, performs cleanup if needed\"\"\"\n"," tid = ctypes.c_long(tid)\n"," if not inspect.isclass(exctype):\n"," exctype = type(exctype)\n"," res = ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, ctypes.py_object(exctype))\n"," if res == 0:\n"," raise ValueError(\"invalid thread id\")\n"," elif res != 1:\n"," # \"\"\"if it returns a number greater than one, you're in trouble,\n"," # and you should call it again with exc=NULL to revert the effect\"\"\"\n"," ctypes.pythonapi.PyThreadState_SetAsyncExc(tid, None)\n"," raise SystemError(\"PyThreadState_SetAsyncExc failed\")\n","\n","def stop_thread(thread):\n"," _async_raise(thread.ident, SystemExit)\n","\n","def stop_solo_threads():\n"," global _runing\n"," _runing = False\n"," # 获取当前所有活动的线程\n"," threads = threading.enumerate()\n"," # 关闭之前创建的子线程\n"," for thread in threads:\n"," if thread.name.startswith('solo_'):\n"," print(f'结束线程:{thread.name}')\n"," try:\n"," stop_thread(thread)\n"," except socket.error:\n"," print(f'结束线程:{thread.name} 执行失败')"]},{"cell_type":"markdown","metadata":{"id":"Ve3p8oOkLCtE"},"source":["# webui 安装和配置函数\n","---"]},{"cell_type":"code","execution_count":null,"metadata":{"_kg_hide-input":true,"id":"GTjyBJihLCtE","trusted":true},"outputs":[],"source":["envInstalled=False\n","quickStart = True\n","#安装\n","def install():\n"," print('安装')\n"," os.chdir(f'''{_install_path}''')\n"," run(f'''git lfs install''')\n"," run(f'''git config --global credential.helper store''')\n"," for requirement in requirements:\n"," run(f'pip install {requirement}')\n"," if _reLoad:\n"," run(f'''rm -rf {_install_path}/{_ui_dir_name}''')\n"," if Path(f\"{_ui_dir_name}\").exists():\n"," os.chdir(f'''{_install_path}/{_ui_dir_name}/''')\n"," run(f'''git checkout .''')\n"," run(f'''git pull''')\n"," else:\n"," run(f'''git clone --recursive {_sd_git_repo} {_ui_dir_name}''')\n"," if not Path(f'''{_install_path}/{_ui_dir_name}''').exists():\n"," print('sd-webui主程序安装失败,请检查 sd_git_repo 配置的值是否正确')\n"," sys.exit(0)\n"," os.chdir(f'''{_install_path}/{_ui_dir_name}''')\n"," print('安装 完成')\n","\n","# 链接输出目录\n","def link_dir():\n"," print('链接输出目录')\n"," # 链接图片输出目录\n"," run(f'''mkdir -p {_output_path}/outputs''')\n"," run(f'''rm -rf {_install_path}/{_ui_dir_name}/outputs''')\n"," run(f'''ln -s -r {_output_path}/outputs {_install_path}/{_ui_dir_name}/''')\n"," # 输出收藏目录\n"," run(f'''mkdir -p {_output_path}/log''')\n"," run(f'''rm -rf {_install_path}/{_ui_dir_name}/log''')\n"," run(f'''ln -s -r {_output_path}/log {_install_path}/{_ui_dir_name}/''')\n"," # 链接训练输出目录 文件夹链接会导致功能不能用\n"," run(f'''rm -rf {_install_path}/{_ui_dir_name}/textual_inversion''')\n"," run(f'''mkdir -p {_output_path}/textual_inversion/''')\n"," run(f'''ln -s -r {_output_path}/textual_inversion {_install_path}/{_ui_dir_name}/''')\n"," print('链接输出目录 完成') \n","\n","def install_optimizing():\n"," run('add-apt-repository ppa:deadsnakes/ppa -y')\n"," run('apt update -y')\n"," run('apt install nginx -y')\n"," run('apt install python3.11 -y')\n"," \n","#安装依赖\n","def install_dependencies():\n"," print('安装需要的python环境')\n"," import venv\n"," global envInstalled\n"," global venvPath\n"," if Path(f'{_install_path}/{_ui_dir_name}/venv').exists():\n"," print('跳过安装python环境')\n"," envInstalled = True\n"," return\n"," \n"," if quickStart:\n"," if not Path(venvPath).exists():\n"," mkdirs(f'{_install_path}/venv_cache',True)\n"," if not Path(f'{_install_path}/venv_cache/venv.tar.bak').exists():\n"," print('下载 venv.zip')\n"," download_file('https://huggingface.co/viyi/sdwui/resolve/main/venv.zip','venv.zip',f'{_install_path}/venv_cache')\n"," run(f'''unzip {_install_path}/venv_cache/venv.zip -d {_install_path}/venv_cache''')\n"," venvPath = f'{_install_path}/venv_cache/venv.tar.bak'\n"," run(f'''rm -rf {_install_path}/venv_cache/venv.zip''')\n"," elif venvPath.endswith('.zip'):\n"," mkdirs(f'{_install_path}/venv_cache',True)\n"," run(f'''unzip {venvPath} -d {_install_path}/venv_cache''')\n"," venvPath = f'{_install_path}/venv_cache/venv.tar.bak'\n"," print('解压环境')\n"," mkdirs(f'{_install_path}/{_ui_dir_name}/venv')\n","# run('python3.10 -m venv venv',cwd=f'{_install_path}/{_ui_dir_name}')\n"," run(f'tar -xf {venvPath} -C ./venv',cwd=f'{_install_path}/{_ui_dir_name}')\n"," run(f'rm -f {_install_path}/{_ui_dir_name}/venv/bin/pip*')\n"," run(f'rm -f {_install_path}/{_ui_dir_name}/venv/bin/python*')\n"," venv.create(f'{_install_path}/{_ui_dir_name}/venv')\n"," if not Path(f'{_install_path}/{_ui_dir_name}/venv/bin/pip').exists():\n"," run('curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py')\n"," run(f'{_install_path}/{_ui_dir_name}/venv/bin/python3 get-pip.py')\n","\n"," get_ipython().system(f'''{_install_path}/{_ui_dir_name}/venv/bin/python3 -V''')\n"," get_ipython().system(f'''{_install_path}/{_ui_dir_name}/venv/bin/python3 -m pip -V''')\n","\n"," envInstalled = True\n"," print('安装需要的python环境 完成')\n"," \n","# 个性化配置 \n","def use_config():\n"," print('使用自定义配置 包括tag翻译 \\n')\n"," run(f'''mkdir -p {_install_path}/temp''')\n"," run(f'git clone {_sd_config_git_repu} sd-configs',cwd=f'{_install_path}/temp')\n"," run(f'cp -r -f -n {_install_path}/temp/sd-configs/dist/* {_install_path}/{_ui_dir_name}')\n"," if not Path(_ui_config_file).exists() and _ui_config_file != 'ui-config.json': # ui配置文件\n"," run(f'''mkdir -p {_ui_config_file[:_ui_config_file.rfind('/')]}''')\n"," run(f'cp -f -n {_install_path}/{_ui_dir_name}/ui-config.json {_ui_config_file}')\n"," if not Path(_setting_file).exists() and _setting_file != 'config.json': # 设置配置文件\n"," run(f'''mkdir -p {_setting_file[:_setting_file.rfind('/')]}''')\n"," run(f'cp -f -n {_install_path}/{_ui_dir_name}/config.json {_setting_file}')\n","\n","def copy_last_log_to_images():\n"," if not Path(f'{_install_path}/{_ui_dir_name}/log/images').exists(): mkdirs(f'{_install_path}/{_ui_dir_name}/log/images')\n"," print('复制编号最大的一张收藏图到输出目录,用于保持编号,否则会出现收藏的图片被覆盖的情况')\n"," img_list = os.listdir(f'{_install_path}/{_ui_dir_name}/log/images')\n"," last_img_path = ''\n"," last_img_num = 0\n"," for img in img_list:\n"," if re.findall(r'^\\d+-',str(img)):\n"," num = int(re.findall(r'^\\d+-',str(img))[0][:-1])\n"," if num > last_img_num:\n"," last_img_path = img\n"," last_img_num = num\n"," \n"," if not last_img_path: return\n"," \n"," print(f'{_install_path}/{_ui_dir_name}/log/images/{last_img_path} {_install_path}/{_ui_dir_name}/outputs/txt2img-images')\n"," run(f'''mkdir -p {_install_path}/{_ui_dir_name}/outputs/txt2img-images''')\n"," run(f'''cp -f {_install_path}/{_ui_dir_name}/log/images/{last_img_path} {_install_path}/{_ui_dir_name}/outputs/txt2img-images/''')\n"," \n"," print(f'{_install_path}/{_ui_dir_name}/log/images/{last_img_path} {_install_path}/{_ui_dir_name}/outputs/img2img-images')\n"," run(f'''mkdir -p {_install_path}/{_ui_dir_name}/outputs/img2img-images''')\n"," run(f'''cp -f {_install_path}/{_ui_dir_name}/log/images/{last_img_path} {_install_path}/{_ui_dir_name}/outputs/img2img-images/''')\n"," \n","def start_webui(i):\n"," # 只要不爆内存,其他方式关闭后会再次重启 访问地址会发生变化\n"," print(i,'--port',str(_server_port+1+i))\n"," if i>0:\n"," print(f'使用第{i+1}张显卡启动第{i+1}个服务,通过frpc或nrgok地址后加{_sub_path[i]}进行访问')\n","\n"," restart_times = 0\n"," last_restart_time = time.time()\n"," while _runing:\n"," os.chdir(f'{_install_path}/{_ui_dir_name}')\n"," root_path = _sub_path[i]\n"," if root_path.endswith('/'): root_path = root_path[:-1]\n"," get_ipython().system(f'''venv/bin/python3 launch.py --device-id={i} --port {str(_server_port+1+i)} --subpath={_sub_path[i]}''')\n"," print('10秒后重启服务')\n"," if time.time() - last_restart_time < 60:\n"," restart_times = restart_times + 1\n"," else:\n"," restart_times = 0\n"," last_restart_time = time.time()\n"," if restart_times >3 :\n"," # 如果180秒内重启了3此,将不再自动重启\n"," break\n"," time.sleep(10)\n"," \n","# 启动\n","def start():\n"," print('启动webui')\n"," os.chdir(f'''{_install_path}/{_ui_dir_name}''')\n"," args = ''\n"," if _ui_config_file is not None and _ui_config_file != '' and Path(_ui_config_file).exists(): # ui配置文件\n"," args += ' --ui-config-file=' + _ui_config_file\n"," if _setting_file is not None and _setting_file != '' and Path(_setting_file).exists(): # 设置配置文件\n"," args += ' --ui-settings-file=' + _setting_file\n"," args += ' ' + otherArgs\n"," os.environ['COMMANDLINE_ARGS']=args\n"," run(f'''echo COMMANDLINE_ARGS=$COMMANDLINE_ARGS''')\n"," os.environ['REQS_FILE']='requirements_versions.txt'\n","\n"," with concurrent.futures.ThreadPoolExecutor(max_workers=2) as executor:\n"," for i in range(torch.cuda.device_count() if _multi_case else 1):\n"," executor.submit(start_webui,i)\n"," while _runing and not check_service('localhost',str(_server_port+1+i)): # 当当前服务启动完成才允许退出此次循环\n"," time.sleep(5)\n"," if not _runing: break\n"," time.sleep(10)"]},{"cell_type":"markdown","metadata":{"id":"qLvsk8ByLCtF"},"source":["# 入口函数\n","---"]},{"cell_type":"code","execution_count":null,"metadata":{"_kg_hide-input":true,"id":"IOKjaMlcLCtF","trusted":true},"outputs":[],"source":["\n","# 启动非webui相关的的内容,加快启动速度\n","def main():\n"," global envInstalled\n"," global huggingface_is_init\n"," global _runing\n"," stop_solo_threads()\n"," print('启动...')\n"," startTicks = time.time()\n"," time.sleep(5)\n"," _runing = True\n"," isInstall = True if os.getenv('IsInstall','False') == 'True' else False\n"," _proxy_path[_sub_path[0]] = f'http://127.0.0.1:{_server_port+1}/'\n"," _proxy_path[_sub_path[1]] = f'http://127.0.0.1:{_server_port+2}/'\n"," proxy_thread = threading.Thread(target = startProxy, daemon=True, name='solo_startProxy')\n"," proxy_thread.start()\n"," if isInstall is False or _reLoad: \n"," print('安装运行环境')\n"," install()\n"," link_dir()\n"," init_huggingface()\n"," install_optimizing()\n"," if not _skip_webui:\n"," threading.Thread(target = install_dependencies,daemon=True,name='solo_install_dependencies').start()\n"," else: envInstalled = True\n"," link_or_download_flie(replace_path(_async_downloading), _link_instead_of_copy=_link_instead_of_copy,\n"," base_path=f'{_install_path}/{_ui_dir_name}')\n"," if huggingface_is_init:\n"," threading.Thread(target = download__huggingface_repo,daemon=True,\n"," args=([_huggingface_repo]),\n"," kwargs={\"callback\":copy_last_log_to_images},\n"," name='solo_download__huggingface_repo').start()\n"," \n"," link_or_download_flie(replace_path(_before_downloading), _link_instead_of_copy=_link_instead_of_copy,\n"," base_path=f'{_install_path}/{_ui_dir_name}',is_await=True,sync=True)\n"," t = 0\n"," while _runing and not envInstalled:\n"," if t%10==0:\n"," print('等待python环境安装...')\n"," t = t+1\n"," time.sleep(1)\n"," use_config()\n"," os.environ['IsInstall'] = 'True'\n"," else:\n"," envInstalled = True\n"," localProxy()\n"," link_or_download_flie(replace_path(_before_start_sync_downloading), _link_instead_of_copy=_link_instead_of_copy,\n"," base_path=f'{_install_path}/{_ui_dir_name}',sync=True)\n"," if init_huggingface():\n"," start_sync_log_to_huggingface(_huggingface_repo)\n"," ticks = time.time()\n"," _on_before_start()\n"," print(\"加载耗时:\",(ticks - startTicks),\"秒\")\n"," if _skip_webui:\n"," print('跳过webui启动')\n"," proxy_thread.join()\n"," else:\n"," start()\n"]},{"cell_type":"markdown","metadata":{"id":"0oaCRs2gLCtF"},"source":["# 执行区域\n","---"]},{"cell_type":"code","execution_count":null,"metadata":{"_kg_hide-output":true,"id":"O3DR0DWHLCtF","scrolled":true,"trusted":true},"outputs":[],"source":["# 启动\n","# _reLoad = True\n","# hidden_console_info = False\n","# run_by_none_device = True\n","# show_shell_info = True\n","\n","print(f'当前sd的安装路径是:{_install_path}/{_ui_dir_name}')\n","print(f'当前图片保存路径是:{_output_path}')\n","print(f'当前数据集路径是:{_input_path}')\n","\n","print(update_desc)\n","\n","if _skip_start:\n"," print('已跳过自动启动,可手动执行 main() 进行启动。')\n"," print('''推荐的启动代码:\n","try:\n"," check_gpu() # 检查是否存在gpu\n"," main()\n","except KeyboardInterrupt:\n"," stop_solo_threads() # 中断后自动停止后台线程 (有部分功能在后台线程中运行)\n"," ''')\n","else:\n"," try:\n"," check_gpu()\n"," main()\n"," except KeyboardInterrupt:\n"," stop_solo_threads()"]},{"cell_type":"code","execution_count":null,"metadata":{"trusted":true},"outputs":[],"source":[]}],"metadata":{"kaggle":{"accelerator":"nvidiaTeslaT4","dataSources":[{"datasetId":2716934,"sourceId":6167400,"sourceType":"datasetVersion"},{"datasetId":3654544,"sourceId":6346544,"sourceType":"datasetVersion"},{"datasetId":2962375,"sourceId":6720235,"sourceType":"datasetVersion"},{"datasetId":3074484,"sourceId":6817788,"sourceType":"datasetVersion"}],"isGpuEnabled":true,"isInternetEnabled":true,"language":"python","sourceType":"notebook"},"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.12.4"}},"nbformat":4,"nbformat_minor":4}
|
stable-diffusion-webui-comfyui.ipynb
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"cells":[{"cell_type":"markdown","metadata":{},"source":["- 这是一个sd webui启动笔记,启动快速、配置灵活简单,可以免费快速的使用AI绘画。 \n","- kaggle和colab都是AI学习平台,请勿浪费计算资源,如果有需求,可以考虑AutoDL这类租用显卡的平台或者colab付费使用。\n","- 在保持可以免配置直接启动的情况下也提供了很多可自定义的配置,在下方的配置项里,请自行查看。 \n","- 需要安装插件或者下载文件到指定目录,只需要在下方的文件下载列表内写上目标目录和下载链接即可。\n","- 同时安装了ComfyUI,与webui共用大部分模型,通过访问url后加 `/` 和 `/1/` 访问webui,通过加 `/cui/` 和 `/cui2/` 访问ComfyUI。\n","- 安装有文件管理器,通过访问url后加 `/fslist/` 来访问,默认账号`admin`密码`admin`。\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","- 使用前可以看一下最后的更新日志,可能有功能更新需要注意,有些功能更新在启动后的输出里面可以看见\n","- 这里可以下载用于查看和解密加密后图片的软件 https://github.com/viyiviyi/encrypt_gallery/releases/\n","- 发布地址 [kaggle stable-diffusion-webui-novelai](https://www.kaggle.com/code/yiyiooo/stable-diffusion-webui-novelai)\n","- [stable-diffusion-webui 项目地址](https://github.com/AUTOMATIC1111/stable-diffusion-webui) \n","\n","## !!!!重要提示:如果要使用Comfyui,请一定要将 `use_comfyui` 配置改为True \n","\n","#### sd webui版本\n","\n","**version: v1.10.0 • python: 3.10.13 • torch: 2.3.0+cu121 • xformers: 0.0.26 • gradio: 3.41.2**\n"]},{"cell_type":"code","execution_count":1,"metadata":{},"outputs":[],"source":["# ... existing code ...\n","\n","# 注释 ComfyUI 相关配置\n","# _use_comfyui = locals().get('use_comfyui') or globals().get('use_comfyui') or False\n","# if _use_comfyui:\n","# _sub_path = ['/webui/','/webui2/'] \n","# _proxy_path['/'] = 'http://127.0.0.1:8188/'\n","# _proxy_path['/cui/'] = 'http://127.0.0.1:8189/'\n","# _proxy_path['/cui2/'] = 'http://127.0.0.1:8190/'\n","\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","# # ... 其他 ComfyUI 相关代码 ...\n","\n","def main():\n"," global envInstalled\n"," global huggingface_is_init\n"," global _runing\n"," stop_solo_threads()\n"," print('启动...')\n"," startTicks = time.time()\n"," time.sleep(5)\n"," _runing = True\n"," isInstall = True if os.getenv('IsInstall','False') == 'True' else False\n"," _proxy_path[_sub_path[0]] = f'http://127.0.0.1:{_server_port+1}/'\n"," _proxy_path[_sub_path[1]] = f'http://127.0.0.1:{_server_port+2}/'\n"," proxy_thread = threading.Thread(target = startProxy, daemon=True, name='solo_startProxy')\n"," proxy_thread.start()\n"," if isInstall is False or _reLoad:\n"," print('安装运行环境')\n"," install()\n"," link_dir()\n"," install_optimizing()\n"," if not _skip_webui:\n"," threading.Thread(target = install_dependencies,daemon=True,name='solo_install_dependencies').start()\n"," else:\n"," envInstalled = True\n"," link_or_download_flie(replace_path(_async_downloading), _link_instead_of_copy=_link_instead_of_copy,\n"," base_path=f'{_install_path}/{_ui_dir_name}')\n"," \n"," link_or_download_flie(replace_path(_before_downloading), _link_instead_of_copy=_link_instead_of_copy,\n"," base_path=f'{_install_path}/{_ui_dir_name}',is_await=True,sync=True)\n"," t = 0\n"," while _runing and not envInstalled:\n"," if t%10==0:\n"," print('等待python环境安装...')\n"," t = t+1\n"," time.sleep(1)\n"," use_config()\n"," os.environ['IsInstall'] = 'True'\n"," else:\n"," envInstalled = True\n"," localProxy()\n"," link_or_download_flie(replace_path(_before_start_sync_downloading), _link_instead_of_copy=_link_instead_of_copy,\n"," base_path=f'{_install_path}/{_ui_dir_name}',sync=True)\n"," \n"," ticks = time.time()\n"," _on_before_start()\n"," print(\"加载耗时:\",(ticks - startTicks),\"秒\")\n"," if _skip_webui:\n"," print('跳过webui启动')\n"," proxy_thread.join()\n"," else:\n"," start()\n","\n","# 注释掉 on_before_start 中的 ComfyUI 启动\n","def _on_before_start():\n"," if locals().get('on_before_start'):\n"," on_before_start()\n"," # if _use_comfyui:\n"," # threading.Thread(target = start_comfyui, daemon=True, name='solo_start_comfyui').start()\n","\n","# ... existing code ..."]},{"cell_type":"code","execution_count":2,"metadata":{},"outputs":[],"source":["class Config:\n"," \"\"\"统一管理配置项\"\"\"\n"," def __init__(self):\n"," self.server_port = 7860\n"," self.sub_path = ['/', '/1/']\n"," self.proxy_path = {}\n"," self.install_path = self._get_install_path()\n"," self.output_path = self._get_output_path()\n"," self.input_path = self._get_input_path()\n"," self.ui_dir_name = 'sd_main_dir'\n"," self.skip_webui = False\n"," self.link_instead_of_copy = True\n"," self.hidden_console_info = True\n"," \n"," def _get_install_path(self):\n"," return f\"/kaggle\" if os.path.exists('/kaggle/') else f\"{os.environ['HOME']}/sd_webui\"\n"," \n"," def _get_output_path(self):\n"," return '/kaggle/working' if os.path.exists('/kaggle/working/') else f\"{os.environ['HOME']}/.sdwui/Output\"\n"," \n"," def _get_input_path(self):\n"," return '/kaggle/input'"]},{"cell_type":"code","execution_count":3,"metadata":{},"outputs":[],"source":["class FileManager:\n"," \"\"\"管理文件下载和链接\"\"\"\n"," def __init__(self, config):\n"," self.config = config\n"," \n"," def link_or_download(self, file_list, base_path, is_await=False, sync=False):\n"," \"\"\"统一处理文件下载和链接\"\"\"\n"," if not file_list:\n"," return\n"," \n"," tasks = self._parse_file_list(file_list)\n"," \n"," if sync:\n"," for task in tasks:\n"," self._process_task(task, base_path)\n"," else:\n"," threads = []\n"," for task in tasks:\n"," thread = threading.Thread(\n"," target=self._process_task,\n"," args=(task, base_path),\n"," daemon=True\n"," )\n"," threads.append(thread)\n"," thread.start()\n"," \n"," if is_await:\n"," for thread in threads:\n"," thread.join()\n"," \n"," def _parse_file_list(self, file_list):\n"," \"\"\"解析文件列表配置\"\"\"\n"," # 实现文件列表解析逻辑\n"," pass\n"," \n"," def _process_task(self, task, base_path):\n"," \"\"\"处理单个下载/链接任务\"\"\"\n"," # 实现具体的下载或链接逻辑\n"," pass"]},{"cell_type":"code","execution_count":4,"metadata":{},"outputs":[],"source":["class ProxyManager:\n"," \"\"\"管理代理服务\"\"\"\n"," def __init__(self, config):\n"," self.config = config\n"," self.proxy_thread = None\n"," \n"," def start_proxy(self):\n"," \"\"\"启动代理服务\"\"\"\n"," self.proxy_thread = threading.Thread(\n"," target=self._run_proxy,\n"," daemon=True,\n"," name='solo_startProxy'\n"," )\n"," self.proxy_thread.start()\n"," \n"," def _run_proxy(self):\n"," \"\"\"运行代理服务的具体实现\"\"\"\n"," # 实现代理服务逻辑\n"," pass"]},{"cell_type":"code","execution_count":5,"metadata":{},"outputs":[],"source":["class WebUILauncher:\n"," \"\"\"WebUI启动器\"\"\"\n"," def __init__(self):\n"," self.config = Config()\n"," self.file_manager = FileManager(self.config)\n"," self.proxy_manager = ProxyManager(self.config)\n"," self.running = False\n"," \n"," def start(self):\n"," \"\"\"启动主程序\"\"\"\n"," try:\n"," print('启动...')\n"," start_ticks = time.time()\n"," self.running = True\n"," \n"," # 启动代理\n"," self.proxy_manager.start_proxy()\n"," \n"," # 安装环境\n"," if self._need_install():\n"," self._install_environment()\n"," \n"," # 下载/链接文件\n"," self._handle_files()\n"," \n"," # 启动WebUI\n"," if not self.config.skip_webui:\n"," self._start_webui()\n"," \n"," print(f\"加载耗时: {time.time() - start_ticks} 秒\")\n"," \n"," except KeyboardInterrupt:\n"," self.stop()\n"," \n"," def stop(self):\n"," \"\"\"停止所有服务\"\"\"\n"," self.running = False\n"," stop_solo_threads()\n"," \n"," def _need_install(self):\n"," \"\"\"检查是否需要安装\"\"\"\n"," return os.getenv('IsInstall', 'False') != 'True' or globals().get('_reLoad')\n"," \n"," def _install_environment(self):\n"," \"\"\"安装环境\"\"\"\n"," print('安装运行环境')\n"," # 实现环境安装逻辑\n"," \n"," def _handle_files(self):\n"," \"\"\"处理文件下载和链接\"\"\"\n"," # 实现文件处理逻辑\n"," \n"," def _start_webui(self):\n"," \"\"\"启动WebUI\"\"\"\n"," # 实现WebUI启动逻辑"]},{"cell_type":"code","execution_count":6,"metadata":{},"outputs":[],"source":["class WebUIError(Exception):\n"," \"\"\"WebUI相关错误的基类\"\"\"\n"," pass\n"," \n","class InstallationError(WebUIError):\n"," \"\"\"安装过程中的错误\"\"\"\n"," pass\n"," \n","class FileProcessError(WebUIError):\n"," \"\"\"文件处理过程中的错误\"\"\"\n"," pass\n","\n","def error_handler(func):\n"," \"\"\"错误处理装饰器\"\"\"\n"," @functools.wraps(func)\n"," def wrapper(*args, **kwargs):\n"," try:\n"," return func(*args, **kwargs)\n"," except WebUIError as e:\n"," logging.error(f\"WebUI错误: {str(e)}\")\n"," raise\n"," except Exception as e:\n"," logging.error(f\"未预期的错误: {str(e)}\")\n"," raise WebUIError(f\"执行{func.__name__}时发生错误: {str(e)}\")\n"," return wrapper"]},{"cell_type":"markdown","metadata":{},"source":["## 重要文件列表\n","\n","- **这个列表仅加载一次 且会等待加载完成再开始安装其他环境,为减少故障,会按照顺序进行加载**\n","- ```[]```内的是下载文件的目标目录,可以是相对目录也可以是绝对路径\n","- ```[]```的下一行就是文件列表,可以是下载地址、git仓库、文件路径、文件夹路径,且支持通配符\n","- 如果需要对下载的文件重命名,可以在下载链接前面写上文件名后加一个```:```分开文件名和下载地址\n","- 如果需要下载到其他目录,可以使用同样的格式写其他目录"]},{"cell_type":"code","execution_count":1,"metadata":{"execution":{"iopub.execute_input":"2024-10-22T14:40:05.367057Z","iopub.status.busy":"2024-10-22T14:40:05.366729Z","iopub.status.idle":"2024-10-22T14:40:05.380898Z","shell.execute_reply":"2024-10-22T14:40:05.379824Z","shell.execute_reply.started":"2024-10-22T14:40:05.367022Z"},"trusted":true},"outputs":[],"source":["before_downloading = '''# 这个列表仅加载一次 且会等待加载完成再开始安装其他环境\n","[extensions] # 插件 如果你需要增加插件,把插件地址写到这来就行,支持git仓库和文件夹路径\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/sd-encrypt-image.git # 图片加密插件,解决涩图封号问题,需要在参数里设置你的密码开启\n","https://github.com/viyiviyi/Stable-Diffusion-Webui-Civitai-Helper.git # 修改过的c站助手,下载的缩略图可以被加密插件加密\n","https://github.com/viyiviyi/sd-civitai-browser-plus.git # 修改过的c站浏览器,下载的缩略图可以被加密插件加密\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/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/mcmonkeyprojects/sd-dynamic-thresholding.git\n","# https://github.com/viyiviyi/prompts-filter.git z_prompts-filter # 这个插件可以解决一些tag异常\n","\n","# 如果你有模型文件需要在启动前加载,可以写在这个下面对应位置\n","\n","[models/Stable-diffusion] # 大模型列表\n","\n","[models/hypernetworks] # hypernetworks文件列表\n","\n","[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 -b v0.2.3 # confyui主分支不一定可以启动,当有新版本时请手动更换版本号(tag)\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","\n","[{install_path}/ComfyUI/custom_nodes/ComfyUI-Impact-Pack]\n","https://github.com/ltdrdata/ComfyUI-Impact-Subpack impact_subpack\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","- ```[]```内的是下载文件的目标目录,可以是相对目录也可以是绝对路径\n","- ```[]```的下一行就是文件列表,可以是下载地址、git仓库、文件路径、文件夹路径,且支持通配符\n","- 如果需要对下载的文件重命名,可以在下载链接前面写上文件名后加一个```:```分开文件名和下载地址\n","- 如果需要下载到其他目录,可以使用同样的格式写其他目录\n","- **这些文件启动webui后可能还没下载完成,需要自行刷新列表查看是否下载完成,如果介意,就把需要下载的内容移动到下一个配置**"]},{"cell_type":"code","execution_count":2,"metadata":{"execution":{"iopub.execute_input":"2024-10-22T14:40:05.383827Z","iopub.status.busy":"2024-10-22T14:40:05.383386Z","iopub.status.idle":"2024-10-22T14:40:05.397380Z","shell.execute_reply":"2024-10-22T14:40:05.396519Z","shell.execute_reply.started":"2024-10-22T14:40:05.383784Z"},"trusted":true},"outputs":[],"source":["async_downloading='''# 这个列表仅加载一次 且不会等待加载完成\n","[extensions] # 插件 建议不要把插件放在这里加载,因为这里的文件可能在webui启动后才加载完成\n","\n","[models/ESRGAN]\n","https://huggingface.co/lokCX/4x-Ultrasharp/resolve/main/4x-UltraSharp.pth?download=true\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","https://huggingface.co/stabilityai/sd-vae-ft-ema-original/resolve/main/vae-ft-ema-008400-ema-pruned.safetensors?download=true\n","# https://huggingface.co/WarriorMama777/OrangeMixs/resolve/main/VAEs/orangemix.vae.pt\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","/kaggle/input/anime-xl/animagineXLV3_v30.safetensors # 动漫SDXL大模型 如果需要,把链接前面的#删掉\n","# https://civitai.com/api/download/models/176425\n","\n","[models/hypernetworks] # hypernetworks文件列表\n","\n","[embeddings] # embeddings文件列表\n","\n","[models/Lora] # Lora文件列表\n","# Genshin_Impact_all-in-one.safetensors: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插件的模型列表 因为下载耗时,所以默认不下载大部分controlnet模型\n","# https://huggingface.co/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11e_sd15_ip2p_fp16.safetensors?download=true\n","# https://huggingface.co/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11e_sd15_shuffle_fp16.safetensors?download=true\n","# https://huggingface.co/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11f1e_sd15_tile_fp16.safetensors?download=true\n","# https://huggingface.co/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11f1p_sd15_depth_fp16.safetensors?download=true\n","https://huggingface.co/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11p_sd15_canny_fp16.safetensors?download=true\n","# https://huggingface.co/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11p_sd15_inpaint_fp16.safetensors?download=true\n","# https://huggingface.co/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11p_sd15_lineart_fp16.safetensors?download=true\n","# https://huggingface.co/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11p_sd15_mlsd_fp16.safetensors?download=true\n","# https://huggingface.co/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11p_sd15_normalbae_fp16.safetensors?download=true\n","# https://huggingface.co/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11p_sd15_openpose_fp16.safetensors?download=true\n","# https://huggingface.co/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11p_sd15_scribble_fp16.safetensors?download=true\n","# https://huggingface.co/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11p_sd15_seg_fp16.safetensors?download=true\n","# https://huggingface.co/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11p_sd15_softedge_fp16.safetensors?download=true\n","# https://huggingface.co/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11p_sd15s2_lineart_anime_fp16.safetensors?download=true\n","# https://huggingface.co/comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11u_sd15_tile_fp16.safetensors?download=true\n","\n","[extensions/animatediff/model] # animatediff 插件基本模型\n","# https://huggingface.co/guoyww/animatediff/resolve/cd71ae134a27ec6008b968d6419952b0c0494cf2/mm_sd_v15.ckpt?download=true\n","# https://huggingface.co/guoyww/animatediff/resolve/cd71ae134a27ec6008b968d6419952b0c0494cf2/mm_sd_v15_v2.ckpt?download=true\n","\n","[models/Lora/animatediff] # animatediff lora模型\n","# https://huggingface.co/guoyww/animatediff/resolve/cd71ae134a27ec6008b968d6419952b0c0494cf2/v2_lora_PanLeft.ckpt?download=true\n","\n","\n","'''\n"]},{"cell_type":"markdown","metadata":{},"source":["## 按顺序加载的重要文件列表\n","\n","- **这个列表每次 run all 启动都会加载一次,且一定按照顺序加载后才启动webui**\n","- ```[]```内的是下载文件的目标目录,可以是相对目录也可以是绝对路径\n","- ```[]```的下一行就是文件列表,可以是下载地址、git仓库、文件路径、文件夹路径,且支持通配符\n","- 如果需要对下载的文件重命名,可以在下载链接前面写上文件名后加一个```:```分开文件名和下载地址\n","- 如果需要下载到其他目录,可以使用同样的格式写其他目录"]},{"cell_type":"code","execution_count":3,"metadata":{"execution":{"iopub.execute_input":"2024-10-22T14:40:05.399370Z","iopub.status.busy":"2024-10-22T14:40:05.399004Z","iopub.status.idle":"2024-10-22T14:40:05.410786Z","shell.execute_reply":"2024-10-22T14:40:05.409999Z","shell.execute_reply.started":"2024-10-22T14:40:05.399328Z"},"trusted":true},"outputs":[],"source":["before_start_sync_downloading = ''' # 这个列表每次 run all 启动都会加载一次,且一定按照顺序加载\n","\n","# 如果你需要每次启动都加载一下文件,可以写在这。(比如测试路径是否正确的时候)\n","\n","[models/Stable-diffusion] # 大模型列表\n","\n","[models/hypernetworks] # hypernetworks文件列表\n","\n","[embeddings] # embeddings文件列表\n","\n","[models/Lora] # Lora文件列表\n","\n","[models/VAE] # VAE文件列表\n","\n","[extensions/sd-webui-controlnet/models] # controlnet插件的模型列表\n","\n","'''\n","\n"]},{"cell_type":"markdown","metadata":{},"source":["### 重要配置,一般情况下不需要改"]},{"cell_type":"code","execution_count":4,"metadata":{"execution":{"iopub.execute_input":"2024-10-22T14:40:05.521535Z","iopub.status.busy":"2024-10-22T14:40:05.521193Z","iopub.status.idle":"2024-10-22T14:40:05.529140Z","shell.execute_reply":"2024-10-22T14:40:05.528195Z","shell.execute_reply.started":"2024-10-22T14:40:05.521493Z"},"trusted":true},"outputs":[],"source":["useGooglrDrive = True # 连接到谷歌云盘 在google colab环境才会生效\n","#Ngrok\n","useNgrok=True # 非必填 是否使用ngrok作为公网访问地址\n","#frp内网穿透\n","useFrpc=True # 开启frp 如果ngrok和frp都不开,将不能访问webui\n","\n","#ngrok token 可以填写文件路径或直接填 token 内容 (替换一整行)\n","ngrok_config_or_file = '''\n","{input_path}/configs/ngrok_token.txt\n","'''\n","# frp配置 配置文件路径或者参数 或者配置内容 如果不填,将会使用免费的freefrp(不保证可用)\n","# 替换内容时请替换 {input_path}/configs/frpc_litechat.ini 这一整行\n","frp_config_or_file = '''\n","{input_path}/configs/frpc_litechat.ini3\n","'''\n","# frp用的域名证书所在目录\n","frp_ssl_dir = '''\n","{input_path}/configs/litechat_nginx\n","'''\n","\n","# 这个是字符串替换配置,可以将键值对的键替换成值,对以上的所有字符串内容生效\n","config_args = {}\n","\n","# 配置启动参数\n","server_port=7860 # webui 默认端口\n","\n","# 仓库地址 默认是是修改过界面布局顺序的webui,更适合手机使用,不定期同步到官方版本\n","# 如果要使用官方版本或其他版本,启用下面的或者自己该,正常情况下都是可以启动的\n","sd_git_repo='https://github.com/viyiviyi/stable-diffusion-webui.git -b local-1.9' # 手机界面优化\n","# sd_git_repo='https://github.com/AUTOMATIC1111/stable-diffusion-webui.git' # 官方原本\n","# sd_git_repo='https://github.com/lllyasviel/stable-diffusion-webui-forge.git' # forge版本,据说出图更快\n","\n","# 配置文件,包括webui的设置和UI默认值,如果要自定义,fork这个仓库后修改并把地址替换这个地址\n","sd_config_git_repu = 'https://github.com/viyiviyi/sd-configs.git'\n","# 设置文件保存路径 当使用谷歌云盘时非常有用\n","setting_file = 'config.json'\n","ui_config_file = '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-imgs'\n","\n","link_instead_of_copy = True # 下载或加载Input的文件时是使用链接还是复制的方式加载到目标目录\n","hidden_console_info = True # 是否隐藏大部分的控制台内容\n","\n","# 跳过启动webui,会导致不再安装webui的环境,也不再启动webui,但是下载还是会正常下载,在需要使用comfyui的时候可以打开\n","skip_webui = False\n","\n","# 是否启用 comfyui ,如果需要使用 comfyui,请将这个配置的 Fals 额改为 True。 \n","# 如果只需要使用comfyui,强烈建议将上面的 skip_webui 配置的 False 改为 True\n","use_comfyui = False \n","\n","# 多卡模式,当选择T4X2的GPU时可以启动两个 webui\n","multi_case = False # 将False改为True开启多卡"]},{"cell_type":"markdown","metadata":{},"source":["### 自定义脚本内容"]},{"cell_type":"code","execution_count":5,"metadata":{"execution":{"iopub.execute_input":"2024-10-22T14:40:05.531385Z","iopub.status.busy":"2024-10-22T14:40:05.531101Z","iopub.status.idle":"2024-10-22T14:40:05.542138Z","shell.execute_reply":"2024-10-22T14:40:05.541168Z","shell.execute_reply.started":"2024-10-22T14:40:05.531342Z"},"trusted":true},"outputs":[],"source":[" \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","def read_text_file(file_path:str):\n"," if not Path(file_path).exists(): return ''\n"," with open(file_path,\"r\") as f:\n"," text = file.read()\n"," if text: return text.strip()\n"," return ''\n"]},{"cell_type":"code","execution_count":6,"metadata":{"execution":{"iopub.execute_input":"2024-10-22T14:40:05.543566Z","iopub.status.busy":"2024-10-22T14:40:05.543267Z","iopub.status.idle":"2024-10-22T14:40:05.707423Z","shell.execute_reply":"2024-10-22T14:40:05.706502Z","shell.execute_reply.started":"2024-10-22T14:40:05.543535Z"},"trusted":true},"outputs":[],"source":["# 启动 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"," if Path(f'{install_path}/ComfyUI/custom_nodes/AnimateDiff').exists():\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"," \n"," if os.getenv('INIT_COMFYUI',''):\n"," pass\n"," else:\n"," print(f'下载 comfyui 依赖 预计需要5分钟以上')\n"," !python3.10 -m venv {install_path}/ComfyUI/venv\n"," if Path(f'/kaggle/input/comfyui-venv/cui-venv.tar.bak').exists():\n"," run(f'tar -xf /kaggle/input/comfyui-venv/cui-venv.tar.bak -C ./venv',cwd=f'{install_path}/ComfyUI')\n"," !python3.10 -m venv {install_path}/ComfyUI/venv\n"," run(f'{install_path}/ComfyUI/venv/bin/python3 -s -m pip install -r requirements.txt',cwd=f'{install_path}/ComfyUI')\n"," \n","# run(f'{install_path}/ComfyUI/venv/bin/python -m pip install torchvision==0.18.0 torchaudio==2.3.0 --index-url https://download.pytorch.org/whl/cu121')\n","# run(f'{install_path}/ComfyUI/venv/bin/python -m pip install xformers==0.0.26.post1')\n","\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}/ComfyUI/venv/bin/python3 -s -m pip install -r requirements.txt',cwd=os.path.join(f'{install_path}/ComfyUI/custom_nodes',node))\n"," \n"," os.environ['INIT_COMFYUI'] = \"DONE\"\n"," \n"," \n"," def start(device:int):\n"," print(f'启动 comfyui {device}')\n"," %cd {install_path}/ComfyUI \n"," \n"," !venv/bin/python3 main.py --force-fp16 --cuda-device={device} --port={8188+device}\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"]},{"cell_type":"code","execution_count":7,"metadata":{"execution":{"iopub.execute_input":"2024-10-22T14:40:05.709738Z","iopub.status.busy":"2024-10-22T14:40:05.709396Z","iopub.status.idle":"2024-10-22T14:40:05.721107Z","shell.execute_reply":"2024-10-22T14:40:05.720224Z","shell.execute_reply.started":"2024-10-22T14:40:05.709705Z"},"trusted":true},"outputs":[],"source":["# 安装一个文件浏览器 通过在访问地址后加 /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"]},{"cell_type":"code","execution_count":8,"metadata":{"execution":{"iopub.execute_input":"2024-10-22T14:40:05.724011Z","iopub.status.busy":"2024-10-22T14:40:05.723716Z","iopub.status.idle":"2024-10-22T14:40:05.735756Z","shell.execute_reply":"2024-10-22T14:40:05.734851Z","shell.execute_reply.started":"2024-10-22T14:40:05.723979Z"},"trusted":true},"outputs":[],"source":["\n","# 这个方法内的函数会在所有文件加载完成,准备启动webui前执行,可以放一些自定义的逻辑功能\n","def on_before_start():\n"," if use_comfyui:\n"," threading.Thread(target = start_comfyui, daemon=True, name='solo_start_comfyui').start()\n"," threading.Thread(target = start_filebrower, daemon=True, name='solo_start_filebrower').start()\n"," ## 下面可以写更多自定义逻辑\n"," pass\n"," "]},{"cell_type":"markdown","metadata":{},"source":["## webui 启动参数\n","- 所有的参数都会在启动时传入\n","- 可以在前面加```#```来屏蔽某个参数\n","- 端口参数需要在下一个代码块的```webuiPort```处修改"]},{"cell_type":"code","execution_count":9,"metadata":{"execution":{"iopub.execute_input":"2024-10-22T14:40:05.737659Z","iopub.status.busy":"2024-10-22T14:40:05.736987Z","iopub.status.idle":"2024-10-22T14:40:05.746957Z","shell.execute_reply":"2024-10-22T14:40:05.745963Z","shell.execute_reply.started":"2024-10-22T14:40:05.737614Z"},"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":10,"metadata":{"execution":{"iopub.execute_input":"2024-10-22T14:40:05.748625Z","iopub.status.busy":"2024-10-22T14:40:05.748176Z","iopub.status.idle":"2024-10-22T14:40:05.758062Z","shell.execute_reply":"2024-10-22T14:40:05.757299Z","shell.execute_reply.started":"2024-10-22T14:40:05.748584Z"},"trusted":true},"outputs":[],"source":["# 自定义本地反向代理 这些配置将会成为nginx的反向代理配置,用于实现一个穿透访问多个实例\n","# 默认情况下 / 被代理到了webui;/1/ 被代理到了第二个webui\n","proxy_path={\n"," '/fslist/':'http://127.0.0.1:8012/',\n","}\n","if use_comfyui:\n"," sub_path=['/webui/','/webui2/'] # 当启用comfyui时,webui需要变更到新目录,因为comfyui当前不支持被代理到二级目录\n"," proxy_path['/'] = 'http://127.0.0.1:8188/'"]},{"cell_type":"code","execution_count":11,"metadata":{"execution":{"iopub.execute_input":"2024-10-22T14:40:05.759242Z","iopub.status.busy":"2024-10-22T14:40:05.758999Z","iopub.status.idle":"2024-10-22T14:40:05.773582Z","shell.execute_reply":"2024-10-22T14:40:05.772677Z","shell.execute_reply.started":"2024-10-22T14:40:05.759215Z"},"trusted":true},"outputs":[{"name":"stdout","output_type":"stream","text":["/root\n"]}],"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":12,"metadata":{"execution":{"iopub.execute_input":"2024-10-22T14:40:05.774874Z","iopub.status.busy":"2024-10-22T14:40:05.774612Z","iopub.status.idle":"2024-10-22T14:40:12.022614Z","shell.execute_reply":"2024-10-22T14:40:12.021445Z","shell.execute_reply.started":"2024-10-22T14:40:05.774845Z"},"trusted":true},"outputs":[{"name":"stdout","output_type":"stream","text":["\n","\n","\n","\n","当前sd的安装路径是:/kaggle/sd_main_dir\n","当前图片保存路径是:/kaggle/working\n","当前数据集路径是:/kaggle/input\n","\n","欢迎使用 stable-diffusion-webui 便捷启动工具\n","\n","此脚本理论上可以在任何jupyter环境运行,但仅在 google colab 和 kaggle 测试。 已经无法在 google colab 免费实例上运行。\n","此脚本的【前置脚本】发布地址 https://www.kaggle.com/code/yiyiooo/stable-diffusion-webui-novelai-sdxl。\n","此脚本需配合 【前置脚本】 的脚本附带的配置项才能正常启动。\n","此脚本的内容会自动更新,你无需更新【前置脚本】就能获取到最新的功能。\n","增加一个说明:为解决加密图片的解密和浏览的问题,开发了一个独立应用,可以在这里下载 https://github.com/viyiviyi/encrypt_gallery/releases/\n","加密插件可解决生成nsfw图片后被平台封号问题\n","\n","路径说明\n","* 为了解决平台差异,所有的安装目录和文件输出目录都被重新指定,如果你需要在配置中访问这些目录,请查看以下说明\n","*\n","* 可以使用 $install_path 或 {install_path} 来访问安装目录,写在字符串内也会生效\n","* $output_path 或 {output_path} 可以访问输出目录\n","* 如果你需要安装在自定义目录,也可以设置这些值 如: install_path = '新的路径'\n","* 可自定义方法 on_before_start 并在方法内写上启动前需要的逻辑来实现在webui启动前执行自定义逻辑\n","* 可以增加配置 multi_case = True 来控制是否使用多卡\n","* 如果需要显示更多控制台输出 需配置 hidden_console_info = False\n","\n","********* 特别提示 *********\n","* huggingface 的下载链接需要增加 ?download=true 参数才能正确下载到文件,如果你需要的文件里的下载链接没有���个参数,请自行增加。\n","\n","已跳过自动启动,可手动执行 main() 进行启动。\n","推荐的启动代码:\n","try:\n"," check_gpu() # 检查是否存在gpu\n"," main()\n","except KeyboardInterrupt:\n"," stop_solo_threads() # 中断后自动停止后台线程 (有部分功能在后台线程中运行)\n"," \n"]}],"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":13,"metadata":{"execution":{"iopub.execute_input":"2024-10-22T14:40:12.024341Z","iopub.status.busy":"2024-10-22T14:40:12.023876Z","iopub.status.idle":"2024-10-22T14:40:12.028631Z","shell.execute_reply":"2024-10-22T14:40:12.027684Z","shell.execute_reply.started":"2024-10-22T14:40:12.024306Z"},"trusted":true},"outputs":[],"source":["reLoad = True\n","# 如果需要重新安装,请注释下面这一行\n","reLoad = False"]},{"cell_type":"code","execution_count":14,"metadata":{"execution":{"iopub.execute_input":"2024-10-22T14:40:12.030336Z","iopub.status.busy":"2024-10-22T14:40:12.029924Z","iopub.status.idle":"2024-10-22T14:40:12.043553Z","shell.execute_reply":"2024-10-22T14:40:12.042640Z","shell.execute_reply.started":"2024-10-22T14:40:12.030287Z"},"trusted":true},"outputs":[{"data":{"text/plain":["0"]},"execution_count":14,"metadata":{},"output_type":"execute_result"}],"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(12*60*60-60) # 定时关机时间,12小时 x 60分钟 x 60秒 当需要提前关机时可以修改数值"]},{"cell_type":"code","execution_count":15,"metadata":{"execution":{"iopub.execute_input":"2024-10-22T14:40:12.045107Z","iopub.status.busy":"2024-10-22T14:40:12.044751Z","iopub.status.idle":"2024-10-22T14:40:12.053106Z","shell.execute_reply":"2024-10-22T14:40:12.052161Z","shell.execute_reply.started":"2024-10-22T14:40:12.045064Z"},"trusted":true},"outputs":[],"source":["stop_solo_threads()"]},{"cell_type":"markdown","metadata":{},"source":["## 启动"]},{"cell_type":"code","execution_count":36,"metadata":{"execution":{"iopub.execute_input":"2024-10-22T14:54:15.116365Z","iopub.status.busy":"2024-10-22T14:54:15.115971Z","iopub.status.idle":"2024-10-22T14:54:50.450523Z","shell.execute_reply":"2024-10-22T14:54:50.449384Z","shell.execute_reply.started":"2024-10-22T14:54:15.116332Z"},"scrolled":true,"trusted":true},"outputs":[{"name":"stdout","output_type":"stream","text":["结束线程:solo_directory_to_watch\n","结束线程:solo_directory_to_watch\n","结束线程:solo_directory_to_watch\n","启动...\n","Token is valid (permission: write).\n","Your token has been saved in your configured git credential helpers (store).\n","Your token has been saved to /root/.cache/huggingface/token\n","Login successful\n","huggingface token 已经加载,可以下载私有仓库或文件\n","启动收藏图片文件夹监听,并自动同步到 huggingface dataset : viyi/sdwui-imgs\n","加载耗时: 5.20603609085083 秒\n","跳过webui启动\n","ngrok 访问地址:https://7da6-108-59-81-6.ngrok-free.app\n","ngrok 访问地址:https://7da6-108-59-81-6.ngrok-free.app\n","ngrok 本地服务:http://127.0.0.1:7862/ 访问地址:https://7da6-108-59-81-6.ngrok-free.app/webui2/\n","ngrok 本地服务:http://127.0.0.1:8012/ 访问地址:https://7da6-108-59-81-6.ngrok-free.app/fslist/\n","ngrok 本地服务:http://127.0.0.1:7861/ 访问地址:https://7da6-108-59-81-6.ngrok-free.app/webui/\n","ngrok 本地服务:http://127.0.0.1:8188/ 访问地址:https://7da6-108-59-81-6.ngrok-free.app/\n","freefrp 访问地址:http://8aad0b44-9083-11ef-925e-0242ac130202.frp.eaias.com\n","freefrp 本地服务:http://127.0.0.1:7862/ 访问地址:http://8aad0b44-9083-11ef-925e-0242ac130202.frp.eaias.com/webui2/\n","freefrp 本地服务:http://127.0.0.1:8012/ 访问地址:http://8aad0b44-9083-11ef-925e-0242ac130202.frp.eaias.com/fslist/\n","freefrp 本地服务:http://127.0.0.1:7861/ 访问地址:http://8aad0b44-9083-11ef-925e-0242ac130202.frp.eaias.com/webui/\n","freefrp 本地服务:http://127.0.0.1:8188/ 访问地址:http://8aad0b44-9083-11ef-925e-0242ac130202.frp.eaias.com/\n","Downloading File Browser for linux/amd64...\n","https://github.com/filebrowser/filebrowser/releases/download/v2.31.2/linux-amd64-filebrowser.tar.gz\n","2024/10/22 14:54:21 \u001b[1;34m[I] 检查更新中...\u001b[0m\n","2024/10/22 14:54:21 \u001b[1;34m[I] 出现错误, 请打开 https://doc.natfrp.com 查看帮助文档\u001b[0m\n","2024/10/22 14:54:21 \u001b[1;33m[W] 更新检查失败: API is not initialized\u001b[0m\n","2024/10/22 14:54:21 \u001b[1;34m[I] frpc version: 0.51.0-sakura-6 (built: 2024-06-25 20:30)\u001b[0m\n","2024/10/22 14:54:21 \u001b[1;34m[I] 正在连接节点 [frp.freefrp.net, tcp]\u001b[0m\n","Extracting...\n","Putting filemanager in /usr/local/bin (may require password)\n","Successfully installed\n","2024/10/22 14:54:22 \u001b[1;34m[I] [b473fe9a] 连接节点成功, 运行 ID [b473fe9a]\u001b[0m\n","2024/10/22 14:54:22 \u001b[1;34m[I] [b473fe9a] 隧道启动中: [8aad0b44-9083-11ef-925e-0242ac130202_http, http -> 127.0.0.1:7860]\u001b[0m\n","HTTP 隧道启动成功\n","使用 >>8aad0b44-9083-11ef-925e-0242ac130202.frp.eaias.com<< 连接你的隧道\n","请记得为您的自有域名添加 CNAME/A 记录\n","记录值为: >>frp.freefrp.net<<\n","2024/10/22 14:54:22 \u001b[1;34m[I] [b473fe9a] [8aad0b44-9083-11ef-925e-0242ac130202_http] 隧道启动成功\u001b[0m\n","2024/10/22 14:54:23 Using database: /kaggle/ComfyUI/filebrowser.db\n","2024/10/22 14:54:23 No config file used\n","2024/10/22 14:54:23 Listening on 127.0.0.1:8012\n","启动 comfyui\n","启动 comfyui 0\n","/kaggle/ComfyUI\n","[START] Security scan\n","[DONE] Security scan\n","## ComfyUI-Manager: installing dependencies done.\n","** ComfyUI startup time: 2024-10-22 14:54:36.977447\n","** Platform: Linux\n","** Python version: 3.10.14 | packaged by conda-forge | (main, Mar 20 2024, 12:45:18) [GCC 12.3.0]\n","** Python executable: /kaggle/ComfyUI/venv/bin/python3\n","** ComfyUI Path: /kaggle/ComfyUI\n","** Log path: /kaggle/ComfyUI/comfyui.log\n","\n","Prestartup times for custom nodes:\n"," 1.1 seconds: /kaggle/ComfyUI/custom_nodes/ComfyUI-Manager\n","\n","Set cuda device to: 0\n","Total VRAM 15095 MB, total RAM 32110 MB\n","pytorch version: 2.3.0+cu121\n","xformers version: 0.0.26.post1\n","Forcing FP16.\n","Set vram state to: NORMAL_VRAM\n","Device: cuda:0 Tesla T4 : cudaMallocAsync\n","Using xformers cross attention\n","[Prompt Server] web root: /kaggle/ComfyUI/web\n","[VideoHelperSuite] - \u001b[0;33mWARNING\u001b[0m - Failed to import imageio_ffmpeg\n","\u001b[36;20m[comfyui_controlnet_aux] | INFO -> Using ckpts path: /kaggle/ComfyUI/custom_nodes/comfyui_controlnet_aux/ckpts\u001b[0m\n","\u001b[36;20m[comfyui_controlnet_aux] | INFO -> Using symlinks: False\u001b[0m\n","\u001b[36;20m[comfyui_controlnet_aux] | INFO -> Using ort providers: ['CUDAExecutionProvider', 'DirectMLExecutionProvider', 'OpenVINOExecutionProvider', 'ROCMExecutionProvider', 'CPUExecutionProvider', 'CoreMLExecutionProvider']\u001b[0m\n","/kaggle/ComfyUI/custom_nodes/comfyui_controlnet_aux/node_wrappers/dwpose.py:26: UserWarning: DWPose: Onnxruntime not found or doesn't come with acceleration providers, switch to OpenCV with CPU device. DWPose might run very slowly\n"," warnings.warn(\"DWPose: Onnxruntime not found or doesn't come with acceleration providers, switch to OpenCV with CPU device. DWPose might run very slowly\")\n","### Loading: ComfyUI-Inspire-Pack (V1.6)\n","图片加密插件加载成功\n","Adding /kaggle/ComfyUI/custom_nodes to sys.path\n","\u001b[36mEfficiency Nodes:\u001b[0m Attempting to add Control Net options to the 'HiRes-Fix Script' Node (comfyui_controlnet_aux add-on)...\u001b[92mSuccess!\u001b[0m\n","\u001b[93mEfficiency Nodes Warning:\u001b[0m Failed to import python package 'simpleeval'; related nodes disabled.\n","\n","Loaded Efficiency nodes from /kaggle/ComfyUI/custom_nodes/efficiency-nodes-comfyui\n","Loaded ControlNetPreprocessors nodes from /kaggle/ComfyUI/custom_nodes/comfyui_controlnet_aux\n","Could not find AdvancedControlNet nodes\n","Could not find AnimateDiff nodes\n","Loaded IPAdapter nodes from /kaggle/ComfyUI/custom_nodes/ComfyUI_IPAdapter_plus\n","Loaded VideoHelperSuite from /kaggle/ComfyUI/custom_nodes/ComfyUI-VideoHelperSuite\n","### Loading: ComfyUI-Impact-Pack (V7.10.5)\n","### Loading: ComfyUI-Impact-Pack (Subpack: V0.7)\n","### Loading: ComfyUI-Impact-Pack (V7.10.5)\n","Loaded ImpactPack nodes from /kaggle/ComfyUI/custom_nodes/ComfyUI-Impact-Pack\n","[Impact Pack] Wildcards loading done.\n","[Impact Pack] Wildcards loading done.\n","### Loading: ComfyUI-Impact-Pack (V7.10.5)\n","[Impact Pack] Wildcards loading done.\n","\u001b[36;20m[comfy_mtb] | INFO -> loaded \u001b[96m81\u001b[0m nodes successfuly\u001b[0m\n","\u001b[36;20m[comfy_mtb] | INFO -> Some nodes (7) could not be loaded. This can be ignored, but go to http://127.0.0.1:8188/mtb if you want more information.\u001b[0m\n","### Loading: ComfyUI-Manager (V2.51.8)\n","### ComfyUI Revision: 2753 [5f9d5a24] *DETACHED | Released on '2024-10-09'\n","[ComfyUI-Manager] default cache updated: https://raw.githubusercontent.com/ltdrdata/ComfyUI-Manager/main/alter-list.json\n","[ComfyUI-Manager] default cache updated: https://raw.githubusercontent.com/ltdrdata/ComfyUI-Manager/main/github-stats.json\n","[ComfyUI-Manager] default cache updated: https://raw.githubusercontent.com/ltdrdata/ComfyUI-Manager/main/model-list.json\n","[ComfyUI-Manager] default cache updated: https://raw.githubusercontent.com/ltdrdata/ComfyUI-Manager/main/custom-node-list.json\n","[ComfyUI-Manager] default cache updated: https://raw.githubusercontent.com/ltdrdata/ComfyUI-Manager/main/extension-node-map.json\n","\u001b[34mWAS Node Suite: \u001b[0mOpenCV Python FFMPEG support is enabled\u001b[0m\n","\u001b[34mWAS Node Suite \u001b[93mWarning: \u001b[0m`ffmpeg_bin_path` is not set in `/kaggle/ComfyUI/custom_nodes/was-node-suite-comfyui/was_suite_config.json` config file. Will attempt to use system ffmpeg binaries if available.\u001b[0m\n","\u001b[34mWAS Node Suite: \u001b[0mFinished.\u001b[0m \u001b[32mLoaded\u001b[0m \u001b[0m218\u001b[0m \u001b[32mnodes successfully.\u001b[0m\n","\n","\t\u001b[3m\u001b[93m\"Art is the most beautiful of all lies.\"\u001b[0m\u001b[3m - Claude Debussy\u001b[0m\n","\n","\u001b[34mFizzleDorf Custom Nodes: \u001b[92mLoaded\u001b[0m\n","Total VRAM 15095 MB, total RAM 32110 MB\n","pytorch version: 2.3.0+cu121\n","xformers version: 0.0.26.post1\n","Forcing FP16.\n","Set vram state to: NORMAL_VRAM\n","Device: cuda:0 Tesla T4 : cudaMallocAsync\n","------------------------------------------\n","\u001b[34mComfyroll Studio v1.76 : \u001b[92m 175 Nodes Loaded\u001b[0m\n","------------------------------------------\n","** For changes, please see patch notes at https://github.com/Suzie1/ComfyUI_Comfyroll_CustomNodes/blob/main/Patch_Notes.md\n","** For help, please see the wiki at https://github.com/Suzie1/ComfyUI_Comfyroll_CustomNodes/wiki\n","------------------------------------------\n","\n","Import times for custom nodes:\n"," 0.0 seconds: /kaggle/ComfyUI/custom_nodes/websocket_image_save.py\n"," 0.0 seconds: /kaggle/ComfyUI/custom_nodes/efficiency-nodes-comfyui\n"," 0.0 seconds: /kaggle/ComfyUI/custom_nodes/sdxl_prompt_styler\n"," 0.0 seconds: /kaggle/ComfyUI/custom_nodes/ComfyUI-Image-Selector\n"," 0.0 seconds: /kaggle/ComfyUI/custom_nodes/comfyui-encrypt-image\n"," 0.0 seconds: /kaggle/ComfyUI/custom_nodes/masquerade-nodes-comfyui\n"," 0.0 seconds: /kaggle/ComfyUI/custom_nodes/ComfyQR\n"," 0.0 seconds: /kaggle/ComfyUI/custom_nodes/ComfyUI-Impact-Pack\n"," 0.0 seconds: /kaggle/ComfyUI/custom_nodes/ComfyUI_UltimateSDUpscale\n"," 0.0 seconds: /kaggle/ComfyUI/custom_nodes/comfy-image-saver\n"," 0.0 seconds: /kaggle/ComfyUI/custom_nodes/ymc-node-suite-comfyui\n"," 0.0 seconds: /kaggle/ComfyUI/custom_nodes/ComfyUI_Comfyroll_CustomNodes\n"," 0.0 seconds: /kaggle/ComfyUI/custom_nodes/ComfyUI_IPAdapter_plus\n"," 0.0 seconds: /kaggle/ComfyUI/custom_nodes/ComfyUI-Manager\n"," 0.1 seconds: /kaggle/ComfyUI/custom_nodes/ComfyUI-VideoHelperSuite\n"," 0.1 seconds: /kaggle/ComfyUI/custom_nodes/comfy_mtb\n"," 0.1 seconds: /kaggle/ComfyUI/custom_nodes/facerestore_cf\n"," 0.1 seconds: /kaggle/ComfyUI/custom_nodes/ComfyUI-Inspire-Pack\n"," 0.4 seconds: /kaggle/ComfyUI/custom_nodes/ComfyUI_FizzNodes\n"," 0.5 seconds: /kaggle/ComfyUI/custom_nodes/comfyui_controlnet_aux\n"," 0.5 seconds: /kaggle/ComfyUI/custom_nodes/comfyui-art-venture\n"," 1.6 seconds: /kaggle/ComfyUI/custom_nodes/was-node-suite-comfyui\n","\n","Starting server\n","\n","To see the GUI go to: http://127.0.0.1:8188\n","结束线程:solo_directory_to_watch\n","结束线程:solo_directory_to_watch\n","结束线程:solo_directory_to_watch\n","结束线程:solo_startProxy\n","结束线程:solo_directory_to_watch\n","结束线程:solo_start_filebrower\n","结束线程:solo_start_comfyui_0\n"]}],"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":"markdown","metadata":{},"source":["## 一些示例代码"]},{"cell_type":"code","execution_count":null,"metadata":{"scrolled":true,"trusted":true},"outputs":[],"source":["# %cd {install_path}/{ui_dir_name}\n","# !venv/bin/python -m pip install torch==2.3.0 --index-url https://download.pytorch.org/whl/cu121\n","# !venv/bin/python -m pip install torchvision==0.18.0 torchaudio==2.3.0 --index-url https://download.pytorch.org/whl/cu121\n","# !venv/bin/python -m pip install xformers==0.0.26.post1\n","# !venv/bin/python -m pip install -r requirements_versions.txt\n","# !venv/bin/python -m pip install spandrel==0.3.0\n","# !venv/bin/python -m pip install opencv-python\n","# !venv/bin/python -m pip install pydantic==1.10.15\n","# !venv/bin/python -m pip install transformers -U\n","# !venv/bin/python -m pip install llama-cpp-python\n","# !venv/bin/python -m pip install pytorch_lightning==2.3.3 torchsde==0.2.6 spandrel==0.3.4\n","\n","# !{install_path}/{ui_dir_name}/venv/bin/python3 -m pip install open-clip-torch -U\n","# !{install_path}/{ui_dir_name}/venv/bin/python3 -m pip install protobuf==4.25.3\n","# !{install_path}/{ui_dir_name}/venv/bin/python3 -m pip install blendmodes==2022\n","# !{install_path}/{ui_dir_name}/venv/bin/python3 -m pip install Pillow==9.5.0\n","\n","# !{install_path}/ComfyUI/venv/bin/python3 -m pip install qrcode==7.4.2\n","# !{install_path}/ComfyUI/venv/bin/python3 -m pip install -r /kaggle/ComfyUI/custom_nodes/ComfyUI-Impact-Pack/requirements.txt\n","# !{install_path}/ComfyUI/venv/bin/python3 -m pip install opencv-python numba numexpr piexif scikit-image webcolors pydantic lpips qrcode pandas Pillow==9.5.0"]},{"cell_type":"code","execution_count":null,"metadata":{"trusted":true},"outputs":[],"source":["# 打包收藏文件夹 如果需要可以取消下面两行的注释\n","# zipPath(f'{install_path}/{ui_dir_name} /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(f'{install_path}/{ui_dir_name}/textual_inversion','训练输出') \n","# zipPath(f'{install_path}/{ui_dir_name}/outputs','outputs')\n","\n","# 打包venv并上传到数据集\n","# !rm -rf /kaggle/working/venv.tar.bak\n","# !rm -rf {output_path}/venv.tar\n","# zipPath(f'{install_path}/{ui_dir_name}/venv','venv')\n","# !mv {output_path}/venv.tar /kaggle/working/venv.tar.bak\n","# createOrUpdateDataSet('/kaggle/working/venv.tar.bak','sd-webui-venv')\n","# comfyui\n","# !rm -rf /kaggle/working/cui-venv.tar.bak\n","# !rm -rf {output_path}/cui-venv.tar\n","# zipPath(f'{install_path}/ComfyUI/venv','cui-venv')\n","# !mv {output_path}/cui-venv.tar /kaggle/working/cui-venv.tar.bak\n","# createOrUpdateDataSet('/kaggle/working/cui-venv.tar.bak','comfyui-venv')\n","# 打包命令参考,--exclude 可以排除不需要打包的目录\n","# !tar -cf $output_path/webui.tar.bak --exclude=venv --exclude=extensions -C /sd_main_dir/ ."]},{"cell_type":"markdown","metadata":{},"source":["# 使用帮助\n","---\n","**代码块不能删除也不能调换顺序,如果出现变量未定义,请检查是否按顺序执行了代码块**\n","\n","**请注意查看启动后最开始的那一段输出,里面会包含更新的内容和一些特别的设置,可能对文件访问有帮助**\n","\n","---\n","\n","## kaggle账号\n","- 注册账号需要手机号,国内手机号也行,如果点击注册后没反应,估计是需要梯子,用于人机验证\n","- 注册后点此笔记的 **Copy & Edit** 按钮就进到编辑界面\n","\n","## 准备工作\n","1. 右侧面板 **Notebook options/ACCELERATOR** 需要选择GPU **T4x2**出图更快\n","2. 右侧面板 **Notebook options/LANGUAGE** 需要选择Python\n","2. 右侧面板 **Notebook options/PERSISTENCE** 建议选择 Files only **作用是保存Outpot目录内的文件,当前这个功能并没有任何作用**\n","3. 右侧面板 **Notebook options/ENVIRONMENT** 建议不改这个配置,使用当前默认值就行\n","4. 右侧面板 **Notebook options/INTERNET** 需要打开 用于联网\n","\n","## 启动\n","#### 启动方式一 **直接点击页面上边的 RunAll**\n","- 手机端可能会出现页面上边的工具栏不显示的情况,左侧菜单按钮里也有相关的操作\n","- 长时间不操作页面会导致脚本停止 (应该是40分钟吧)\n","\n","#### 启动方式二 **使用页面上边的 Save Version 后台运行**\n","- 后台运行不用担心长时间不操作脚本停止\n","- Version Type 选择 **Save & Run All**\n","- 在Save Version弹窗里需要选择使用**GPU**环境 (Advanced Settings 里最后一个选项)\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","- 可以直接写模型的下载链接,省去下面这些步骤\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","- **受到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","- **注意! 以上对文件的访问路径仅做示例,真实的安装位置需要通过 {install_path}/{ui_dir_name} 来访问**\n","\n","## **一些可能没用的说明**\n","- 配置说明 **True或者False**表示布尔值 **True**表示“**是**” **False**表示“**否**” 只有这两个值\n","- 配置说明 **[]** 表示数组,里面可以存放内容,每个内容需要用**英语(半角)逗号**隔开\n","- 配置说明 **''或者\"\"** 英语(半角)的双引号或者单引号包裹的内容是**字符串**,比如放在数组里面的路径就需要是一个字符串\n","- 配置说明 **#** **#** 后面的内容是**注释**,是帮助性内容,对整个代码的执行不会有影响\n"]},{"cell_type":"markdown","metadata":{},"source":["# 更新记录\n","#### 2401022 v222\n","- 增加打包的 Comfyui 运行环境,将 Comfyui 的启动时间减少到5分钟作用\n","\n","#### 2401019 v221\n","- 修复 Comfyui 启动失败的问题\n","\n","#### 2400817 v220\n","- 修复 Comfyui 白屏的问题。(因为当前Comfyui不再能代理到二级目录,所以在启用comfyui的情况下将会导致webui的访问路径变更为`/webui/`和`/webui2/`,且comfyui只能使用到一张卡)\n","\n","#### 2400803 v218\n","- 增加跳过启动webui的功能(同时也会跳过安装webui的pyhton环境)\n","\n","#### 240717 v216\n","- 给 huggingface 的下载链接增加 download=true 参数,解决下载的文件不正确的问题\n","\n","#### 240622 v215\n","- 默认只启动一个webui,降低内存占用,使用SDXL模型时降低卡死的概率\n","- 修复定时结束功能导致笔记状态为异常退出的问题\n","- 安装目录更新到/kaggle默认,使用文件浏览器管理文件时更方便\n","\n","#### 240619 v212\n","- 更新环境包\n","- 分离Comfyui与Webui的环境(Comfyui的环境在启动时下载)\n","\n","#### 240526 v211\n","- 更新到sd1.9 (没有适配最新的环境,依然使用旧环境)\n","\n","# 更新记录\n","#### 2400317 v209\n","- 更新到新的环境包\n","\n","#### 2401026 v202\n","- 增加了一个文件浏览器,通过在访问地址后加 ``` /fslist/ ``` 来访问 登录用户 admin 密码 admin\n","\n","#### 2401024 v201\n","- 增加一个定时停止的功能,用于在有些时候仅需要启动来使用几个小时的情况\n","\n","#### 240104 v200\n","- 双开ComfyUI\n","\n","#### 240101 v198\n","- 增加了更多ComfyUI节点,让ComfyUI安装后变得可用,而不是示例\n","\n","#### 231226 v195\n","- 修复代理配置错误导致cui无法访问的问题\n","- 增加了一个ComfyUI插件,可以优化移动端使用体验 ComfyUI 可以在代理地址后面加 ``` /cui/ ``` 来访问\n","\n","#### 231221 v193\n","- 增加安装了一个ComfyUI,同时也作为一个文件加载配置的示例\n","\n","#### 231201 v190\n","- 当存在huggingface token的情况下,将会使用token下载huggingface文件,可以下载私有仓库或文件\n","- 增加了一个修改后支持加密插件的C站浏览器插件,方便在运行时搜索和下载C站模型。\n","\n","#### 231112 v188\n","- 新增了两个插件和一个超分辨模型\n","\n","#### 231111 v187\n","- 修改了一些说明文字\n","\n","#### 231110 v186\n","- 增加了一些默认插件\n","\n","#### 231109 v184\n","- 增加了一个可在启动前执行自定义逻辑的功能,将需要执行的逻辑写在 on_before_start 方法里面即可\n","\n","#### 231011 v183\n","- 移除了两个默认插件\n","- 更新了env环境 \n","\n","#### 231011 v180\n","- 增加了图��加密插件,默认不启用,请查看启动参数部分设置密码启动,批量解密图片可以查看插件的发布地址\n","\n","#### 230920 v177\n","- 默认不再开启gradio这个内网穿透\n","- 更新了一些文档和说明\n","\n","#### 230910 v175\n","- 增加了默认的sdxl模型\n","- 修改了不合适的使用说明\n","\n","#### 230901 v173\n","- 更新了依赖版本,可以加载sdxl模型了\n","- 增加代码块内容说明,希望有用\n","\n","#### 230812 v171\n","- 把关闭半精度的参数注释了,这是之前写错的,注释后不容易爆内存\n","- 增加默认模型的参数,用于指定模型启动时默认的模型\n","\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":{"kaggle":{"accelerator":"nvidiaTeslaT4","dataSources":[{"datasetId":2716934,"sourceId":6167400,"sourceType":"datasetVersion"},{"datasetId":3654544,"sourceId":6346544,"sourceType":"datasetVersion"},{"datasetId":4364744,"sourceId":7496040,"sourceType":"datasetVersion"},{"datasetId":2962375,"sourceId":8927260,"sourceType":"datasetVersion"},{"datasetId":3074484,"sourceId":8972237,"sourceType":"datasetVersion"},{"datasetId":5926543,"sourceId":9693949,"sourceType":"datasetVersion"}],"isGpuEnabled":true,"isInternetEnabled":true,"language":"python","sourceType":"notebook"},"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.12.4"}},"nbformat":4,"nbformat_minor":4}
|