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')
结果
相关推荐
ServBay7 小时前
全栈开发者的 AI 模型选择指南:Kimi K3、Claude、GPT 分别适合什么场景
开源·aigc·ai编程
Miracleeee8 小时前
OpenAI 官方教你怎么用 Codex,其实是在教你怎么写一份「Skill」
aigc·openai
手写码匠13 小时前
华为云Flexus+DeepSeek征文|DeepSeek+RAG知识库实战:基于Flexus X实例与Dify构建企业级智能问答系统
人工智能·深度学习·算法·aigc
神奇霸王龙14 小时前
金融AI对决:Qwen3.7-Max屠榜降本60%
人工智能·ai·金融·prompt·aigc·ai金融
leeyi14 小时前
切片策略选错了,检索效果天差地别(第68篇-E54)
aigc·agent·ai编程
怕浪猫15 小时前
第11章 实战项目二:自动化研发运维Agent
aigc·agent·ai编程
ServBay1 天前
AI Gateway 与直连 LLM API 的应该怎么选,一篇文章说明白
aigc·ai编程
donoot1 天前
《大话文渊慧典》:外二篇-Tesseract+OpenCV自制OCR,我写了三百个if-else,最后代码成了玄学
人工智能·aigc·文渊慧典·大话系列
墨风如雪1 天前
Hermes Agent 进阶教程:服务器安全防护3项必做
aigc