【novelai】colab存档

本笔记由此改写而成:

https://colab.research.google.com/drive/1kw3egmSn-KgWsikYvOMjJkVDsPLjEMzl
https://colab.research.google.com/drive/1AfAmwLMd_Vx33O9IwY2TmO9wKZ8ABRRa

感谢大佬们的贡献
最终成果如下:

https://blog.csdn.net/Algernon98/article/details/127332323?spm=1001.2014.3001.5501


#@title 杀掉colab进程,会使页面报错,但是不用担心,继续运行即可,请勿跳过
import os
os.kill(os.getpid(), 9)
#@title 加载Google云端硬盘
from google.colab import drive
import os
drive.mount('/content/drive')

#%cd /content/drive/MyDrive/ML2021/
#!ls
Drive already mounted at /content/drive; to attempt to forcibly remount, call drive.mount("/content/drive", force_remount=True).

1. 克隆git仓库

!git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
%cd stable-diffusion-webui

fatal: destination path 'stable-diffusion-webui' already exists and is not an empty directory.
/content/stable-diffusion-webui

2. 安装依赖

!COMMANDLINE_ARGS="--exit" REQS_FILE="requirements.txt" python launch.py
Python 3.7.14 (default, Sep  8 2022, 00:06:44) 
[GCC 7.5.0]
Commit hash: acedbe67d2b8a3af99ca3b9a2f809e7a2db285d1
Installing requirements for Web UI
Exiting because of --exit argument

3. 下载full模型,以下两种方式二选一

#建议用云盘复制版,自己上传full模型。
#若使用Gdown下载,人数太多之后文件容易被BAN

使用云盘复制版时,请严格按照以下步骤将模型文件上传到谷歌云盘:

1.进入谷歌云盘 https://drive.google.com/drive/my-drive 找到云盘根目录

2.在根目录下创建文件夹,并命名为:stableckpt

3.从泄露模型的磁链中下载需要的文件,如下图所示,下载animefull-final-pruned文件夹,modules文件夹,以及animevae.pt这个文件,下载好后,请保持原样,不要改动文件夹内部的路径格式,否则在复制时会因为路径报错

4.将第三部步下载好的所有文件,全部上传到第二步中创建好的stableckpt文件夹内,等待成功上传即可。

(P.S. 成功上传后,文件将长期储存在谷歌云盘中,再次使用时,就可以省略该步)

下面两种方式,请二选一,只执行一种

%cd /content/drive/MyDrive/ML2021/animefull-final-pruned/model.ckpt
[Errno 20] Not a directory: '/content/drive/MyDrive/ML2021/animefull-final-pruned/model.ckpt'
/content/stable-diffusion-webui
#@title 云盘复制版(推荐使用,需先进行文件上传)

!cp /content/drive/MyDrive/ML2021/animefull-final-pruned/model.ckpt /content/stable-diffusion-webui/models/Stable-diffusion/final-pruned.ckpt
!cp /content/drive/MyDrive/ML2021/animevae.pt /content/stable-diffusion-webui/models/Stable-diffusion/final-pruned.vae.pt
!mkdir /content/stable-diffusion-webui/models/hypernetworks
!cp -r /content/drive/MyDrive/ML2021/modules/modules/* /content/stable-diffusion-webui/models/hypernetworks
!rm /content/stable-diffusion-webui/repositories/stable-diffusion/configs/stable-diffusion/v1-inference.yaml
!cp /content/drive/MyDrive/ML2021/animefull-final-pruned/config.yaml /content/stable-diffusion-webui/repositories/stable-diffusion/configs/stable-diffusion/v1-inference.yaml

mkdir: cannot create directory ‘/content/stable-diffusion-webui/models/hypernetworks’: File exists
#@title Gdown下载版(使用人数过多,会导致文件被冻,不建议使用)
!gdown --id '1kJ2lCJ56_R342dQVzHfcvKdyq9HXIxQe' --output /content/stable-diffusion-webui/models/Stable-diffusion/final-pruned.ckpt
!gdown --id '1cZoN_PTmdOidDeVlj_B8kG99TvQZ2I0O' --output /content/stable-diffusion-webui/models/Stable-diffusion/final-pruned.vae.pt
!mkdir /content/temps
!gdown --id '1V7gSylOF9W_03CPap70etPUYKBmtkVi2' --output /content/temps/modules.zip
!unzip /content/temps/modules.zip -d /content/temps
!mkdir /content/stable-diffusion-webui/models/hypernetworks
!cp -r /content/temps/modules/* /content/stable-diffusion-webui/models/hypernetworks
#config
!rm /content/stable-diffusion-webui/repositories/stable-diffusion/configs/stable-diffusion/v1-inference.yaml
!gdown --id '1C1swqS024tgXK_JWr40d4_F3LYVW7W4F' --output /content/stable-diffusion-webui/repositories/stable-diffusion/configs/stable-diffusion/v1-inference.yaml

/usr/local/lib/python3.7/dist-packages/gdown/cli.py:131: FutureWarning: Option `--id` was deprecated in version 4.3.1 and will be removed in 5.0. You don't need to pass it anymore to use a file ID.
  category=FutureWarning,
Access denied with the following error:

 	Too many users have viewed or downloaded this file recently. Please
	try accessing the file again later. If the file you are trying to
	access is particularly large or is shared with many people, it may
	take up to 24 hours to be able to view or download the file. If you
	still can't access a file after 24 hours, contact your domain
	administrator. 

You may still be able to access the file from the browser:

	 https://drive.google.com/uc?id=1kJ2lCJ56_R342dQVzHfcvKdyq9HXIxQe 

/usr/local/lib/python3.7/dist-packages/gdown/cli.py:131: FutureWarning: Option `--id` was deprecated in version 4.3.1 and will be removed in 5.0. You don't need to pass it anymore to use a file ID.
  category=FutureWarning,
Access denied with the following error:

 	Too many users have viewed or downloaded this file recently. Please
	try accessing the file again later. If the file you are trying to
	access is particularly large or is shared with many people, it may
	take up to 24 hours to be able to view or download the file. If you
	still can't access a file after 24 hours, contact your domain
	administrator. 

You may still be able to access the file from the browser:

	 https://drive.google.com/uc?id=1cZoN_PTmdOidDeVlj_B8kG99TvQZ2I0O 

/usr/local/lib/python3.7/dist-packages/gdown/cli.py:131: FutureWarning: Option `--id` was deprecated in version 4.3.1 and will be removed in 5.0. You don't need to pass it anymore to use a file ID.
  category=FutureWarning,
Access denied with the following error:

 	Too many users have viewed or downloaded this file recently. Please
	try accessing the file again later. If the file you are trying to
	access is particularly large or is shared with many people, it may
	take up to 24 hours to be able to view or download the file. If you
	still can't access a file after 24 hours, contact your domain
	administrator. 

You may still be able to access the file from the browser:

	 https://drive.google.com/uc?id=1V7gSylOF9W_03CPap70etPUYKBmtkVi2 

unzip:  cannot find or open /content/temps/modules.zip, /content/temps/modules.zip.zip or /content/temps/modules.zip.ZIP.
mkdir: cannot create directory ‘/content/stable-diffusion-webui/models/hypernetworks’: File exists
cp: cannot stat '/content/temps/modules/*': No such file or directory
rm: cannot remove '/content/stable-diffusion-webui/repositories/stable-diffusion/configs/stable-diffusion/v1-inference.yaml': No such file or directory
/usr/local/lib/python3.7/dist-packages/gdown/cli.py:131: FutureWarning: Option `--id` was deprecated in version 4.3.1 and will be removed in 5.0. You don't need to pass it anymore to use a file ID.
  category=FutureWarning,
Downloading...
From: https://drive.google.com/uc?id=1C1swqS024tgXK_JWr40d4_F3LYVW7W4F
To: /content/stable-diffusion-webui/repositories/stable-diffusion/configs/stable-diffusion/v1-inference.yaml
100% 1.87k/1.87k [00:00<00:00, 3.65MB/s]

4. 部署模型到gradio

使用web ui. 你将会得到一个类似 xxx.gradio.app,点击它就可以进入部署好的页面.

命令行参数如下:

  • --share - 创建一个在线的 gradio.app 链接
  • --gradio-debug - 打印输出到控制台
  • --gradio-auth me:qwerty - 创建用户,默认 username 为 me, password 为 qwerty,可以自行修改,用作登陆

10月13日追记:为了避免别人爬取你的线上部署来使用,强烈建议修改用户名与密码,请将me和qwerty替换成其他的。

!COMMANDLINE_ARGS="--share --gradio-debug --gradio-auth algernon:code" REQS_FILE="requirements.txt" python launch.py
Python 3.7.14 (default, Sep  8 2022, 00:06:44) 
[GCC 7.5.0]
Commit hash: acedbe67d2b8a3af99ca3b9a2f809e7a2db285d1
Installing requirements for Web UI
Launching Web UI with arguments: --share --gradio-debug --gradio-auth algernon:yhyfgcyydt98
LatentDiffusion: Running in eps-prediction mode
DiffusionWrapper has 859.52 M params.
making attention of type 'vanilla' with 512 in_channels
Working with z of shape (1, 4, 64, 64) = 16384 dimensions.
making attention of type 'vanilla' with 512 in_channels
Downloading: 100% 939k/939k [00:01<00:00, 703kB/s] 
Downloading: 100% 512k/512k [00:00<00:00, 575kB/s]
Downloading: 100% 389/389 [00:00<00:00, 323kB/s]
Downloading: 100% 905/905 [00:00<00:00, 713kB/s]
Downloading: 100% 4.41k/4.41k [00:00<00:00, 3.34MB/s]
Downloading: 100% 1.59G/1.59G [00:24<00:00, 68.5MB/s]
Loading weights [925997e9] from /content/stable-diffusion-webui/models/Stable-diffusion/final-pruned.ckpt
Loading VAE weights from: /content/stable-diffusion-webui/models/Stable-diffusion/final-pruned.vae.pt
Applying cross attention optimization (Doggettx).
Model loaded.
Loaded a total of 0 textual inversion embeddings.
Running on local URL:  http://127.0.0.1:7860
Running on public URL: https://25278.gradio.app

This share link expires in 72 hours. For free permanent hosting, check out Spaces: https://huggingface.co/spaces
  0% 0/16 [00:00

【novelai】colab存档_第1张图片
【novelai】colab存档_第2张图片
【novelai】colab存档_第3张图片
【novelai】colab存档_第4张图片
【novelai】colab存档_第5张图片

你可能感兴趣的:(全栈,python,开发语言,novelai)