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

功能
  1. stable-diffusion(文本生成图片)
  2. PaddleHub,HuggingFace两种调用方式
PaddleHub
环境
bash 复制代码
pip install paddlepaddle-gpu
pip install paddlehub
代码
bash 复制代码
from PIL import Image
import paddlehub as hub
module = hub.Module(name='stable_diffusion')

## 保存在demo目录
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
环境
bash 复制代码
pip install diffusers transformers accelerate scipy safetensors
代码
bash 复制代码
import torch
from diffusers import StableDiffusionPipeline, DPMSolverMultistepScheduler
import matplotlib.pyplot as plt
import matplotlib.image as mpimg

def show(image_path):
    # 使用 Matplotlib 加载图片文件
    image = mpimg.imread(image_path)

    # 显示图片
    plt.imshow(image)
    plt.axis('off')  # 关闭坐标轴
    plt.show()

model_id = "stabilityai/stable-diffusion-2-1"

# Use the DPMSolverMultistepScheduler (DPM-Solver++) scheduler here instead
pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
pipe.scheduler = DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
pipe = pipe.to("cuda")


prompt = "clouds surround the mountains and Chinese palaces,sunshine,lake,overlook,overlook,unreal engine,light effect,Dream,Greg Rutkowski,James Gurney,artstation"
image = pipe(prompt).images[0]
    
image.save("test.png")
show('test.png')
结果
相关推荐
AlbertZein2 天前
Step-5-Preview 上手实测:3D 游戏、金融分析、网页设计一次跑完
人工智能·aigc
AIGCmagic社区3 天前
文档智能专题:小模型后训练怎么选样本?PaddleOCR-VL-1.6按三类弱点挖掘
人工智能·aigc·文档智能
AIGCmagic社区3 天前
文档智能专题:HunyuanOCR-1.5用DFlash把整页解码压到1.4秒
人工智能·aigc·文档智能
小虎AI生活3 天前
腾讯开源了一个项目,让 AI 直接用你已经登录好的浏览器
aigc·ai编程
plainGeekDev3 天前
Harness 实战:用 Android 登录模块搭一套可靠的 Agent 开发环境
aigc·ai编程·claude
全栈弄潮儿3 天前
周复盘:把 AI 当实习生,还是当工程搭档?
aigc·openai·ai编程
程序员清风3 天前
系统架构设计:模型服务、业务服务与知识库如何拆分
人工智能·ai·架构·aigc
倔强的石头_3 天前
我给 WorkBuddy 设了个闹钟:每天上午十点半,一份 AI 日报自动送进微信
aigc
李白客3 天前
向量数据库怎么选:RAG 项目最该比较的 8 个维度(深度拆解)
数据库·aigc
へ蟲児.3 天前
国内适合设计师的AIGC学习平台哪个好?能贴合商业设计实战
aigc