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')
结果
相关推荐
奇舞精选3 小时前
prompt的参数调优入门指南 - 小白也能轻松掌握
人工智能·aigc
DisonTangor3 小时前
商汤InternLM发布最先进的开源多模态推理模型——Intern-S1
人工智能·深度学习·开源·aigc
软件测试君3 小时前
【Rag实用分享】小白也能看懂的文档解析和分割教程
aigc·openai·ai编程
redreamSo7 小时前
AI Daily | AI日报:Meta百亿抢人,AI数据标注产业升级; 百度全栈自研,AI应用大放异彩; Hinton访华:多模态大模型已有「意识」
程序员·aigc·资讯
DisonTangor7 小时前
Mistral AI开源 Magistral-Small-2507
人工智能·语言模型·开源·aigc
青Cheng序员石头7 小时前
【转译】Agentic AI 与 AI Agent:五大差异及其重要性
llm·aigc·agent
青Cheng序员石头7 小时前
Prompt Engineering vs Vibe Coding vs Context Engineering
langchain·llm·aigc
数据智能老司机8 小时前
构建由 LLM 驱动的 Neo4j 应用程序——使用 Neo4j 和 Haystack 实现强大搜索功能
langchain·llm·aigc
CyberTM8 小时前
Dify之外的新选择?开源版Coze部署初体验,真香警告!
aigc·agent·coze
优秘智能UMI9 小时前
私有化大模型架构解决方案构建指南
大数据·人工智能·深度学习·信息可视化·aigc