Fix diffusers code snippet

This commit is contained in:
apolinario 2023-03-24 18:19:15 +01:00 committed by GitHub
parent 84d3c27982
commit 8d95d19606
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -19,19 +19,29 @@ Diffusers integration
Stable UnCLIP Image Variations is integrated with the [🧨 diffusers](https://github.com/huggingface/diffusers) library Stable UnCLIP Image Variations is integrated with the [🧨 diffusers](https://github.com/huggingface/diffusers) library
```python ```python
#pip install git+https://github.com/huggingface/diffusers.git transformers accelerate #pip install git+https://github.com/huggingface/diffusers.git transformers accelerate
import requests
import torch import torch
from diffusers import StableUnCLIPPipeline from PIL import Image
from io import BytesIO
pipe = StableUnCLIPPipeline.from_pretrained( from diffusers import StableUnCLIPImg2ImgPipeline
"stabilityai/stable-diffusion-2-1-unclip", torch_dtype=torch.float16
#Start the StableUnCLIP Image variations pipeline
pipe = StableUnCLIPImg2ImgPipeline.from_pretrained(
"stabilityai/stable-diffusion-2-1-unclip", torch_dtype=torch.float16, variation="fp16"
) )
pipe = pipe.to("cuda") pipe = pipe.to("cuda")
prompt = "a photo of an astronaut riding a horse on mars" #Get image from URL
images = pipe(prompt).images url = "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main/stable_unclip/tarsila_do_amaral.png"
images[0].save("astronaut_horse.png") response = requests.get(url)
init_image = Image.open(BytesIO(response.content)).convert("RGB")
#Pipe to make the variation
images = pipe(init_image).images
images[0].save("tarsila_variation.png")
``` ```
Check out the [Stable UnCLIP pipeline docs here](https://huggingface.co/docs/diffusers/api/pipelines/stable_unclip) Check out the [Stable UnCLIP pipeline docs here](https://huggingface.co/docs/diffusers/main/en/api/pipelines/stable_unclip)
Streamlit UI demo Streamlit UI demo