Spaces:
Running
on
T4
Running
on
T4
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
from diffusers import AutoPipelineForImage2Image
|
3 |
+
from diffusers.utils import make_image_grid, load_image
|
4 |
+
|
5 |
+
pipeline = AutoPipelineForImage2Image.from_pretrained(
|
6 |
+
"runwayml/stable-diffusion-v1-5", torch_dtype=torch.float16, variant="fp16", use_safetensors=True
|
7 |
+
)
|
8 |
+
pipeline.enable_model_cpu_offload()
|
9 |
+
# remove following line if xFormers is not installed or you have PyTorch 2.0 or higher installed
|
10 |
+
pipeline.enable_xformers_memory_efficient_attention()
|
11 |
+
|
12 |
+
# prepare image
|
13 |
+
url = "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/diffusers/img2img-init.png"
|
14 |
+
init_image = load_image(url)
|
15 |
+
|
16 |
+
prompt = "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k"
|
17 |
+
|
18 |
+
# pass prompt and image to pipeline
|
19 |
+
image = pipeline(prompt, image=init_image).images[0]
|
20 |
+
make_image_grid([init_image, image], rows=1, cols=2)
|