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')
结果
相关推荐
神奇霸王龙4 小时前
Cursor 3 + Claude Opus 4.8 屠榜:5 编程基座 IDE 卡位
ide·人工智能·ai·aigc·agent·ai编程·ai写作
AI创界者4 小时前
IndexTTS 2.5 零样本语音克隆本地部署指南与实战避坑(附WebUI使用技巧)
人工智能·aigc
Rocky Ding*7 小时前
一文读懂Wan 3.0视频创作大模型核心基础知识
论文阅读·人工智能·深度学习·机器学习·aigc·ai-native·wan 3.0
后端小肥肠8 小时前
开营 10 天变现率 20%:我用一套 Skill,把小红书虚拟资料跑成了可复制流程
人工智能·aigc·agent
远航计算机8 小时前
GEO自诊断实操手册:你的内容为什么AI搜不到?
人工智能·矩阵·aigc·媒体
Csvn10 小时前
第 6 章 Agent 主循环
人工智能·aigc·agent
Csvn10 小时前
第 5 章 工具调用
人工智能·aigc·agent
李剑一10 小时前
连名词都不会,你AI个Der!学会AI基础之:到底模型是什么玩意儿?都说大模型,有小模型嘛?训练数据多它就是大模型吗?
aigc·openai·ai编程
全栈弄潮儿12 小时前
一周总结:AI 能帮你节省时间的 10 类任务
aigc·openai·ai编程
leeyi13 小时前
Agent 怎么测试:mock LLM + 状态机表驱动,不调真模型的测试策略(第96篇-E82)
llm·aigc·agent