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')
结果
相关推荐
饼干哥哥1 小时前
给OpenClaw开天眼!解决了10个跨境电商网站爬虫难题
aigc
AI攻城狮3 小时前
Kimi Bot + OpenClaw 完整配置指南:5 步实现本地 AI Agent 集成
人工智能·云原生·aigc
量子位3 小时前
1秒1元!Seedance 2.0模型定价公布,短剧真的要被颠覆了
aigc·ai编程
倔强的石头_8 小时前
春节寒假作业辅导:基于 Rokid 灵珠平台打造 AI Glasses 作业助手
aigc
小兵张健20 小时前
价值1000的 AI 工作流:Codex 通用前端协作模式
前端·aigc·ai编程
AI攻城狮1 天前
RAG Chunking 为什么这么难?5 大挑战 + 最佳实践指南
人工智能·云原生·aigc
量子位1 天前
悬赏5000刀!148局AI斗蛐蛐世界杯官方战报出炉,全球赛邀你接棒来战
aigc·ai编程
量子位1 天前
华为重金押注的世界模型公司,新融了10个亿!
aigc
量子位1 天前
阿里批准林俊旸离职,CTO周靖人接管千问!Gemini周浩确定加盟
aigc·阿里巴巴
量子位1 天前
谷歌Gemini最强性价比模型发布,1块8读完3本三体
aigc·gemini