Spaces:
Sleeping
Sleeping
from diffusers import AutoPipelineForText2Image, AutoPipelineForImage2Image | |
import torch | |
from diffusers.utils import make_image_grid | |
pipeline = AutoPipelineForText2Image.from_pretrained( | |
"runwayml/stable-diffusion-v1-5", torch_dtype=torch.float16, variant="fp16", use_safetensors=True | |
) | |
pipeline.enable_model_cpu_offload() | |
# remove following line if xFormers is not installed or you have PyTorch 2.0 or higher installed | |
pipeline.enable_xformers_memory_efficient_attention() | |
text2image = pipeline("Astronaut in a jungle, cold color palette, muted colors, detailed, 8k").images[0] | |
text2image | |
pipeline = AutoPipelineForImage2Image.from_pretrained( | |
"kandinsky-community/kandinsky-2-2-decoder", torch_dtype=torch.float16, use_safetensors=True | |
) | |
pipeline.enable_model_cpu_offload() | |
# remove following line if xFormers is not installed or you have PyTorch 2.0 or higher installed | |
pipeline.enable_xformers_memory_efficient_attention() | |
image2image = pipeline("Astronaut in a jungle, cold color palette, muted colors, detailed, 8k", image=text2image).images[0] | |
make_image_grid([text2image, image2image], rows=1, cols=2) | |
import torch | |
from diffusers import AutoPipelineForImage2Image | |
from diffusers.utils import make_image_grid, load_image | |
pipeline = AutoPipelineForImage2Image.from_pretrained( | |
"runwayml/stable-diffusion-v1-5", torch_dtype=torch.float16, variant="fp16", use_safetensors=True | |
) | |
pipeline.enable_model_cpu_offload() | |
# remove following line if xFormers is not installed or you have PyTorch 2.0 or higher installed | |
pipeline.enable_xformers_memory_efficient_attention() | |
# prepare image | |
url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/img2img-init.png" | |
init_image = load_image(url) | |
prompt = "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k" | |
# pass prompt and image to pipeline | |
image = pipeline(prompt, image=init_image, output_type="latent").images[0] | |
pipeline = AutoPipelineForImage2Image.from_pretrained( | |
"ogkalu/Comic-Diffusion", torch_dtype=torch.float16 | |
) | |
pipeline.enable_model_cpu_offload() | |
# remove following line if xFormers is not installed or you have PyTorch 2.0 or higher installed | |
pipeline.enable_xformers_memory_efficient_attention() | |
# need to include the token "charliebo artstyle" in the prompt to use this checkpoint | |
image = pipeline("Astronaut in a jungle, charliebo artstyle", image=image, output_type="latent").images[0] | |
pipeline = AutoPipelineForImage2Image.from_pretrained( | |
"kohbanye/pixel-art-style", torch_dtype=torch.float16 | |
) | |
pipeline.enable_model_cpu_offload() | |
# remove following line if xFormers is not installed or you have PyTorch 2.0 or higher installed | |
pipeline.enable_xformers_memory_efficient_attention() | |
# need to include the token "pixelartstyle" in the prompt to use this checkpoint | |
image = pipeline("Astronaut in a jungle, pixelartstyle", image=image).images[0] | |
make_image_grid([init_image, image], rows=1, cols=2) | |
import torch | |
from diffusers import AutoPipelineForImage2Image | |
from diffusers.utils import make_image_grid, load_image | |
pipeline = AutoPipelineForImage2Image.from_pretrained( | |
"runwayml/stable-diffusion-v1-5", torch_dtype=torch.float16, variant="fp16", use_safetensors=True | |
) | |
pipeline.enable_model_cpu_offload() | |
# remove following line if xFormers is not installed or you have PyTorch 2.0 or higher installed | |
pipeline.enable_xformers_memory_efficient_attention() | |
# prepare image | |
url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/img2img-init.png" | |
init_image = load_image(url) | |
prompt = "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k" | |
# pass prompt and image to pipeline | |
image_1 = pipeline(prompt, image=init_image, output_type="latent").images[0] | |
from diffusers import StableDiffusionLatentUpscalePipeline | |
upscaler = StableDiffusionLatentUpscalePipeline.from_pretrained( | |
"stabilityai/sd-x2-latent-upscaler", torch_dtype=torch.float16, variant="fp16", use_safetensors=True | |
) | |
upscaler.enable_model_cpu_offload() | |
upscaler.enable_xformers_memory_efficient_attention() | |
image_2 = upscaler(prompt, image=image_1, output_type="latent").images[0] | |
from diffusers import StableDiffusionUpscalePipeline | |
super_res = StableDiffusionUpscalePipeline.from_pretrained( | |
"stabilityai/stable-diffusion-x4-upscaler", torch_dtype=torch.float16, variant="fp16", use_safetensors=True | |
) | |
super_res.enable_model_cpu_offload() | |
super_res.enable_xformers_memory_efficient_attention() | |
image_3 = super_res(prompt, image=image_2).images[0] | |
make_image_grid([init_image, image_3.resize((512, 512))], rows=1, cols=2) | |