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')
结果
相关推荐
wangruofeng3 小时前
AI Models 模型目录,跨平台比较大模型 API 价格与上下文
github·aigc·ai编程
孟健6 小时前
一个人做 26 个平台的内容分发:字流 3.0 从选题到复盘的完整链路
aigc·ai编程
小四的小六10 小时前
一次出站重试风暴的沙箱复盘:重试没退避,Agent 十几分钟烧穿整月额度
aigc·openai·ai编程
小虎AI生活10 小时前
Claude Duet 抢的不是活,是你每天早上那半小时
aigc·ai编程
shengjk110 小时前
你以为是大模型在执行命令?真相是它只会“说“
人工智能·aigc·ai编程
AI创界者14 小时前
Python 进阶实战:AsyncIO 异步环境下的熔断器、限流器与代理模式深度融合
人工智能·aigc
技灵AI14 小时前
AI 视频转场提示词怎么写?让前后画面衔接更自然
人工智能·prompt·aigc·音视频
泰迪智能科技0116 小时前
分享AIGC应用工程师证书2026年报考解析:报考条件、报考流程与学习内容
人工智能·aigc
远航计算机16 小时前
AI 看不见图,它只读旁边的字
人工智能·chatgpt·aigc
小虎AI生活1 天前
DeepSeek 开源 DeepInfer 拆解:一张卡一小时收 38 美元背后的成本逻辑
aigc·ai编程