可以根据文字生成图片的模型。只要输入一段文字描述,就能得到一张由 AI 生成的图片,除此之外该项目还支持将粗糙的草图转化成精致的艺术图片。
https://github.com/CompVis/stable-diffusion
# make sure you're logged in with `huggingface-cli login`
from torch import autocast
from diffusers import StableDiffusionPipeline
pipe = StableDiffusionPipeline.from_pretrained(
"CompVis/stable-diffusion-v1-4",
use_auth_token=True
).to("cuda")
prompt = "a photo of an astronaut riding a horse on mars"
with autocast("cuda"):
image = pipe(prompt)["sample"][0]
image.save("astronaut_rides_horse.png")