Spaces:
Sleeping
Sleeping
Update text-to-image-image-to-text
Browse files- text-to-image-image-to-text +42 -0
text-to-image-image-to-text
CHANGED
|
@@ -62,3 +62,45 @@ pipeline.enable_xformers_memory_efficient_attention()
|
|
| 62 |
# need to include the token "pixelartstyle" in the prompt to use this checkpoint
|
| 63 |
image = pipeline("Astronaut in a jungle, pixelartstyle", image=image).images[0]
|
| 64 |
make_image_grid([init_image, image], rows=1, cols=2)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 62 |
# need to include the token "pixelartstyle" in the prompt to use this checkpoint
|
| 63 |
image = pipeline("Astronaut in a jungle, pixelartstyle", image=image).images[0]
|
| 64 |
make_image_grid([init_image, image], rows=1, cols=2)
|
| 65 |
+
|
| 66 |
+
import torch
|
| 67 |
+
from diffusers import AutoPipelineForImage2Image
|
| 68 |
+
from diffusers.utils import make_image_grid, load_image
|
| 69 |
+
|
| 70 |
+
pipeline = AutoPipelineForImage2Image.from_pretrained(
|
| 71 |
+
"runwayml/stable-diffusion-v1-5", torch_dtype=torch.float16, variant="fp16", use_safetensors=True
|
| 72 |
+
)
|
| 73 |
+
pipeline.enable_model_cpu_offload()
|
| 74 |
+
# remove following line if xFormers is not installed or you have PyTorch 2.0 or higher installed
|
| 75 |
+
pipeline.enable_xformers_memory_efficient_attention()
|
| 76 |
+
|
| 77 |
+
# prepare image
|
| 78 |
+
url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/img2img-init.png"
|
| 79 |
+
init_image = load_image(url)
|
| 80 |
+
|
| 81 |
+
prompt = "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k"
|
| 82 |
+
|
| 83 |
+
# pass prompt and image to pipeline
|
| 84 |
+
image_1 = pipeline(prompt, image=init_image, output_type="latent").images[0]
|
| 85 |
+
|
| 86 |
+
from diffusers import StableDiffusionLatentUpscalePipeline
|
| 87 |
+
|
| 88 |
+
upscaler = StableDiffusionLatentUpscalePipeline.from_pretrained(
|
| 89 |
+
"stabilityai/sd-x2-latent-upscaler", torch_dtype=torch.float16, variant="fp16", use_safetensors=True
|
| 90 |
+
)
|
| 91 |
+
upscaler.enable_model_cpu_offload()
|
| 92 |
+
upscaler.enable_xformers_memory_efficient_attention()
|
| 93 |
+
|
| 94 |
+
image_2 = upscaler(prompt, image=image_1, output_type="latent").images[0]
|
| 95 |
+
|
| 96 |
+
from diffusers import StableDiffusionUpscalePipeline
|
| 97 |
+
|
| 98 |
+
super_res = StableDiffusionUpscalePipeline.from_pretrained(
|
| 99 |
+
"stabilityai/stable-diffusion-x4-upscaler", torch_dtype=torch.float16, variant="fp16", use_safetensors=True
|
| 100 |
+
)
|
| 101 |
+
super_res.enable_model_cpu_offload()
|
| 102 |
+
super_res.enable_xformers_memory_efficient_attention()
|
| 103 |
+
|
| 104 |
+
image_3 = super_res(prompt, image=image_2).images[0]
|
| 105 |
+
make_image_grid([init_image, image_3.resize((512, 512))], rows=1, cols=2)
|
| 106 |
+
|