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')
结果
相关推荐
JackLi36 分钟前
最新大模型及智能体开发平台全套部署方案
aigc·ai编程
用户5191495848453 小时前
Citrix NetScaler内存泄漏漏洞利用工具 (CVE-2025-5777)
人工智能·aigc
EdisonZhou21 小时前
MAF快速入门(17)用户智能体交互协议AG-UI(中)
llm·aigc·agent
ssshooter1 天前
免费和付费 AI API 选择指南
人工智能·aigc·openai
多恩Stone1 天前
【C++入门扫盲1】C++ 与 Python:类型、编译器/解释器与 CPU 的关系
开发语言·c++·人工智能·python·算法·3d·aigc
爱吃的小肥羊1 天前
DeepSeek V4 细节曝光:100 万上下文 + 原生多模态
人工智能·aigc·deepseek
DigitalOcean1 天前
无服务器推理(Serverless Inference)是什么?与传统AI推理部署方式全面对比
aigc
infiniteWei1 天前
Skills、MCP、Agent 的边界与商业化定位(附项目筛选表)
人工智能·aigc·测试
树獭叔叔1 天前
05-从隐藏向量到文字:LM Head如何输出"下一个词"?
后端·aigc·openai