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')
结果
相关推荐
LV技术派8 小时前
肝了一周,我把 Super Agent 的架构融入到了我的 AI Native 工作台中
aigc·ai编程
stormzhangV10 小时前
Google 重返第一梯队
人工智能·google·aigc
小虎AI生活13 小时前
8万星开源HyperFrames,我用WorkBuddy免费模型做了3条视频
aigc·ai编程
ZhengEnCi1 天前
AI 读不懂你的代码怎么办:用高价值注释消除曲解、过度优化与上下文膨胀
aigc·ai编程
爱查宝小二1 天前
爱查宝降AIGC效果实测与过检能力展示
aigc
花椒技术1 天前
从“实时生成游戏”出发,我们用 AI 做了四次游戏开发尝试
人工智能·aigc·游戏开发
花椒技术1 天前
数字人为什么突然爆发?从 H3 Max Lip Sync 看生成式数字人的临界点
人工智能·aigc
小虎AI生活1 天前
太好了!豆包终于接入了多模型,正面硬刚WorkBuddy
aigc·ai编程
Csvn2 天前
所有问题都喂最贵的模型?规则路由实测:30 个问题里 16 个能交给便宜模型(C03)
人工智能·aigc·agent
掘黄金的打工人2 天前
LangChain 少样本示例 和 动态示例选择
langchain·aigc·ai编程