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')
结果
相关推荐
程序员X小鹿3 分钟前
谷歌又出黑科技:支持图文混排的AI创意画布来了!1个想法,3秒出图,免费可用!(附教程)
aigc
万里鹏程转瞬至24 分钟前
开源项目分析:wan2.1 VACE 关键设计与实现代码解读
论文阅读·aigc
墨风如雪29 分钟前
告别代码苦海:Manus 1.5 让你的创意以光速落地
aigc
麦麦麦造11 小时前
有了 MCP,为什么Claude 还要推出 Skills?
人工智能·aigc·ai编程
张晓~1833994812113 小时前
碰一碰发视频 系统源码 /PHP 语言开发方案
开发语言·线性代数·矩阵·aigc·php·音视频·文心一言
Mintopia14 小时前
🎨 AIGC 内容过滤技术:当创作的洪流遇上理性的堤坝
前端·javascript·aigc
ANnianStriver14 小时前
智谱大模型实现文生视频案例
java·aigc
weixin_519535771 天前
从ChatGPT到新质生产力:一份数据驱动的AI研究方向指南
人工智能·深度学习·机器学习·ai·chatgpt·数据分析·aigc
墨风如雪1 天前
Anthropic Haiku 4.5:这波AI性能,我愿称之为“超值”!
aigc
Keria1021 天前
本地私有化部署Dify步骤
aigc