Diffusers
English
stable-diffusion
stable-diffusion-diffusers
inpainting
art
artistic
anime
absolute-realism
Instructions to use diffusers/tools with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Diffusers
How to use diffusers/tools with Diffusers:
pip install -U diffusers transformers accelerate
import torch from diffusers import DiffusionPipeline # switch to "mps" for apple devices pipe = DiffusionPipeline.from_pretrained("diffusers/tools", dtype=torch.bfloat16, device_map="cuda") prompt = "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k" image = pipe(prompt).images[0] - Notebooks
- Google Colab
- Kaggle
| #!/usr/bin/env python3 | |
| from huggingface_hub import HfApi | |
| import torch | |
| # https://github.com/pix2pixzero/pix2pix-zero/blob/main/src/edit_synthetic.py | |
| import requests | |
| from diffusers import DDIMScheduler, StableDiffusionPix2PixZeroPipeline | |
| api = HfApi() | |
| def download(embedding_url, local_filepath): | |
| r = requests.get(embedding_url) | |
| with open(local_filepath, "wb") as f: | |
| f.write(r.content) | |
| model_ckpt = "CompVis/stable-diffusion-v1-4" | |
| pipeline = StableDiffusionPix2PixZeroPipeline.from_pretrained( | |
| model_ckpt, conditions_input_image=False, torch_dtype=torch.float16 | |
| ) | |
| pipeline.scheduler = DDIMScheduler.from_config(pipeline.scheduler.config) | |
| pipeline.to("cuda") | |
| prompt = "a high resolution painting of a cat in the style of van gough" | |
| source_embedding_url = "https://github.com/pix2pixzero/pix2pix-zero/raw/main/assets/embeddings_sd_1.4/cat.pt" | |
| target_embedding_url = "https://github.com/pix2pixzero/pix2pix-zero/raw/main/assets/embeddings_sd_1.4/dog.pt" | |
| for url in [source_embedding_url, target_embedding_url]: | |
| download(url, url.split("/")[-1]) | |
| source_embeds = torch.load(source_embedding_url.split("/")[-1]) | |
| target_embeds = torch.load(target_embedding_url.split("/")[-1]) | |
| image = pipeline( | |
| prompt, | |
| source_embeds=source_embeds, | |
| target_embeds=target_embeds, | |
| num_inference_steps=50, | |
| cross_attention_guidance_amount=0.15, | |
| ).images[0] | |
| path = "/home/patrick_huggingface_co/images/aa.png" | |
| image.save(path) | |
| api.upload_file( | |
| path_or_fileobj=path, | |
| path_in_repo=path.split("/")[-1], | |
| repo_id="patrickvonplaten/images", | |
| repo_type="dataset", | |
| ) | |
| print("https://huggingface.co/datasets/patrickvonplaten/images/blob/main/aa.png") | |