mirror of
https://github.com/Stability-AI/stablediffusion.git
synced 2024-12-21 23:24:59 +00:00
Fix diffusers code snippet
This commit is contained in:
parent
84d3c27982
commit
8d95d19606
1 changed files with 17 additions and 7 deletions
|
@ -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
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue