{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"name":"python","version":"3.7.12","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# 安装目录\ninstall_path=\"/kaggle/working\" \nupdata_webui = False #是否开机自动更新webui\n\n# 重置变量 会删掉sd_webui重新安装\nreLoad = False\n\n#清理和打包生成的图片\nzip_output=True\nclear_output=True\n\n# 使用huggingface保存和载入webui配置文件\nhuggingface_use = False\nhuggingface_token_file = '/kaggle/input/hugfacetoken/hugfacetoken.txt'\nhuggiingface_repo_id = 'sukaka/sd_configs'\n# 将会同步的文件\nyun_files = ['ui-config.json','config.json','styles.csv']","metadata":{"execution":{"iopub.status.busy":"2023-05-10T13:17:09.748011Z","iopub.execute_input":"2023-05-10T13:17:09.749007Z","iopub.status.idle":"2023-05-10T13:17:09.756506Z","shell.execute_reply.started":"2023-05-10T13:17:09.748953Z","shell.execute_reply":"2023-05-10T13:17:09.755299Z"},"trusted":true},"execution_count":137,"outputs":[]},{"cell_type":"code","source":"#模型和插件\n\n# 插件列表: git仓库地址\n# 不需要的插件在前面加 # ,插件地址之间需要用英语逗号隔开\nextensions = [\n 'https://github.com/Elldreth/loopback_scaler',\n 'https://github.com/jexom/sd-webui-depth-lib.git',\n 'https://github.com/AlUlkesh/stable-diffusion-webui-images-browser',\n 'https://github.com/camenduru/sd-civitai-browser',\n #'https://github.com/kohya-ss/sd-webui-additional-networks ',\n 'https://github.com/Mikubill/sd-webui-controlnet',\n 'https://github.com/camenduru/openpose-editor',\n 'https://github.com/dtlnor/stable-diffusion-webui-localization-zh_CN',\n 'https://github.com/opparco/stable-diffusion-webui-two-shot',\n #'https://github.com/minicacas/stable-diffusion-webui-composable-lora',\n 'https://github.com/DominikDoom/a1111-sd-webui-tagcomplete',\n #'https://github.com/hnmr293/posex',\n 'https://github.com/pkuliyi2015/multidiffusion-upscaler-for-automatic1111',\n 'https://github.com/KohakuBlueleaf/a1111-sd-webui-locon',\n 'https://github.com/hnmr293/sd-webui-cutoff',\n 'https://github.com/hako-mikan/sd-webui-lora-block-weight',\n 'https://github.com/butaixianran/Stable-Diffusion-Webui-Civitai-Helper.git',\n 'https://github.com/catppuccin/stable-diffusion-webui.git',\n]\n\n# Stable Diffusion模型请放在这里(不用填模型的文件名,只填模型的目录即可)\nsd_model = [\n '/kaggle/input/cetus-mix/',\n #'/kaggle/input/aom3ackpt',\n #'/kaggle/input/lora-9527-counterfeit',\n '/kaggle/input/dalcefo-painting',\n ]\n# Stable Diffusion模型下载链接放这里\nsd_model_urls=[\n#9527\n'https://civitai.com/api/download/models/7278',\n \n]\n\n# VAE模型请放在这里(不用填模型的文件名,只填模型的目录即可)\nvae_model = []\n#VAE模型下载链接放这里\nvae_model_urls=[]\n\n# Lora模型的数据集路径请写在这里:\nlora_model = [\n#'/kaggle/input/loras-bocchi-the-rock',\n#'/kaggle/input/lora-1',\n#'/kaggle/input/gachalora',\n#'/kaggle/input/dksss-lora/lora',\n#'/kaggle/input/dksss-lora/standingFullBodyWithBackgroundStyle_v10Offset'\n'/kaggle/input/hanfu-lora'\n] \n# Lora模型下载链接放这里\nlora_model_urls=[]\n\n# ControlNet模型data请放在这里:\ncn_model = [\n#'/kaggle/input/controlnet-ext'\n#'/kaggle/input/t2i-adapters'\n]\n# controlnet模型下载链接放这里\ncn_model_urls = [\n'https://huggingface.co./comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11e_sd15_ip2p_fp16.safetensors',\n'https://huggingface.co./comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11e_sd15_shuffle_fp16.safetensors',\n'https://huggingface.co./comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11f1p_sd15_depth_fp16.safetensors',\n'https://huggingface.co./comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11p_sd15_canny_fp16.safetensors',\n'https://huggingface.co./comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11p_sd15_inpaint_fp16.safetensors',\n'https://huggingface.co./comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11p_sd15_lineart_fp16.safetensors',\n'https://huggingface.co./comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11p_sd15_mlsd_fp16.safetensors',\n'https://huggingface.co./comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11p_sd15_normalbae_fp16.safetensors',\n'https://huggingface.co./comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11p_sd15_openpose_fp16.safetensors',\n'https://huggingface.co./comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11p_sd15_scribble_fp16.safetensors',\n'https://huggingface.co./comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11p_sd15_softedge_fp16.safetensors',\n'https://huggingface.co./comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11p_sd15s2_lineart_anime_fp16.safetensors',\n'https://huggingface.co./comfyanonymous/ControlNet-v1-1_fp16_safetensors/resolve/main/control_v11u_sd15_tile_fp16.safetensors',\n]\n\n# Hypernetworks超网络模型路径请放在这里:\nhypernetworks_model = []\n\n# embeddings(pt文件)请放在这里:\nembeddings_model = ['/kaggle/input/1embeddings/embeddings',\n '/kaggle/input/1embeddings/embeddings/person'\n ] \n","metadata":{"execution":{"iopub.status.busy":"2023-05-10T12:54:39.173674Z","iopub.execute_input":"2023-05-10T12:54:39.174459Z","iopub.status.idle":"2023-05-10T12:54:39.189486Z","shell.execute_reply.started":"2023-05-10T12:54:39.174418Z","shell.execute_reply":"2023-05-10T12:54:39.188271Z"},"trusted":true},"execution_count":120,"outputs":[]},{"cell_type":"code","source":"#ngrok穿透\nngrok_use = False\nngrokTokenFile='/kaggle/input/ngroktoken/Authtoken.txt' # 非必填 存放ngrokToken的文件的路径\n\n# 启动时默认加载的模型名称 可填全路径或者模型名称,名称建议带上文件名后缀\n# 如果你想加载7G以上的大模型,请填这个来加载,直接在Webui里切换模型容易爆内存\nusedCkpt = 'cetusMix.safetensors'\n\n#启动参数\nargs = [\n '--share',\n '--xformers',\n '--lowram',\n '--no-hashing',\n '--disable-nan-check',\n '--enable-insecure-extension-access',\n '--disable-console-progressbars',\n '--enable-console-prompts',\n '--disable-safe-unpickle',\n '--no-gradio-queue'\n]","metadata":{"execution":{"iopub.status.busy":"2023-05-10T12:54:39.191389Z","iopub.execute_input":"2023-05-10T12:54:39.192147Z","iopub.status.idle":"2023-05-10T12:54:39.205096Z","shell.execute_reply.started":"2023-05-10T12:54:39.192101Z","shell.execute_reply":"2023-05-10T12:54:39.203691Z"},"trusted":true},"execution_count":121,"outputs":[]},{"cell_type":"code","source":"use2 = False#是否开启两个webui\n#ngrok穿透\nngrok_use1 = False\nngrokTokenFile1='/kaggle/input/ngroktoken/Authtoken1.txt' # 非必填 存放ngrokToken的文件的路径\n\n#第二个webui使用的模型\nusedCkpt1 = 'cetusMix.safetensors'\n\n#启动参数\nargs1 = [\n '--share',\n '--xformers',\n '--lowram',\n '--no-hashing',\n '--disable-nan-check',\n '--enable-insecure-extension-access',\n '--disable-console-progressbars',\n '--enable-console-prompts',\n '--disable-safe-unpickle',\n '--no-gradio-queue'\n]","metadata":{"execution":{"iopub.status.busy":"2023-05-10T12:54:39.208058Z","iopub.execute_input":"2023-05-10T12:54:39.208876Z","iopub.status.idle":"2023-05-10T12:54:39.218833Z","shell.execute_reply.started":"2023-05-10T12:54:39.208831Z","shell.execute_reply":"2023-05-10T12:54:39.217548Z"},"trusted":true},"execution_count":122,"outputs":[]},{"cell_type":"code","source":"#使用的库\nfrom multiprocessing import Process\nfrom pathlib import Path\nimport pandas as pd\nimport shutil\nimport os\nimport time\nimport re\nimport gc\nimport requests\nimport subprocess\nimport multiprocessing\nos.environ['install_path'] = install_path","metadata":{"execution":{"iopub.status.busy":"2023-05-10T12:54:39.220828Z","iopub.execute_input":"2023-05-10T12:54:39.221745Z","iopub.status.idle":"2023-05-10T12:54:39.229934Z","shell.execute_reply.started":"2023-05-10T12:54:39.221704Z","shell.execute_reply":"2023-05-10T12:54:39.228691Z"},"trusted":true},"execution_count":123,"outputs":[]},{"cell_type":"code","source":"#功能函数,内存优化和多进程\ndef libtcmalloc():\n !apt-get remove google-perftools -y\n %cd /kaggle\n !mkdir temp\n %cd temp\n !wget -qq --show-progres http://launchpadlibrarian.net/367274644/libgoogle-perftools-dev_2.5-2.2ubuntu3_amd64.deb\n !wget -qq --show-progres https://launchpad.net/ubuntu/+source/google-perftools/2.5-2.2ubuntu3/+build/14795286/+files/google-perftools_2.5-2.2ubuntu3_all.deb\n !wget -qq --show-progres https://launchpad.net/ubuntu/+source/google-perftools/2.5-2.2ubuntu3/+build/14795286/+files/libtcmalloc-minimal4_2.5-2.2ubuntu3_amd64.deb\n !wget -qq --show-progres https://launchpad.net/ubuntu/+source/google-perftools/2.5-2.2ubuntu3/+build/14795286/+files/libgoogle-perftools4_2.5-2.2ubuntu3_amd64.deb\n !apt install -qq libunwind8-dev -y\n !dpkg -i *.deb\n !rm *.deb\n os.environ[\"LD_PRELOAD\"] = \"libtcmalloc.so\"\n\ndef run_programs(programs):\n processes = []\n for program in programs:\n p = Process(target=program)\n p.start()\n processes.append(p)\n time.sleep(2)\n for p in processes:\n p.join()","metadata":{"execution":{"iopub.status.busy":"2023-05-10T12:54:39.233625Z","iopub.execute_input":"2023-05-10T12:54:39.234006Z","iopub.status.idle":"2023-05-10T12:54:39.302175Z","shell.execute_reply.started":"2023-05-10T12:54:39.233956Z","shell.execute_reply":"2023-05-10T12:54:39.301030Z"},"trusted":true},"execution_count":124,"outputs":[]},{"cell_type":"code","source":"#功能函数,环境和sd_webui安装\ndef venvinstall():\n %cd /opt/conda/envs\n if os.path.exists('venv'):\n print('环境已安装')\n else:\n %cd /kaggle/working/\n if not os.path.exists('venv.tar.gz'):\n print('环境包下载中')\n !wget https://huggingface.co./datasets/sukaka/venv_ai_drow/resolve/main/sd_webui_torch2_cu118_xf19.tar.gz -O venv.tar.gz\n print('环境包已下载')\n %cd /opt/conda/envs/\n !mkdir venv\n %cd venv\n print('环境安装中')\n !tar -xzf /kaggle/working/venv.tar.gz\n !source /opt/conda/bin/activate venv\n print('环境安装完毕')\n \n#安装webui\ndef install_webui():\n %cd $install_path\n if reLoad:\n !rm -rf stable-diffusion-webui\n if Path(\"stable-diffusion-webui\").exists():\n if updata_webui:\n %cd $install_path/stable-diffusion-webui/\n !git pull\n print('stable-diffusion-webui已安装')\n else:\n print('stable-diffusion-webui安装中')\n #Download Automatic1111's Stable Diffusion Web UI\n !git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui\n %cd $install_path/stable-diffusion-webui/\n #Use lastest version\n !git checkout 5ab7f213bec2f816f9c5644becb32eb72c8ffb89\n with open('launch.py', 'r') as f:\n content = f.read()\n with open('launch.py', 'w') as f:\n f.write('import ssl\\n')\n f.write('ssl._create_default_https_context = ssl._create_unverified_context\\n')\n f.write(content)\n print('stable-diffusion-webui已安装')\n if huggingface_use:\n def webui_config_download(yun_files, huggiingface_repo_id):\n %cd $install_path/stable-diffusion-webui/\n for yun_file in yun_files:\n url = f'https://huggingface.co./datasets/{huggiingface_repo_id}/resolve/main/{yun_file}'\n response = requests.head(url)\n if response.status_code == 200:\n result = subprocess.run(['wget', '-O', yun_file, url, '-q'], capture_output=True)\n if result.returncode != 0:\n print(f'Error: Failed to download {yun_file} from {url}')\n else:\n print(f'Error: Invalid URL {url}')\n webui_config_download(yun_files, huggiingface_repo_id)","metadata":{"execution":{"iopub.status.busy":"2023-05-10T12:54:39.336541Z","iopub.execute_input":"2023-05-10T12:54:39.337261Z","iopub.status.idle":"2023-05-10T12:54:39.481587Z","shell.execute_reply.started":"2023-05-10T12:54:39.337219Z","shell.execute_reply":"2023-05-10T12:54:39.480521Z"},"trusted":true},"execution_count":125,"outputs":[]},{"cell_type":"code","source":"# 安装插件,下载和同步模型\ndef install_extensions():\n print('安装插件,此处出现红条是正常的')\n %cd $install_path/stable-diffusion-webui\n !mkdir -p extensions\n %cd extensions\n for ex in extensions:\n os.system('git clone '+ex)\n print('插件已安装')\n \ndef download_links(links, target_folder):\n for link in links:\n if link.startswith('https://huggingface.co./'):\n filename = re.search(r'[^/]+$', link).group(0)\n os.system(f'aria2c --console-log-level=error -q -c -x 16 -s 16 -k 1M -d \"{target_folder}\" -o \"{filename}\" \"{link}\"')\n else:\n os.system(f'aria2c --console-log-level=error -q -c -x 16 -s 16 -k 1M --remote-time -d \"{target_folder}\" \"{link}\"')\n \n# 下载模型文件\ndef download_model():\n os.chdir('/kaggle')\n os.makedirs('models', exist_ok=True)\n os.chdir('models')\n os.makedirs('VAE', exist_ok=True)\n os.makedirs('Stable-diffusion', exist_ok=True)\n os.makedirs('Lora', exist_ok=True)\n os.makedirs('cn-model', exist_ok=True)\n download_links(vae_model_urls, 'VAE')\n download_links(sd_model_urls, 'Stable-diffusion')\n download_links(lora_model_urls, 'Lora')\n download_links(cn_model_urls, 'cn-model')\n\ndef create_symlinks(folder_paths, target_dir):\n # Create target directory if it doesn't exist\n if not os.path.exists(target_dir):\n os.makedirs(target_dir)\n # Remove broken symlinks in target directory\n for filename in os.listdir(target_dir):\n target_path = os.path.join(target_dir, filename)\n if os.path.islink(target_path) and not os.path.exists(target_path):\n os.unlink(target_path)\n # Create new symlinks\n for source_dir in folder_paths:\n if not os.path.exists(source_dir):\n continue\n for filename in os.listdir(source_dir):\n source_path = os.path.join(source_dir, filename)\n target_path = os.path.join(target_dir, filename)\n if not os.path.exists(target_path):\n os.symlink(source_path, target_path)\n print(f'Created symlink for {filename} in {target_dir}')\n\n# 链接模型文件\ndef link_models():\n !mkdir {install_path}/stable-diffusion-webui/models/Lora\n cn_model.append('/kaggle/models/cn-model')\n vae_model.append('/kaggle/models/VAE')\n sd_model.append('/kaggle/models/Stable-diffusion')\n lora_model.append('/kaggle/models/Lora')\n create_symlinks(vae_model,f'{install_path}/stable-diffusion-webui/models/VAE')\n create_symlinks(sd_model,f'{install_path}/stable-diffusion-webui/models/Stable-diffusion')\n create_symlinks(lora_model,f'{install_path}/stable-diffusion-webui/models/Lora')\n create_symlinks(cn_model,f'{install_path}/stable-diffusion-webui/extensions/sd-webui-controlnet/models')\n create_symlinks(embeddings_model,f'{install_path}/stable-diffusion-webui/embeddings')\n create_symlinks(hypernetworks_model,f'{install_path}/stable-diffusion-webui/models/hypernetworks')\n","metadata":{"execution":{"iopub.status.busy":"2023-05-10T12:54:39.485637Z","iopub.execute_input":"2023-05-10T12:54:39.488287Z","iopub.status.idle":"2023-05-10T12:54:39.543117Z","shell.execute_reply.started":"2023-05-10T12:54:39.488253Z","shell.execute_reply":"2023-05-10T12:54:39.541980Z"},"trusted":true},"execution_count":126,"outputs":[]},{"cell_type":"code","source":"# 功能函数:内网穿透\ndef ngrok_start(ngrokTokenFile: str, port: int, address_name: str, should_run: bool):\n if not should_run:\n print('Skipping ngrok start')\n return\n if Path(ngrokTokenFile).exists():\n with open(ngrokTokenFile, encoding=\"utf-8\") as nkfile:\n ngrokToken = nkfile.readline()\n print('use nrgok')\n from pyngrok import conf, ngrok\n conf.get_default().auth_token = ngrokToken\n conf.get_default().monitor_thread = False\n ssh_tunnels = ngrok.get_tunnels(conf.get_default())\n if len(ssh_tunnels) == 0:\n ssh_tunnel = ngrok.connect(port, bind_tls=True)\n print(f'{address_name}:' + ssh_tunnel.public_url)\n else:\n print(f'{address_name}:' + ssh_tunnels[0].public_url)\n else:\n print('skip start ngrok')\n\ndef ngrok_start1(ngrokTokenFile: str, port: int, address_name: str, should_run: bool):\n if not should_run:\n print('Skipping ngrok start')\n return\n if Path(ngrokTokenFile).exists():\n with open(ngrokTokenFile, encoding=\"utf-8\") as nkfile:\n ngrokToken = nkfile.readline()\n print('use nrgok')\n from pyngrok import conf, ngrok\n conf.get_default().auth_token = ngrokToken\n conf.get_default().monitor_thread = False\n ssh_tunnels = ngrok.get_tunnels(conf.get_default())\n if len(ssh_tunnels) == 0:\n ssh_tunnel = ngrok.connect(port, bind_tls=True)\n print(f'{address_name}:' + ssh_tunnel.public_url)\n else:\n print(f'{address_name}:' + ssh_tunnels[0].public_url)\n else:\n print('skip start ngrok')\n","metadata":{"execution":{"iopub.status.busy":"2023-05-10T12:54:39.546637Z","iopub.execute_input":"2023-05-10T12:54:39.546975Z","iopub.status.idle":"2023-05-10T12:54:39.563973Z","shell.execute_reply.started":"2023-05-10T12:54:39.546944Z","shell.execute_reply":"2023-05-10T12:54:39.562942Z"},"trusted":true},"execution_count":127,"outputs":[]},{"cell_type":"code","source":"#sd_webui启动\ndef start_webui1():\n if use2:\n ngrok_start1(ngrokTokenFile1,7861,'第二个webui',ngrok_use1)\n %cd $install_path/stable-diffusion-webui\n args1.append(f'--ckpt=models/Stable-diffusion/{usedCkpt1}')\n !/opt/conda/envs/venv/bin/python3 launch.py {' '.join(args1)} --port 7861 --device-id=1\n pass\n\ndef start_webui():\n ngrok_start(ngrokTokenFile,7860,'第一个webui',ngrok_use)\n %cd $install_path/stable-diffusion-webui\n args.append(f'--ckpt=models/Stable-diffusion/{usedCkpt}')\n !/opt/conda/envs/venv/bin/python3 launch.py {' '.join(args)}","metadata":{"execution":{"iopub.status.busy":"2023-05-10T12:54:39.566126Z","iopub.execute_input":"2023-05-10T12:54:39.567956Z","iopub.status.idle":"2023-05-10T12:54:39.587309Z","shell.execute_reply.started":"2023-05-10T12:54:39.567900Z","shell.execute_reply":"2023-05-10T12:54:39.586305Z"},"trusted":true},"execution_count":128,"outputs":[]},{"cell_type":"code","source":"def ready_webui():\n !apt -y install -qq aria2\n !pip install -q pyngrok \n install_webui()\n install_extensions()\n\ndef main():\n startTicks = time.time()\n isInstall = True if os.getenv('IsInstall','False') == 'True' else False\n if isInstall is False or reLoad:\n !apt -y update -qq\n libtcmalloc()\n if __name__ == '__main__':\n ready=[venvinstall,\n ready_webui]\n run_programs(ready)\n isInstall = True\n os.environ['IsInstall'] = 'True'\n download_model()\n link_models()\n ticks = time.time()\n print(\"加载耗时:\",(ticks - startTicks),\"s\")\n gc.collect()\n if __name__ == '__main__':\n start=[start_webui,\n start_webui1]\n run_programs(start)","metadata":{"execution":{"iopub.status.busy":"2023-05-10T12:54:39.591102Z","iopub.execute_input":"2023-05-10T12:54:39.591535Z","iopub.status.idle":"2023-05-10T12:54:39.611991Z","shell.execute_reply.started":"2023-05-10T12:54:39.591473Z","shell.execute_reply":"2023-05-10T12:54:39.610882Z"},"trusted":true},"execution_count":129,"outputs":[]},{"cell_type":"code","source":"#功能函数,清理打包上传\nfrom pathlib import Path\nfrom huggingface_hub import HfApi, login\n\ndef hugface_upload(huggingface_token_file, yun_files, repo_id):\n if Path(huggingface_token_file).exists():\n with open(huggingface_token_file, encoding=\"utf-8\") as nkfile:\n hugToken = nkfile.readline()\n if hugToken != '':\n # 使用您的 Hugging Face 访问令牌登录\n login(token=hugToken)\n # 实例化 HfApi 类\n api = HfApi()\n print(\"HfApi 类已实例化\")\n %cd $install_path/stable-diffusion-webui\n # 使用 upload_file() 函数上传文件\n print(\"开始上传文件...\")\n for yun_file in yun_files:\n if Path(yun_file).exists():\n response = api.upload_file(\n path_or_fileobj=yun_file,\n path_in_repo=yun_file,\n repo_id=repo_id,\n repo_type=\"dataset\"\n )\n print(\"文件上传完成\")\n print(f\"响应: {response}\")\n else:\n print(f'Error: File {yun_file} does not exist')\n else:\n print(f'Error: File {huggingface_token_file} does not exist')\n\ndef clean_folder(folder_path):\n if not os.path.exists(folder_path):\n return\n for filename in os.listdir(folder_path):\n file_path = os.path.join(folder_path, filename)\n if os.path.isfile(file_path):\n os.remove(file_path)\n elif os.path.isdir(file_path):\n shutil.rmtree(file_path)\n\ndef zip_clear_updata():\n if zip_output:\n output_folder = f'{install_path}/stable-diffusion-webui/outputs/'\n if os.path.exists(output_folder):\n shutil.make_archive('/kaggle/working/图片', 'zip', output_folder)\n print('图片已压缩到output')\n else:\n print(f'文件夹 {output_folder} 不存在,跳过压缩操作')\n if clear_output:\n %cd $install_path/stable-diffusion-webui/outputs/\n clean_folder('img2img-images')\n clean_folder('txt2img-images')\n clean_folder('img2img-grids')\n clean_folder('txt2img-grids')\n clean_folder('extras-images')\n print('清理完毕')\n if huggingface_use == True:\n hugface_upload(huggingface_token_file,yun_files,huggiingface_repo_id)","metadata":{"execution":{"iopub.status.busy":"2023-05-10T13:40:50.329957Z","iopub.execute_input":"2023-05-10T13:40:50.330607Z","iopub.status.idle":"2023-05-10T13:40:50.364157Z","shell.execute_reply.started":"2023-05-10T13:40:50.330563Z","shell.execute_reply":"2023-05-10T13:40:50.363084Z"},"trusted":true},"execution_count":152,"outputs":[]},{"cell_type":"code","source":"# start\nmain()","metadata":{"_kg_hide-input":true,"_kg_hide-output":false,"execution":{"iopub.status.busy":"2023-05-10T12:54:39.645612Z","iopub.execute_input":"2023-05-10T12:54:39.646111Z","iopub.status.idle":"2023-05-10T13:10:35.616885Z","shell.execute_reply.started":"2023-05-10T12:54:39.646061Z","shell.execute_reply":"2023-05-10T13:10:35.612958Z"},"trusted":true},"execution_count":131,"outputs":[{"name":"stdout","text":"87 packages can be upgraded. Run 'apt list --upgradable' to see them.\nReading package lists... Done\nBuilding dependency tree \nReading state information... Done\nThe following packages will be REMOVED:\n google-perftools\n0 upgraded, 0 newly installed, 1 to remove and 86 not upgraded.\nAfter this operation, 792 kB disk space will be freed.\n(Reading database ... 111812 files and directories currently installed.)\nRemoving google-perftools (2.5-2.2ubuntu3) ...\nProcessing triggers for man-db (2.9.1-1) ...\n/kaggle\nmkdir: cannot create directory ‘temp’: File exists\n/kaggle/temp\nlibgoogle-perftools 100%[===================>] 198.92K 450KB/s in 0.4s \ngoogle-perftools_2. 100%[===================>] 287.33K 563KB/s in 0.5s \nlibtcmalloc-minimal 100%[===================>] 89.50K 363KB/s in 0.2s \nlibgoogle-perftools 100%[===================>] 185.18K 494KB/s in 0.4s \nlibunwind-dev is already the newest version (1.2.1-9ubuntu0.1).\n0 upgraded, 0 newly installed, 0 to remove and 86 not upgraded.\nSelecting previously unselected package google-perftools.\n(Reading database ... 111756 files and directories currently installed.)\nPreparing to unpack google-perftools_2.5-2.2ubuntu3_all.deb ...\nUnpacking google-perftools (2.5-2.2ubuntu3) ...\nPreparing to unpack libgoogle-perftools-dev_2.5-2.2ubuntu3_amd64.deb ...\nUnpacking libgoogle-perftools-dev (2.5-2.2ubuntu3) over (2.5-2.2ubuntu3) ...\nPreparing to unpack libgoogle-perftools4_2.5-2.2ubuntu3_amd64.deb ...\nUnpacking libgoogle-perftools4 (2.5-2.2ubuntu3) over (2.5-2.2ubuntu3) ...\nPreparing to unpack libtcmalloc-minimal4_2.5-2.2ubuntu3_amd64.deb ...\nUnpacking libtcmalloc-minimal4 (2.5-2.2ubuntu3) over (2.5-2.2ubuntu3) ...\nSetting up libtcmalloc-minimal4 (2.5-2.2ubuntu3) ...\nSetting up libgoogle-perftools4 (2.5-2.2ubuntu3) ...\nSetting up google-perftools (2.5-2.2ubuntu3) ...\nSetting up libgoogle-perftools-dev (2.5-2.2ubuntu3) ...\nProcessing triggers for man-db (2.9.1-1) ...\nProcessing triggers for libc-bin (2.31-0ubuntu9.9) ...\n/opt/conda/envs\n环境已安装\naria2 is already the newest version (1.35.0-1build1).\n0 upgraded, 0 newly installed, 0 to remove and 87 not upgraded.\n\u001b[33mWARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv\u001b[0m\u001b[33m\n\u001b[0m/kaggle/working\nstable-diffusion-webui安装中\nCloning into 'stable-diffusion-webui'...\nremote: Enumerating objects: 19606, done.\u001b[K\nremote: Counting objects: 100% (395/395), done.\u001b[K\nremote: Compressing objects: 100% (191/191), done.\u001b[K\nremote: Total 19606 (delta 204), reused 330 (delta 188), pack-reused 19211\u001b[K\nReceiving objects: 100% (19606/19606), 29.24 MiB | 30.96 MiB/s, done.\nResolving deltas: 100% (13656/13656), done.\n/kaggle/working/stable-diffusion-webui\nNote: switching to '5ab7f213bec2f816f9c5644becb32eb72c8ffb89'.\n\nYou are in 'detached HEAD' state. You can look around, make experimental\nchanges and commit them, and you can discard any commits you make in this\nstate without impacting any branches by switching back to a branch.\n\nIf you want to create a new branch to retain commits you create, you may\ndo so (now or later) by using -c with the switch command. Example:\n\n git switch -c \n\nOr undo this operation with:\n\n git switch -\n\nTurn off this advice by setting config variable advice.detachedHead to false\n\nHEAD is now at 5ab7f213 fix an error that prevents running webui on torch<2.0 without --disable-safe-unpickle\nstable-diffusion-webui已安装\n安装插件,此处出现红条是正常的\n/kaggle/working/stable-diffusion-webui\n/kaggle/working/stable-diffusion-webui/extensions\n","output_type":"stream"},{"name":"stderr","text":"Cloning into 'loopback_scaler'...\nCloning into 'sd-webui-depth-lib'...\nCloning into 'stable-diffusion-webui-images-browser'...\nCloning into 'sd-civitai-browser'...\nCloning into 'sd-webui-controlnet'...\nCloning into 'openpose-editor'...\nCloning into 'stable-diffusion-webui-localization-zh_CN'...\nCloning into 'stable-diffusion-webui-two-shot'...\nCloning into 'a1111-sd-webui-tagcomplete'...\nCloning into 'multidiffusion-upscaler-for-automatic1111'...\nCloning into 'a1111-sd-webui-locon'...\nCloning into 'sd-webui-cutoff'...\nCloning into 'sd-webui-lora-block-weight'...\nCloning into 'Stable-Diffusion-Webui-Civitai-Helper'...\n","output_type":"stream"},{"name":"stdout","text":"插件已安装\n成功下载 7278 to Stable-diffusion\n成功下载 control_v11e_sd15_ip2p_fp16.safetensors to cn-model\n成功下载 control_v11e_sd15_shuffle_fp16.safetensors to cn-model\n成功下载 control_v11f1e_sd15_tile_fp16.safetensors to cn-model\nCreated symlink for cetusMix.safetensors in /kaggle/working/stable-diffusion-webui/models/Stable-diffusion\nCreated symlink for 9527_v10.ckpt in /kaggle/working/stable-diffusion-webui/models/Stable-diffusion\nCreated symlink for fashionGirl_v51.safetensors in /kaggle/working/stable-diffusion-webui/models/Lora\nCreated symlink for ZhouShuyi.safetensors in /kaggle/working/stable-diffusion-webui/models/Lora\nCreated symlink for zhaoJinmai_V40chillout.safetensors in /kaggle/working/stable-diffusion-webui/models/Lora\nCreated symlink for angelababy_1.safetensors in /kaggle/working/stable-diffusion-webui/models/Lora\nCreated symlink for lora-hanfugirl-v1.safetensors in /kaggle/working/stable-diffusion-webui/models/Lora\nCreated symlink for hyy-v3-Lion-.safetensors in /kaggle/working/stable-diffusion-webui/models/Lora\nCreated symlink for .safetensors in /kaggle/working/stable-diffusion-webui/models/Lora\nCreated symlink for wbb_koori_v02.safetensors in /kaggle/working/stable-diffusion-webui/models/Lora\nCreated symlink for hanfu_v28.safetensors in /kaggle/working/stable-diffusion-webui/models/Lora\nCreated symlink for zc.safetensors in /kaggle/working/stable-diffusion-webui/models/Lora\nCreated symlink for zls_rosyZhao.safetensors in /kaggle/working/stable-diffusion-webui/models/Lora\nCreated symlink for bingbing_v0.2.safetensors in /kaggle/working/stable-diffusion-webui/models/Lora\nCreated symlink for mingmo.safetensors in /kaggle/working/stable-diffusion-webui/models/Lora\nCreated symlink for lhc_new.safetensors in /kaggle/working/stable-diffusion-webui/models/Lora\nCreated symlink for goutouLora_v25.safetensors in /kaggle/working/stable-diffusion-webui/models/Lora\nCreated symlink for lora-hanfugirl-v1-5.safetensors in /kaggle/working/stable-diffusion-webui/models/Lora\nCreated symlink for lora-hf2song-v1.safetensors in /kaggle/working/stable-diffusion-webui/models/Lora\nCreated symlink for wanqian_shorthair_v01.safetensors in /kaggle/working/stable-diffusion-webui/models/Lora\nCreated symlink for 11e7dbe52a73f66e701c1faa77b8a2cb0ee3abd721e1cae31123f5b299093435 in /kaggle/working/stable-diffusion-webui/extensions/sd-webui-controlnet/models\nCreated symlink for 2f31868eedb243a77932e3c63907a6ba0a2058b6d65b5c27b89ee1b7f618ea33 in /kaggle/working/stable-diffusion-webui/extensions/sd-webui-controlnet/models\nCreated symlink for 8cc77ae071888abefd6e80bafce3d2574f9f6f8aac7ab205db98fb12a53c1132 in /kaggle/working/stable-diffusion-webui/extensions/sd-webui-controlnet/models\n加载耗时: 58.36148476600647 s\nSkipping ngrok start\n/kaggle/working/stable-diffusion-webui\nPython 3.10.10 | packaged by conda-forge | (main, Mar 24 2023, 20:08:06) [GCC 11.3.0]\nCommit hash: 5ab7f213bec2f816f9c5644becb32eb72c8ffb89\nCloning Stable Diffusion into /kaggle/working/stable-diffusion-webui/repositories/stable-diffusion-stability-ai...\nCloning Taming Transformers into /kaggle/working/stable-diffusion-webui/repositories/taming-transformers...\nCloning K-diffusion into /kaggle/working/stable-diffusion-webui/repositories/k-diffusion...\nCloning CodeFormer into /kaggle/working/stable-diffusion-webui/repositories/CodeFormer...\nCloning BLIP into /kaggle/working/stable-diffusion-webui/repositories/BLIP...\nInstalling requirements\n\n\n\nLaunching Web UI with arguments: --share --xformers --lowram --no-hashing --disable-nan-check --enable-insecure-extension-access --disable-console-progressbars --enable-console-prompts --disable-safe-unpickle --ckpt=models/Stable-diffusion/cetusMix.safetensors\nCivitai Helper: Get Custom Model Folder\nCivitai Helper: Load setting from: /kaggle/working/stable-diffusion-webui/extensions/Stable-Diffusion-Webui-Civitai-Helper/setting.json\nCivitai Helper: No setting file, use default\nAdditional Network extension not installed, Only hijack built-in lora\nLoCon Extension hijack built-in lora successfully\nControlNet v1.1.150\nControlNet v1.1.150\nImage Browser: ImageReward is not installed, cannot be used.\nLoading weights [None] from /kaggle/working/stable-diffusion-webui/models/Stable-diffusion/cetusMix.safetensors\nCreating model from config: /kaggle/working/stable-diffusion-webui/configs/v1-inference.yaml\nLatentDiffusion: Running in eps-prediction mode\nDiffusionWrapper has 859.52 M params.\nDownloading (…)olve/main/vocab.json: 100%|███| 961k/961k [00:00<00:00, 19.8MB/s]\nDownloading (…)olve/main/merges.txt: 100%|████| 525k/525k [00:00<00:00, 163MB/s]\nDownloading (…)cial_tokens_map.json: 100%|█████| 389/389 [00:00<00:00, 1.34MB/s]\nDownloading (…)okenizer_config.json: 100%|█████| 905/905 [00:00<00:00, 2.84MB/s]\nDownloading (…)lve/main/config.json: 100%|█| 4.52k/4.52k [00:00<00:00, 12.3MB/s]\nApplying xformers cross attention optimization.\nTextual inversion embeddings loaded(0): \nModel loaded in 72.4s (load weights from disk: 64.6s, create model: 2.1s, apply weights to model: 3.9s, apply half(): 1.0s, move model to device: 0.7s).\nImage Browser: Creating database\nImage Browser: Database created\nRunning on local URL: http://127.0.0.1:7860\nRunning on public URL: https://1226fa8ec5d06aec3e.gradio.live\n\nThis share link expires in 72 hours. For free permanent hosting and GPU upgrades (NEW!), check out Spaces: https://huggingface.co./spaces\nStartup time: 87.5s (import torch: 1.3s, import gradio: 1.3s, import ldm: 1.1s, other imports: 2.3s, setup codeformer: 0.2s, load scripts: 2.5s, load SD checkpoint: 72.4s, create ui: 1.8s, gradio launch: 4.5s).\nClosing server running on port: 7860\nRestarting UI...\nCivitai Helper: Get Custom Model Folder\nCivitai Helper: Load setting from: /kaggle/working/stable-diffusion-webui/extensions/Stable-Diffusion-Webui-Civitai-Helper/setting.json\nCivitai Helper: No setting file, use default\nAdditional Network extension not installed, Only hijack built-in lora\nLoCon Extension hijack built-in lora successfully\nControlNet v1.1.150\nImage Browser: ImageReward is not installed, cannot be used.\nRunning on local URL: http://127.0.0.1:7860\nRunning on public URL: https://1891d3a7e13d80bfee.gradio.live\n\nThis share link expires in 72 hours. For free permanent hosting and GPU upgrades (NEW!), check out Spaces: https://huggingface.co./spaces\nStartup time: 5.2s (load scripts: 0.8s, create ui: 1.6s, gradio launch: 2.7s).\n\ntxt2img: 1girl\n100%|█████████████████████████████████████████| 150/150 [00:30<00:00, 4.92it/s]\n","output_type":"stream"},{"traceback":["\u001b[0;31m---------------------------------------------------------------------------\u001b[0m","\u001b[0;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)","\u001b[0;32m/tmp/ipykernel_24/4281207697.py\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0;31m# start\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0mmain\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m","\u001b[0;32m/tmp/ipykernel_24/535694326.py\u001b[0m in \u001b[0;36mmain\u001b[0;34m()\u001b[0m\n\u001b[1;32m 25\u001b[0m start=[start_webui,\n\u001b[1;32m 26\u001b[0m start_webui1]\n\u001b[0;32m---> 27\u001b[0;31m \u001b[0mrun_programs\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mstart\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m","\u001b[0;32m/tmp/ipykernel_24/3296067800.py\u001b[0m in \u001b[0;36mrun_programs\u001b[0;34m(programs)\u001b[0m\n\u001b[1;32m 22\u001b[0m \u001b[0mtime\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msleep\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 23\u001b[0m \u001b[0;32mfor\u001b[0m \u001b[0mp\u001b[0m \u001b[0;32min\u001b[0m \u001b[0mprocesses\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 24\u001b[0;31m \u001b[0mp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mjoin\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m","\u001b[0;32m/opt/conda/lib/python3.7/multiprocessing/process.py\u001b[0m in \u001b[0;36mjoin\u001b[0;34m(self, timeout)\u001b[0m\n\u001b[1;32m 138\u001b[0m \u001b[0;32massert\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_parent_pid\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0mos\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mgetpid\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'can only join a child process'\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 139\u001b[0m \u001b[0;32massert\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_popen\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'can only join a started process'\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 140\u001b[0;31m \u001b[0mres\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_popen\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mwait\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtimeout\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 141\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mres\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mnot\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 142\u001b[0m \u001b[0m_children\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdiscard\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n","\u001b[0;32m/opt/conda/lib/python3.7/multiprocessing/popen_fork.py\u001b[0m in \u001b[0;36mwait\u001b[0;34m(self, timeout)\u001b[0m\n\u001b[1;32m 46\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 47\u001b[0m \u001b[0;31m# This shouldn't block if wait() returned successfully.\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 48\u001b[0;31m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpoll\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mos\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mWNOHANG\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mtimeout\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;36m0.0\u001b[0m \u001b[0;32melse\u001b[0m \u001b[0;36m0\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 49\u001b[0m \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mreturncode\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 50\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n","\u001b[0;32m/opt/conda/lib/python3.7/multiprocessing/popen_fork.py\u001b[0m in \u001b[0;36mpoll\u001b[0;34m(self, flag)\u001b[0m\n\u001b[1;32m 26\u001b[0m \u001b[0;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mreturncode\u001b[0m \u001b[0;32mis\u001b[0m \u001b[0;32mNone\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 27\u001b[0m \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 28\u001b[0;31m \u001b[0mpid\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0msts\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mos\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mwaitpid\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpid\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mflag\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 29\u001b[0m \u001b[0;32mexcept\u001b[0m \u001b[0mOSError\u001b[0m \u001b[0;32mas\u001b[0m \u001b[0me\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 30\u001b[0m \u001b[0;31m# Child process not yet created. See #1731717\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n","\u001b[0;31mKeyboardInterrupt\u001b[0m: "],"ename":"KeyboardInterrupt","evalue":"","output_type":"error"},{"name":"stdout","text":"^C\nInterrupted with signal 2 in \n","output_type":"stream"}]},{"cell_type":"code","source":"#跑图结束,手动执行,清理图片并打包到output方便下载,同时同步配置文件\nzip_clear_updata()","metadata":{"execution":{"iopub.status.busy":"2023-05-10T13:40:56.862567Z","iopub.execute_input":"2023-05-10T13:40:56.863580Z","iopub.status.idle":"2023-05-10T13:40:57.728286Z","shell.execute_reply.started":"2023-05-10T13:40:56.863523Z","shell.execute_reply":"2023-05-10T13:40:57.727021Z"},"trusted":true},"execution_count":153,"outputs":[{"name":"stdout","text":"图片已压缩到output\n/kaggle/working/stable-diffusion-webui/outputs\n清理完毕\nToken will not been saved to git credential helper. Pass `add_to_git_credential=True` if you want to set the git credential as well.\nToken is valid.\nYour token has been saved to /root/.cache/huggingface/token\nLogin successful\nHfApi 类已实例化\n/kaggle/working/stable-diffusion-webui\n开始上传文件...\n文件上传完成\n响应: https://huggingface.co./datasets/sukaka/sd_configs/blob/main/ui-config.json\n文件上传完成\n响应: https://huggingface.co./datasets/sukaka/sd_configs/blob/main/config.json\nError: File styles.csv does not exist\n","output_type":"stream"}]},{"cell_type":"code","source":"#模型下载器,手动执行后出现一个交互式表格\nimport os\ninstall_path=\"/kaggle/working\" \nos.environ['install_path'] = install_path\ndef model_down_tool():\n import ipywidgets as widgets\n from IPython.display import display\n import subprocess\n def download_with_aria2(link, file_path):\n # 设置aria2c命令行参数\n cmd = ['aria2c','--console-log-level=error', link, '-o', file_path, '-x', '16', '-s', '16', '-k', '1M']\n # 调用aria2c下载文件\n try:\n subprocess.run(cmd, check=True)\n print(f\"文件已保存到: {file_path}\")\n except subprocess.CalledProcessError as e:\n print(f\"下载失败: {e}\")\n def sdmodel_down(link, model_name):\n # 设置模型保存的文件夹路径\n %cd $install_path\n save_dir = 'stable-diffusion-webui/models/Stable-diffusion'\n if not os.path.exists(save_dir):\n os.makedirs(save_dir)\n \n # 设置模型保存的文件名\n file_name = f\"{model_name}\"\n file_path = os.path.join(save_dir, file_name)\n \n # 下载模型\n download_with_aria2(link, file_path)\n \n print(f\"模型已保存到: {file_path}\")\n\n def vae_down(link, model_name):\n # 设置模型保存的文件夹路径\n %cd $install_path\n save_dir = 'stable-diffusion-webui/models/VAE'\n if not os.path.exists(save_dir):\n os.makedirs(save_dir)\n\n # 设置模型保存的文件名\n file_name = f\"{model_name}\"\n file_path = os.path.join(save_dir, file_name)\n\n # 下载模型\n cmd = ['aria2c','--console-log-level=error', link, '-o', file_path, '-x', '16', '-s', '16', '-k', '1M']\n\n print(f\"模型已保存到: {file_path}\")\n\n def vae_down(link, model_name):\n # 设置模型保存的文件夹路径\n %cd $install_path\n save_dir = 'stable-diffusion-webui/models/Lora'\n if not os.path.exists(save_dir):\n os.makedirs(save_dir)\n\n # 设置模型保存的文件名\n file_name = f\"{model_name}\"\n file_path = os.path.join(save_dir, file_name)\n\n # 下载模型\n cmd = ['aria2c','--console-log-level=error', link, '-o', file_path, '-x', '16', '-s', '16', '-k', '1M']\n\n print(f\"模型已保存到: {file_path}\")\n \n model_type = widgets.Dropdown(\n options=['sd大模型', 'vae模型', 'Lora模型'],\n description='模型类型:',\n disabled=False,\n )\n\n link = widgets.Text(\n value='',\n placeholder='输入链接',\n description='链接:',\n disabled=False\n )\n\n model_name = widgets.Text(\n value='',\n placeholder='输入模型名称',\n description='模型名:',\n disabled=False\n )\n\n def on_submit(btn):\n if model_type.value == 'sd大模型':\n sdmodel_down(link.value, model_name.value)\n elif model_type.value == 'vae模型':\n vae_down(link.value, model_name.value)\n else:\n lora_down(link.value, model_name.value)\n\n submit = widgets.Button(description=\"提交\")\n submit.on_click(on_submit)\n\n display(model_type, link, model_name, submit)\n#模型下载器\nmodel_down_tool()\n#safetensors","metadata":{"execution":{"iopub.status.busy":"2023-05-10T13:10:35.624096Z","iopub.status.idle":"2023-05-10T13:10:35.624674Z","shell.execute_reply.started":"2023-05-10T13:10:35.624377Z","shell.execute_reply":"2023-05-10T13:10:35.624406Z"},"trusted":true},"execution_count":null,"outputs":[]}]}