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')
结果
相关推荐
Awu12273 小时前
⚡从零开发 Agent CLI(二):CLI 框架搭建与子命令路由
人工智能·aigc
Awu12273 小时前
⚡从零开发 Agent CLI(三):终端样式改造——从 console.log 到交互式 Ink UI
aigc·ai编程
草帽lufei3 小时前
下班后把活交给AI,定时器让它晚上继续干活
aigc·ai编程
阿祖zu4 小时前
别再优化 RAG 了,适配 Agent 的 LLM Wiki 知识库理念
前端·后端·aigc
墨风如雪5 小时前
AI 火了,人人都想开源,GitHub 没你想的那么复杂
aigc
leeyi5 小时前
Document 组件:把文件喂给 AI 之前,必须先做这三步
aigc·agent·ai编程
92year7 小时前
MCP 协议最大改版:去掉了 Session,你的 Server 要改 6 个地方
aigc
用户5191495848457 小时前
Flex QR Code Generator 漏洞利用工具 CVE-2025-10041
人工智能·aigc
修己xj21 小时前
告别手动画图:用自然语言生成可直接发布的 SVG+PNG 技术图
aigc
用户5191495848451 天前
Windows 渗透测试载荷加载器 POC 工具集
人工智能·aigc