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')
结果
相关推荐
小程故事多_8020 小时前
破除迷思,Harness Engineering从来都不是时代过渡品
人工智能·架构·prompt·aigc
oden1 天前
省下的就是净利润:手把手教你用模型路由砍掉 80% 的 OpenClaw 账单
aigc·ai编程·aiops
爱吃的小肥羊1 天前
2026 Claude Design 完整指南:功能介绍+使用教程+Claude会员订阅方法
aigc·ai编程
量子位1 天前
20亿美金苏度科技具身首秀即大招!0真机数据,zero-shot,跑出98%首次抓取成功率
llm·aigc
HOHO1 天前
说起来你可能不信,我写了个跑在浏览器里的 ai agent 框架
aigc·agent
用户5191495848451 天前
Apache安全漏洞测试工具 - CVE-2024-38475利用脚本
人工智能·aigc
用户5191495848451 天前
Kubernetes kubeadm 集群部署与 CKA 实战指南
人工智能·aigc
92year1 天前
browser-use 怎么让 LLM 看懂网页——86k⭐ 浏览器 Agent 的 DOM 处理管线拆解
aigc
_张一凡1 天前
【大语言模型学习】2026年最适合新手的小型LLM训练项目全指南:从26M到1B,3块钱就能从头训练
llm·aigc·大语言模型·大语言模型微调