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 小时前
【Cursor实战】DeepWiki MCP让Cursor边查项目文档边写代码
aigc·cursor
小和尚同志11 小时前
通俗易懂的 MCP 概念入门
人工智能·aigc
redreamSo20 小时前
AI Daily | AI日报:科学家怒揭 AI 科研黑幕; 清华:AutoMat让电镜流程大提速; AI辩论:81.7%概率让你信服
程序员·aigc·资讯
肖笙XiaoSheng20 小时前
用Gemini调整我的定时任务代码
后端·aigc·ai编程
后端小肥肠1 天前
Coze实战:一分钟生成10w+独居女孩Vlog动画,零基础也能日更!
人工智能·aigc·coze
iThinkAi智能体1 天前
Coze(扣子)智能体工作流:自动批量生成小红书图文,1分钟100篇
aigc
墨风如雪1 天前
小红书AI新里程碑:dots.llm1,中文MoE的“人文”突破!
aigc
iThinkAi智能体1 天前
Coze(扣子)智能体工作流:自动批量生成书单号视频,1分钟100个,书单号博主都在用!
aigc
架构师那点事儿1 天前
一文带你俯瞰大模型领域的世界
langchain·aigc·ai编程
小奏技术2 天前
基于 Spring AI 和 MCP:用自然语言查询 RocketMQ 消息
后端·aigc·mcp