当前位置:   article > 正文

AIGC - SD(中英文本生成图片) + PaddleHub/HuggingFace + stable-diffusion-webui

AIGC - SD(中英文本生成图片) + PaddleHub/HuggingFace + stable-diffusion-webui
功能
  1. stable-diffusion(文本生成图片)
  2. webui-win搭建(开启api+界面汉化)
  3. PaddleHub
  4. HuggingFace: SD2,中文-alibaba/EasyNLP
stable-diffusion-webui
下载与安装
  1. 环境相关下载
  2. python(文档推荐:Install Python 3.10.6 (Newer version of Python does not support torch))
  3. https://www.python.org/downloads/
  4. git-win
  5. https://git-scm.com/download
  6. CUDA(根据电脑配置选择)
  7. https://developer.nvidia.com/cuda-toolkit
  8. nvidia驱动(根据电脑配置选择)
  9. https://www.nvidia.com/Download/index.aspx
  10. 项目部署相关下载
  11. 项目(具体部署以此项目文档为准)
  12. https://github.com/AUTOMATIC1111/stable-diffusion-webui
  13. 汉化(操作流程参考此项目文档)
  14. https://github.com/VinsonLaro/stable-diffusion-webui-chinese
  15. 模型(本示例选择:sd-v1-4.ckpt)
  16. https://huggingface.co/CompVis/stable-diffusion-v-1-4-original
  17. 备注:
  18. 环境安装查看其他文档
配置与启动
  1. 模型配置
  2. 复制到:stable-diffusion-webui\models\Stable-diffusion目录
  3. webui-user.bat配置(根据情况添加)
  4. set COMMANDLINE_ARGS= --api --no-half
  5. cmd运行:webui-user.bat
  6. 备注:
  7. --api 开启sdapi
  8. gui地址:http://127.0.0.1:7860/
  9. api-docs地址:http://127.0.0.1:7860/docs
结果

PaddleHub
环境
  1. pip install paddlepaddle-gpu
  2. pip install paddlehub
代码
  1. from PIL import Image
  2. import paddlehub as hub
  3. module = hub.Module(name='stable_diffusion')
  4. ## 保存在demo目录
  5. result = module.generate_image(text_prompts="clouds surround the mountains and Chinese palaces,sunshine,lake,overlook,overlook,unreal engine,light effect,Dream,Greg Rutkowski,James Gurney,artstation", output_dir='demo')
结果

HuggingFace--SD2
环境
pip install diffusers transformers accelerate scipy safetensors
代码
  1. import torch
  2. from diffusers import StableDiffusionPipeline, DPMSolverMultistepScheduler
  3. import matplotlib.pyplot as plt
  4. import matplotlib.image as mpimg
  5. def show(image_path):
  6. # 使用 Matplotlib 加载图片文件
  7. image = mpimg.imread(image_path)
  8. # 显示图片
  9. plt.imshow(image)
  10. plt.axis('off') # 关闭坐标轴
  11. plt.show()
  12. model_id = "stabilityai/stable-diffusion-2-1"
  13. # Use the DPMSolverMultistepScheduler (DPM-Solver++) scheduler here instead
  14. pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
  15. pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
  16. pipe = pipe.to("cuda")
  17. prompt = "clouds surround the mountains and Chinese palaces,sunshine,lake,overlook,overlook,unreal engine,light effect,Dream,Greg Rutkowski,James Gurney,artstation"
  18. image = pipe(prompt).images[0]
  19. image.save("test.png")
  20. show('test.png')
结果

HuggingFace--中文-alibaba/EasyNLP
代码
  1. from diffusers import StableDiffusionPipeline
  2. ### 环境使用SD2
  3. model_id = "alibaba-pai/pai-diffusion-artist-large-zh"
  4. pipe = StableDiffusionPipeline.from_pretrained(model_id)
  5. pipe = pipe.to("cuda")
  6. prompt = "云环绕群山和中国宫殿,阳光,湖泊,俯瞰,俯瞰,虚幻的引擎,灯光效果,梦想,格雷格·鲁特考斯基,詹姆斯·格尼,艺术站"
  7. image = pipe(prompt).images[0]
  8. image.save("result.png")
  9. show('result.png')
结果

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小蓝xlanll/article/detail/500568
推荐阅读
相关标签
  

闽ICP备14008679号