1. 首先安装基本工具
- # 安装python环境
- sudo apt install wget git
复制代码 若已经安装过请忽略
2. 安装miniconda(也可以自己下载python)
下载最新的安装包
- wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
复制代码 执行安装
- ./Miniconda3-latest-Linux-x86_64.sh
复制代码 一路回车,遇到选择就yes(切记要yes,不然要手动添加环境变量)
刷新环境
此时命令行输入python,看到是3.10版本的就对了
- (base) root@localhost:~# python
- Python 3.10.9 (main, Jan 11 2023, 15:21:40) [GCC 11.2.0] on linux
- Type "help", "copyright", "credits" or "license" for more information.
- >>>
复制代码 后续步骤可以用conda新建一个虚拟环境进行,我的服务器是临时的,所以就直接在base环境下进行了
3. git拉取项目到本地
执行
- git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
复制代码 进入项目目录下
- cd stable-diffusion-webui/
复制代码 4. 安装对应Python依赖包
首先安装pytorch和torchvision,若是GPU环境的用户需要安装与cuda版本对应的torch,cpu环境则无具体要求
- pip install torch==1.13.1+cu117 torchvision==0.14.1+cu117 --extra-index-url https://download.pytorch.org/whl/cu117
复制代码 然后给pip换上中科大的源,也可以换清华源或阿里源
- pip config set global.index-url https://mirrors.ustc.edu.cn/pypi/web/simple
复制代码 接着安装对应依赖
- pip install -r requirements_versions.txt
复制代码 5. 从huggingface下载预训练模型参数
进入模型存放对应目录
- cd models/Stable-diffusion/
复制代码 下载一个模型,这里可以根据自己的需要下载
- wget https://huggingface.co/CompVis/stable-diffusion-v-1-4-original/resolve/main/sd-v1-4-full-ema.ckpt
复制代码 6. 启动项目
到这一步网上很多方法都是直接执行根目录下的webui.sh,我执行时有报错,就换了一种方式
回到项目根目录,执行launch.py文件,启动web服务,并指定监听端口为1234(端口号随意)
- python3 launch.py --port 1234 --listen
复制代码 若为cpu环境,则需提前执行
- export COMMANDLINE_ARGS=--skip-torch-cuda-test
复制代码 并且在运行时加入no-half
- python3 launch.py --no-half --port 1234 --listen
复制代码 启动后安装很多依赖以及克隆相应github仓库,过程有报错的可以看附录解决方案并重新执行这一步
若出现以下内容则说明启动成功

此时访问http://127.0.0.1:1234即可使用
7. 公网访问
若想让服务能在公网上被其他用户访问,则需进入weibu.py文件,修改对应代码,将shared.demo.launch()第一行参数改为share=True。

然后重新启动项目,此时能看到公网地址,说明成功

访问以上临时的公网地址就可以让别人也使用你的AI作图了
8. 汉化扩展
在任意目录下克隆中文扩展地址
- git clone https://github.com/VinsonLaro/stable-diffusion-webui-chinese
复制代码 进入下载好的文件夹,把localizations文件夹内的Chinese-All.json和Chinese-English.json复制到stable-diffusion-webui\localizations目录下,如下

启动web服务后,点击Settings,左侧点击User interface界面,在界面里最下方的Localization (requires restart),选择Chinese-All或者Chinese-English,点击界面最上方的黄色按钮Apply settings,再点击右侧的Reload UI即可完成汉化。


汉化后的页面

附:遇到的错误
- 报错RuntimeError: Couldn’t clone Stable Diffusion。
解决办法:手动clone
- git clone https://github.com/Stability-AI/stablediffusion.git
- "/root/stable-diffusion-webui/repositories/stable-diffusion-stability-ai"
复制代码
- 报错gnutls_handshake() failed: The TLS connection was non-properly terminated
解决办法:在执行时使用http而不是https,替换
- git clone https://github.com/Stability-AI/stablediffusion.git
复制代码 为
- git clone http://github.com/Stability-AI/stablediffusion.git
复制代码
- 报错RuntimeError: Couldn’t install open_clip。安装open_clip失败
解决办法:进入launch.py文件,找到openclip_package 部分代码,修改对应部分代码为
- openclip_package = os.environ.get('OPENCLIP_PACKAGE', "git+https://gitee.com/ufhy/open_clip.git@bb6e834e9c70d9c27d0dc3ecedeebeaeb1ffad6b"))
复制代码 来源:https://blog.csdn.net/UCB001/article/details/130039154
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作! |