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')
结果
相关推荐
一眼万年042 小时前
每天都在使用的VS Code Copilot Chat 开源啦!
aigc·ai编程·visual studio code
不大姐姐AI智能体2 小时前
最新Coze(扣子)智能体工作流:1分钟生成10条合规美女热舞视频,流量暴涨300%
aigc
iThinkAi2 小时前
最新Coze(扣子)智能体工作流:1分钟生成爆款认知混剪视频,自动搜索视频素材,无需手动剪辑 | AI智能体
aigc
鬼鬼鬼10 小时前
从软件1.0到3.0:在这场AI浪潮中,我们如何面对?
aigc·ai编程·cursor
墨风如雪10 小时前
AI界又炸了!会“卡壳”、会“改作业”的Dhanishtha-2.0来了!
aigc
墨风如雪10 天前
告别插件时代!OmniGen2:一个模型,通吃所有AIGC神操作
aigc
阿维同学10 天前
媒体AI关键技术研究
人工智能·ai·aigc·媒体
量子位10 天前
史上最高种子轮花落 AI:20 亿美元断档领先,苹果 Meta 抢着都投不进,扎克伯格转头挖联创也遭拒
aigc
PetterHillWater10 天前
基于大模型SSE的HTTP API接口测试与评估
aigc
顾林海10 天前
DeepSeek 提示词工程完全指南:从基础到高级应用
人工智能·aigc·deepseek