stable-diffusion-webui容器构建教程

一、介绍

Stable Diffusion WebUI 是一个提供了易于使用的 AI 绘画工具,它允许用户通过一个更友好、可视化的网页界面来与 Stable Diffusion 模型互动,可以实现文生图、图生图等。

二、特点

  • 易于使用的界面 :用户可以通过网页界面进行操作。
  • 实时反馈 :该界面通常会显示生成图像的进度和预览,用户可以实时看到生成的结果。
  • 模型切换 :可在界面中切换不同的 stable-diffusion 模型,变换生成图片的风格。

image.png

三、容器构建说明

此项目所需python版本为3.10.6,并且此项目中部分安装依赖的文件在普通用户中运行能避免出现一些问题。

  1. 建议首先创建一个普通用户,并在其中进行环境构建:
adduser sd_user
sudo usermod -aG sudo sd_user
su - sd_user
  1. 下载mimiconda并构建虚拟环境:
sudo apt-get update
sudo apt-get install -y git wget unzip
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh -O ~/miniconda.sh
bash ~/miniconda.sh -b -p $HOME/miniconda
source $HOME/miniconda/bin/activate
conda init
conda create -n sd python=3.10.6
conda activate sd
  1. github仓库中克隆项目:
git clone https://github.com/AUTOMATIC1111/stable-diffusion-webui.git
cd stable-diffusion-webui
  1. 然后安装所需环境:
sudo apt install wget git python3 python3-venv libgl1 libglib2.0-0
./webui.sh
  1. 如果开头没有创建普通用户,那么执行 ./webui.sh时会出现如下图不许root用户执行文件的错误:

image.png

解决办法是打开webui.sh文件,找到下图位置进行修改:

image.png

正常应该为下图:

image.png

  1. 然后等待依赖与模型的下载

如无法访问外网,需从魔搭社区下载模型v1-5-pruned-emaonly.safetensors放在models/stable diffusion文件夹下:

git lfs install
git clone https://www.modelscope.cn/zhiheng/v1-5-pruned-emaonly.safetensors.git

开放端口并运行:

export GRADIO_SERVER_NAME=0.0.0.0
export GRADIO_SERVER_PORT=8080
python launch.py

如果运行时出现报错信息:

OSError: Can't load tokenizer for 'openai/clip-vit-large-patch14'. If you were trying to load it from https://huggingface.co/models', make sure you don't have a local directory with the same name. Otherwise, make sure 'openai/clip-vit-large-patch14' is the correct path to a directory containing all relevant files for a CLIPTokenizer tokenizer

这是因为缺少的openai/clip-vit-large-patch14文件需要在hugging face手动下载,并且放在报错提示中的位置:

(1)将openai解压后放在stable-diffusion-webui文件下

(2)将解压后openai文件中的openai文件重命名为clip-vit-large-patch14

再次开放端口并运行即可

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值